openelections / clarify

Discover and parse results for jurisdictions that use Clarity-based election systems.
MIT License
38 stars 22 forks source link

Fix broken get_current_ver logic and unit test #42

Closed carbonphyber closed 1 year ago

carbonphyber commented 3 years ago

This PR fixes incorrect logic with get_current_ver and the relevant unit tests.

A broken unit test:

requests.exceptions.ConnectionError: Connection refused by Responses - the call doesn't match any registered mock.
Request: 
- GET https://results.enr.clarityelections.com/KY/50972/131636/en/summary.html/current_ver.txt

revealed that this function doesn't correctly truncate the URL path before appending /current_ver.txt. The correct URL should be https://results.enr.clarityelections.com/KY/50972/current_ver.txt (the version file is always in the election_id directory).

The logic fix involved using a RegEx to detect the first 2 or 3 directories of the URL path (depending on jurisdiction level of the election page).

Also, I broke the relevant 1 test function with 4 loop iterations into 1 test function per intent which helps name+describe the intent for each test and helps developers quickly identify which test/intent failed.