-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing municipality by name to more tools
- Loading branch information
Martin Nyhus
committed
Jun 11, 2023
1 parent
6266a72
commit b0fb41d
Showing
6 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import unittest | ||
|
||
import shared | ||
|
||
|
||
class TestMuncipalityResolution(unittest.TestCase): | ||
def setUp(self): | ||
self.municipalities = { | ||
'0301': 'Oslo', | ||
# '0231': 'Skedsmo', | ||
'3018': 'Våler', | ||
'3030': 'Lillestrøm', | ||
'3419': 'Våler', | ||
'4215': 'Lillesand', | ||
'4637': 'Hyllestad', | ||
} | ||
|
||
def _resolve(self, muni_name): | ||
return shared.resolve_municipality_id( | ||
self.municipalities, | ||
muni_name) | ||
|
||
def _assert_resolves_to(self, muni_name, muni_id): | ||
self.assertEqual(muni_id, self._resolve(muni_name)) | ||
|
||
def test_resolve_municipality(self): | ||
self._assert_resolves_to('Lillestrøm', '3030') | ||
|
||
def test_resolve_zero_prefix(self): | ||
self._assert_resolves_to('Oslo', '0301') | ||
|
||
def test_resolve_duplicate_name(self): | ||
with self.assertRaises(shared.MultipleResults) as cm: | ||
self._resolve('Våler') | ||
|
||
self.assertEqual(cm.exception.results, [ | ||
{'id': '3018', 'name': 'Våler'}, | ||
{'id': '3419', 'name': 'Våler'}, | ||
]) | ||
|
||
def test_resolve_missing(self): | ||
with self.assertRaises(shared.NoResults): | ||
self._resolve('Skedsmo') | ||
|
||
def test_resolve_with_different_case(self): | ||
self._assert_resolves_to('lILLESTRØM', '3030') | ||
|
||
def test_resolve_using_prefix(self): | ||
self._assert_resolves_to('Lillest', '3030') | ||
|
||
def test_prefix_resolution_to_multiple_results(self): | ||
with self.assertRaises(shared.MultipleResults) as cm: | ||
self._resolve('Lilles') | ||
|
||
self.assertEqual(cm.exception.results, [ | ||
{'id': '3030', 'name': 'Lillestrøm'}, | ||
{'id': '4215', 'name': 'Lillesand'}, | ||
]) | ||
|
||
def test_resolve_with_infix_match(self): | ||
self._assert_resolves_to('llestr', '3030') |