@@ -171,7 +171,8 @@ def test_get_returns_correct_results_for_topic(self):
171171
172172 # When
173173 query_params = {"topic" : topic }
174- response : Response = client .get (path = self .path , query_params = query_params )
174+ response : Response = client .get (
175+ path = self .path , query_params = query_params )
175176
176177 # Then
177178 # Geographies are returned in descending alphabetical order
@@ -244,7 +245,8 @@ def test_get_returns_correct_results_for_geography_type(self):
244245
245246 # When
246247 query_params = {"geography_type" : ltla }
247- response : Response = client .get (path = self .path , query_params = query_params )
248+ response : Response = client .get (
249+ path = self .path , query_params = query_params )
248250
249251 # Then
250252 # Geographies are returned in descending alphabetical order
@@ -265,3 +267,104 @@ def test_get_returns_correct_results_for_geography_type(self):
265267 assert result ["geographies" ][2 ]["geography_code" ] == hackney .geography_code
266268
267269 assert len (result ["geographies" ]) == 3
270+
271+
272+ class TestGeographiesByGeographyTypeView :
273+ @property
274+ def path (self ) -> str :
275+ return "/api/permission-set/geographies"
276+
277+ @pytest .mark .django_db
278+ def test_get_geographies_by_geography_type_id_should_return_geographies (self ):
279+
280+ client = APIClient ()
281+ ltla = "Lower Tier Local Authority"
282+
283+ bexley = GeographyFactory .create_with_geography_type (
284+ name = "Bexley" , geography_code = "E09000004" , geography_type = ltla
285+ )
286+ arun = GeographyFactory .create_with_geography_type (
287+ name = "Arun" , geography_code = "E07000224" , geography_type = ltla
288+ )
289+ hackney = GeographyFactory .create_with_geography_type (
290+ name = "Hackney" , geography_code = "E09000012" , geography_type = ltla
291+ )
292+ GeographyFactory .create_with_geography_type (
293+ name = "England" , geography_code = "E92000001" , geography_type = "Nation"
294+ )
295+
296+ geographyTypeId = 1
297+ path = f"{ self .path } /{ geographyTypeId } "
298+ response : Response = client .get (path = path )
299+ result = response .data
300+ assert len (response .data ["choices" ]) == 3
301+ assert result ["choices" ][0 ][0 ] == arun .geography_code
302+ assert result ["choices" ][0 ][1 ] == arun .name
303+
304+ assert result ["choices" ][1 ][0 ] == bexley .geography_code
305+ assert result ["choices" ][1 ][1 ] == bexley .name
306+
307+ assert result ["choices" ][2 ][0 ] == hackney .geography_code
308+ assert result ["choices" ][2 ][1 ] == hackney .name
309+
310+ @pytest .mark .django_db
311+ def test_get_geographies_by_geography_type_id_should_return_wildcard (self ):
312+
313+ client = APIClient ()
314+ ltla = "Lower Tier Local Authority"
315+
316+ bexley = GeographyFactory .create_with_geography_type (
317+ name = "Bexley" , geography_code = "E09000004" , geography_type = ltla
318+ )
319+ arun = GeographyFactory .create_with_geography_type (
320+ name = "Arun" , geography_code = "E07000224" , geography_type = ltla
321+ )
322+ hackney = GeographyFactory .create_with_geography_type (
323+ name = "Hackney" , geography_code = "E09000012" , geography_type = ltla
324+ )
325+ GeographyFactory .create_with_geography_type (
326+ name = "England" , geography_code = "E92000001" , geography_type = "Nation"
327+ )
328+
329+ geographyTypeId = - 1
330+ path = f"{ self .path } /{ geographyTypeId } "
331+ response : Response = client .get (path = path )
332+ result = response .data
333+
334+ # Choices length should only contain wildcard option
335+ assert len (response .data ["choices" ]) == 1
336+
337+ # Should return a wildcard choice
338+ assert result ["choices" ][0 ][0 ] == "-1"
339+ assert result ["choices" ][0 ][1 ] == "* (All geographies)"
340+
341+ @pytest .mark .django_db
342+ def test_get_geographies_by_geography_type_id_should_return_an_error (self ):
343+
344+ client = APIClient ()
345+ ltla = "Lower Tier Local Authority"
346+
347+ bexley = GeographyFactory .create_with_geography_type (
348+ name = "Bexley" , geography_code = "E09000004" , geography_type = ltla
349+ )
350+ arun = GeographyFactory .create_with_geography_type (
351+ name = "Arun" , geography_code = "E07000224" , geography_type = ltla
352+ )
353+ hackney = GeographyFactory .create_with_geography_type (
354+ name = "Hackney" , geography_code = "E09000012" , geography_type = ltla
355+ )
356+ GeographyFactory .create_with_geography_type (
357+ name = "England" , geography_code = "E92000001" , geography_type = "Nation"
358+ )
359+
360+ geographyTypeId = "string"
361+ path = f"{ self .path } /{ geographyTypeId } "
362+ response : Response = client .get (path = path )
363+ result = response .data
364+
365+ assert response .status_code == HTTPStatus .BAD_REQUEST
366+
367+ # data should contain error
368+
369+ assert str (result ["geography_type_id" ][0 ]
370+ ) == "Geography Type must be a number or '-1'"
0 commit comments