Skip to content

Commit 464dbd7

Browse files
committed
test: improved school provider test coverage
1 parent 8fe4795 commit 464dbd7

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

docs/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
furo==2024.8.6
2-
myst-parser==4.0.0
2+
myst-parser==4.0.1
33
Sphinx==8.1.3
44
sphinx-copybutton==0.5.2
5-
sphinx-notfound-page==1.0.4
5+
sphinx-notfound-page==1.1.0

fakernaija/tests/providers/test_school_provider.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ def test_get_school_names_no_filters(self, mock_load_json: MagicMock) -> None:
122122
expected = [school["name"] for school in self.sample_schools]
123123
self.assertEqual(result, expected)
124124

125+
@patch("fakernaija.providers.school.load_json")
126+
@patch("fakernaija.providers.school.StateProvider")
127+
def test_invalid_state_with_suggestions(
128+
self, mock_state_provider_class: MagicMock, mock_load_json: MagicMock
129+
) -> None:
130+
"""Test raising suggestions for invalid state name."""
131+
mock_load_json.return_value = self.sample_schools
132+
133+
# Patch the StateProvider to return a fixed list of states.
134+
mock_state_provider_instance = mock_state_provider_class.return_value
135+
mock_state_provider_instance.get_state_names.return_value = ["Lagos", "Kaduna"]
136+
137+
provider = SchoolProvider()
138+
139+
# Use a misspelled state name that should trigger suggestions.
140+
with self.assertRaises(ValueError) as context:
141+
provider.get_schools(state="lagoss") # Note the extra "s"
142+
143+
error_message = str(context.exception)
144+
self.assertIn("Did you mean:", error_message)
145+
self.assertIn("Lagos", error_message)
146+
125147
@patch("fakernaija.providers.school.load_json")
126148
def test_get_school_names_with_acronym(self, mock_load_json: MagicMock) -> None:
127149
"""Test get_school_names with acronym option."""

0 commit comments

Comments
 (0)