Skip to content

Commit

Permalink
improve area search page tests
Browse files Browse the repository at this point in the history
Make sure it's getting all types and ignoring others
  • Loading branch information
struan committed Aug 1, 2024
1 parent ae305e8 commit b9c6a49
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
42 changes: 42 additions & 0 deletions hub/fixtures/areas.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
"description": "Constituency 2023"
}
},
{
"model": "hub.areatype",
"pk": 3,
"fields": {
"name": "District Council",
"code": "DIS",
"area_type": "District Council",
"description": "District Council"
}
},
{
"model": "hub.areatype",
"pk": 4,
"fields": {
"name": "Single Tier Council",
"code": "STC",
"area_type": "Single Tier Council",
"description": "Single Tier Council"
}
},
{
"model": "hub.area",
"pk": 1,
Expand Down Expand Up @@ -51,6 +71,28 @@
"area_type_id": 1,
"geometry": "{\"name\": \"Borsetshire East\", \"properties\": {}}"
}
},
{
"model": "hub.area",
"pk": 101,
"fields": {
"gss": "E10000101",
"mapit_id": "101",
"name": "Borsetshire East District Council",
"area_type_id": 3,
"geometry": "{\"name\": \"Borsetshire East District Council\", \"properties\": {}}"
}
},
{
"model": "hub.area",
"pk": 102,
"fields": {
"gss": "E10000102",
"mapit_id": "102",
"name": "Borsetshire East Council",
"area_type_id": 4,
"geometry": "{\"name\": \"Borsetshire East Council\", \"properties\": {}}"
}
}
]

21 changes: 20 additions & 1 deletion hub/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,22 @@ def test_postcode_lookup(self, mapit_areas):
context = response.context
self.assertEqual(context["area"].name, "New South Borsetshire")

@patch("utils.mapit.MapIt.postcode_point_to_gss_codes")
def test_postcode_lookup_multiple_areas(self, mapit_areas):
mapit_areas.return_value = ["E10000005", "E10000101", "E10000002"]

url = reverse("area_search")
response = self.client.get(url, {"search": "SE17 3HE"}, follow=True)

self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "hub/area_search.html")

context = response.context
self.assertEqual(len(context["areas"]), 2)
self.assertContains(response, "New South Borsetshire")
self.assertContains(response, "Borsetshire East District Council")
self.assertNotContains(response, "Borsetshire West")

@patch("utils.mapit.session.get")
def test_bad_postcode(self, mapit_get):
mock_response = MagicMock()
Expand Down Expand Up @@ -562,7 +578,10 @@ def test_multiple_matches(self):
self.assertTemplateUsed(response, "hub/area_search.html")

context = response.context
self.assertEqual(len(context["areas"]), 3)
self.assertEqual(len(context["areas"]), 5)
self.assertContains(response, "Borsetshire East Council")
self.assertContains(response, "Borsetshire East District Council")
self.assertNotContains(response, "/WMC/Borsetshire East")


class testUserFavouriteViews(TestCase):
Expand Down

0 comments on commit b9c6a49

Please sign in to comment.