Skip to content

Commit ec262d6

Browse files
committed
fix for incorrect lsoa displaying on the page
1 parent 98b327f commit ec262d6

File tree

7 files changed

+232
-11
lines changed

7 files changed

+232
-11
lines changed

findthatpostcode/controllers/postcodes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ def get_area(self, areatype):
122122
"""
123123
Get the area for this postcode based on the type
124124
"""
125+
area_id = self.attributes.get(areatype)
126+
if area_id:
127+
for a in self.relationships["areas"]:
128+
if a.id == area_id:
129+
return a
130+
125131
for a in self.relationships["areas"]:
126132
if a.relationships["areatype"].id == areatype:
127133
return a

tests/blueprints/test_areatypes.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import html
22

3-
4-
AREATYPE_CODE = "lsoa11"
3+
AREATYPE_CODE = "lsoa21"
54

65

76
def test_areatype_json(client):
@@ -11,9 +10,9 @@ def test_areatype_json(client):
1110
assert rv.headers["Access-Control-Allow-Origin"] == "*"
1211
assert (
1312
data.get("data", {}).get("attributes", {}).get("full_name")
14-
== "2011 Census Lower Layer Super Output Area (LSOA)/ Data Zone (DZ)/ SOA"
13+
== "2021 Census Lower Layer Super Output Area (LSOA)/ Data Zone (DZ)/ SOA"
1514
)
16-
assert len(data.get("included", [])) == 8
15+
assert len(data.get("included", [])) == 9
1716

1817

1918
def test_areatype_json_missing(client):

tests/blueprints/test_extend.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_reconcile_spec(client):
3232

3333

3434
extend_q = {
35-
"extend": json.dumps({"ids": ["EX36 4AT"], "properties": [{"id": "lsoa11"}]})
35+
"extend": json.dumps({"ids": ["EX36 4AT"], "properties": [{"id": "lsoa21"}]})
3636
}
3737

3838

@@ -42,7 +42,8 @@ def test_reconcile_extend(client):
4242
assert rv.headers["Access-Control-Allow-Origin"] == "*"
4343
assert "meta" in result
4444
assert "EX36 4AT" in result["rows"]
45-
assert result["rows"]["EX36 4AT"]["lsoa11"] == "E01020135"
45+
assert "lsoa11" not in result["rows"]["EX36 4AT"]
46+
assert result["rows"]["EX36 4AT"]["lsoa21"] == "E01020135"
4647

4748

4849
def test_reconcile_extend_jsonp(client):
@@ -54,7 +55,8 @@ def test_reconcile_extend_jsonp(client):
5455
result = json.loads(data[len(extend_q["callback"]) + 1 : -1])
5556
assert "meta" in result
5657
assert "EX36 4AT" in result["rows"]
57-
assert result["rows"]["EX36 4AT"]["lsoa11"] == "E01020135"
58+
assert "lsoa11" not in result["rows"]["EX36 4AT"]
59+
assert result["rows"]["EX36 4AT"]["lsoa21"] == "E01020135"
5860

5961

6062
def test_reconcile_extend_post(client):
@@ -63,7 +65,8 @@ def test_reconcile_extend_post(client):
6365
assert rv.headers["Access-Control-Allow-Origin"] == "*"
6466
assert "meta" in result
6567
assert "EX36 4AT" in result["rows"]
66-
assert result["rows"]["EX36 4AT"]["lsoa11"] == "E01020135"
68+
assert "lsoa11" not in result["rows"]["EX36 4AT"]
69+
assert result["rows"]["EX36 4AT"]["lsoa21"] == "E01020135"
6770

6871

6972
def test_reconcile_extend_post_jsonp(client):
@@ -74,7 +77,8 @@ def test_reconcile_extend_post_jsonp(client):
7477
result = json.loads(data[len("testCallback") + 1 : -1])
7578
assert "meta" in result
7679
assert "EX36 4AT" in result["rows"]
77-
assert result["rows"]["EX36 4AT"]["lsoa11"] == "E01020135"
80+
assert "lsoa11" not in result["rows"]["EX36 4AT"]
81+
assert result["rows"]["EX36 4AT"]["lsoa21"] == "E01020135"
7882

7983

8084
recon_q = {

tests/blueprints/test_points.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_point_html(client):
2727
content = rv.data.decode("utf8")
2828
assert "EX36 4AT" in content
2929
assert "E01020135" in content
30+
assert "E01020122" not in content
3031
assert "69.0" in content
3132

3233

tests/blueprints/test_postcodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_postcode_html(client):
3333
content = rv.data.decode("utf8")
3434
assert "EX36 4AT" in content
3535
assert "E01020135" in content
36+
assert "E01020122" not in content
3637

3738

3839
def test_postcode_missing_html(client):

tests/mock_data/geo_area.json

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,216 @@
237237
}
238238
}
239239
},
240+
{
241+
"_index": "geo_area",
242+
"_type": "_doc",
243+
"_id": "E01020122",
244+
"_score": 0.9999991,
245+
"_source": {
246+
"code": "E01020122",
247+
"name": "North Devon 013C",
248+
"name_welsh": null,
249+
"statutory_instrument_id": null,
250+
"statutory_instrument_title": null,
251+
"date_start": "2004-02-01T00:00:00",
252+
"date_end": null,
253+
"parent": "E02004187",
254+
"entity": "E01",
255+
"owner": "ONS",
256+
"active": true,
257+
"areaehect": 61.02,
258+
"areachect": 61.02,
259+
"areaihect": 0,
260+
"arealhect": 61.02,
261+
"sort_order": "E01020122",
262+
"predecessor": [],
263+
"successor": [],
264+
"equivalents": {},
265+
"type": "lsoa21",
266+
"stats": {
267+
"imd2015": {
268+
"imd_education_adults_score": 0.385,
269+
"imd_income_decile": 4,
270+
"imd_health_score": 0.716,
271+
"imd_education_score": 34.489,
272+
"imd_employment_rank": 10031,
273+
"imd_education_rank": 7020,
274+
"imd_housing_wider_rank": 12794,
275+
"imd_environment_outdoors_score": -1.446,
276+
"imd_housing_rank": 23596,
277+
"imd_housing_geographical_rank": 23152,
278+
"imd_environment_indoors_rank": 10474,
279+
"imd_income_rank": 11103,
280+
"imd_environment_indoors_decile": 4,
281+
"imd_employment_score": 0.14,
282+
"imd_housing_geographical_score": -0.431,
283+
"imd_crime_score": -0.473,
284+
"imd_housing_score": 14.572,
285+
"imd_score": 23.636,
286+
"imd_crime_decile": 8,
287+
"imd_education_adults_rank": 7793,
288+
"imd_income_score": 0.164,
289+
"imd_environment_score": 17.411,
290+
"imd_education_children_rank": 6281,
291+
"imd_environment_decile": 6,
292+
"imd_housing_wider_decile": 4,
293+
"imd_health_rank": 6948,
294+
"imd_education_children_decile": 2,
295+
"imd_environment_indoors_score": 0.413,
296+
"imd_crime_rank": 23534,
297+
"imd_education_adults_decile": 3,
298+
"imd_environment_outdoors_rank": 10,
299+
"imd_health_decile": 3,
300+
"imd_environment_rank": 16535,
301+
"imd_decile": 4,
302+
"imd_housing_decile": 8,
303+
"imd_education_decile": 3,
304+
"imd_rank": 11666,
305+
"imd_employment_decile": 4,
306+
"imd_housing_geographical_decile": 8,
307+
"imd_education_children_score": 0.72,
308+
"imd_housing_wider_score": 0.529
309+
},
310+
"population2012": {
311+
"population_60_plus": 493,
312+
"population_total": 1615,
313+
"population_0_15": 310,
314+
"population_16_59": 812,
315+
"population_workingage": 815
316+
},
317+
"idaopi2015": {
318+
"idaopi_score": 0.225,
319+
"idaopi_rank": 10020,
320+
"idaopi_decile": 4
321+
},
322+
"idaci2015": {
323+
"idaci_score": 0.159,
324+
"idaci_decile": 5,
325+
"idaci_rank": 15523
326+
},
327+
"idaci2019": {
328+
"idaci_score": 0.214,
329+
"idaci_decile": 3,
330+
"idaci_rank": 9149
331+
},
332+
"imd2019": {
333+
"imd_education_adults_score": 0.385,
334+
"imd_income_decile": 3,
335+
"imd_health_score": 0.807,
336+
"imd_education_score": 31.279,
337+
"imd_employment_rank": 8412,
338+
"imd_education_rank": 8076,
339+
"imd_housing_wider_rank": 10625,
340+
"imd_environment_outdoors_score": -1.529,
341+
"imd_housing_rank": 20430,
342+
"imd_housing_geographical_rank": 22408,
343+
"imd_environment_indoors_rank": 19846,
344+
"imd_income_rank": 8086,
345+
"imd_environment_indoors_decile": 7,
346+
"imd_employment_score": 0.131,
347+
"imd_housing_geographical_score": -0.393,
348+
"imd_crime_score": -0.767,
349+
"imd_housing_score": 17.001,
350+
"imd_score": 25.2,
351+
"imd_crime_decile": 9,
352+
"imd_education_adults_rank": 7793,
353+
"imd_income_score": 0.179,
354+
"imd_environment_score": 7.729,
355+
"imd_education_children_rank": 8442,
356+
"imd_environment_decile": 9,
357+
"imd_housing_wider_decile": 4,
358+
"imd_health_rank": 5838,
359+
"imd_education_children_decile": 3,
360+
"imd_environment_indoors_score": -0.215,
361+
"imd_crime_rank": 26965,
362+
"imd_education_adults_decile": 3,
363+
"imd_environment_outdoors_rank": 10,
364+
"imd_health_decile": 2,
365+
"imd_environment_rank": 26471,
366+
"imd_decile": 4,
367+
"imd_housing_decile": 7,
368+
"imd_education_decile": 3,
369+
"imd_rank": 10643,
370+
"imd_employment_decile": 3,
371+
"imd_housing_geographical_decile": 7,
372+
"imd_education_children_score": 0.533,
373+
"imd_housing_wider_score": 0.981
374+
},
375+
"idaopi2019": {
376+
"idaopi_score": 0.214,
377+
"idaopi_rank": 9035,
378+
"idaopi_decile": 3
379+
},
380+
"population2015": {
381+
"population_60_plus": 493,
382+
"population_total": 1534,
383+
"population_0_15": 301,
384+
"population_16_59": 740,
385+
"population_workingage": 748
386+
},
387+
"idaci2025": {
388+
"idaci_score": 0.214,
389+
"idaci_decile": 3,
390+
"idaci_rank": 9149
391+
},
392+
"imd2025": {
393+
"imd_education_adults_score": 0.385,
394+
"imd_income_decile": 3,
395+
"imd_health_score": 0.807,
396+
"imd_education_score": 31.279,
397+
"imd_employment_rank": 8412,
398+
"imd_education_rank": 8076,
399+
"imd_housing_wider_rank": 10625,
400+
"imd_environment_outdoors_score": -1.529,
401+
"imd_housing_rank": 20430,
402+
"imd_housing_geographical_rank": 22408,
403+
"imd_environment_indoors_rank": 19846,
404+
"imd_income_rank": 8086,
405+
"imd_environment_indoors_decile": 7,
406+
"imd_employment_score": 0.131,
407+
"imd_housing_geographical_score": -0.393,
408+
"imd_crime_score": -0.767,
409+
"imd_housing_score": 17.001,
410+
"imd_score": 25.2,
411+
"imd_crime_decile": 9,
412+
"imd_education_adults_rank": 7793,
413+
"imd_income_score": 0.179,
414+
"imd_environment_score": 7.729,
415+
"imd_education_children_rank": 8442,
416+
"imd_environment_decile": 9,
417+
"imd_housing_wider_decile": 4,
418+
"imd_health_rank": 5838,
419+
"imd_education_children_decile": 3,
420+
"imd_environment_indoors_score": -0.215,
421+
"imd_crime_rank": 26965,
422+
"imd_education_adults_decile": 3,
423+
"imd_environment_outdoors_rank": 10,
424+
"imd_health_decile": 2,
425+
"imd_environment_rank": 26471,
426+
"imd_decile": 4,
427+
"imd_housing_decile": 7,
428+
"imd_education_decile": 3,
429+
"imd_rank": 10643,
430+
"imd_employment_decile": 3,
431+
"imd_housing_geographical_decile": 7,
432+
"imd_education_children_score": 0.533,
433+
"imd_housing_wider_score": 0.981
434+
},
435+
"idaopi2025": {
436+
"idaopi_score": 0.214,
437+
"idaopi_rank": 9035,
438+
"idaopi_decile": 3
439+
},
440+
"population2023": {
441+
"population_60_plus": 493,
442+
"population_total": 1534,
443+
"population_0_15": 301,
444+
"population_16_59": 740,
445+
"population_workingage": 748
446+
}
447+
}
448+
}
449+
},
240450
{
241451
"_index": "geo_area",
242452
"_type": "_doc",

tests/mock_data/geo_postcode.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"pct": "E16000145",
3131
"nuts": "E05012435",
3232
"park": null,
33-
"lsoa11": "E01020135",
34-
"msoa11": "E02004187",
33+
"lsoa11": "E01020122",
34+
"msoa11": "E02004122",
3535
"lsoa21": "E01020135",
3636
"msoa21": "E02004187",
3737
"wz11": "E33049068",

0 commit comments

Comments
 (0)