Skip to content

Commit 59f7211

Browse files
committed
Adding json response for 410 when triggered with extention .json
1 parent e631662 commit 59f7211

File tree

4 files changed

+35
-50
lines changed

4 files changed

+35
-50
lines changed

application/routers/entity.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ def get_entity(
7979
e, old_entity_status, new_entity_id = get_entity_query(session, entity)
8080

8181
if old_entity_status == 410:
82-
return templates.TemplateResponse(
83-
"entity-gone.html",
84-
{
85-
"request": request,
86-
"entity": str(entity),
87-
},
88-
)
82+
if extension:
83+
raise HTTPException(
84+
detail=f"Entity {entity} has been removed", status_code=410
85+
)
86+
else:
87+
return templates.TemplateResponse(
88+
"entity-gone.html",
89+
{
90+
"request": request,
91+
"entity": str(entity),
92+
},
93+
status_code=410,
94+
)
8995
elif old_entity_status == 301:
9096
if extension:
9197
return RedirectResponse(
@@ -278,7 +284,7 @@ def search_entities(
278284
columns = ["dataset", "name", "plural", "typology", "themes", "paint_options"]
279285
datasets = [dataset.dict(include=set(columns)) for dataset in response]
280286

281-
local_authorities = get_local_authorities(session, "local-authority")
287+
local_authorities = get_local_authorities(session, "local-authority-eng")
282288
local_authorities = [la.dict() for la in local_authorities]
283289

284290
if links.get("prev") is not None:
+14-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
11
{% extends "layouts/layout.html" %}
2+
{% set mainClasses = "govuk-main-wrapper--l" %}
23
{% set templateName = "dl-info/entity-gone.html" %}
34

45
{%- block content %}
56

6-
{% block recordHead %}
7-
{% block recordTitle -%}
8-
<span class="govuk-caption-xl">Entity Removed</span>
9-
<h1 class="govuk-heading-xl">Entity Removed</h1>
10-
{%- endblock recordTitle %}
11-
{% endblock recordHead %}
7+
<div class="govuk-grid-row">
8+
<div class="govuk-grid-column-two-thirds">
9+
<h1 class="govuk-heading-l">Entity Removed</h1>
1210

1311
<p class="govuk-body">
1412
This entity (#{{entity}}) has been removed.
1513
</p>
1614

17-
{%- endblock content %}
18-
19-
{% block recordEnd %}{% endblock recordEnd %}
20-
21-
{% block footerStart %}
22-
{%- from "components/feedback/macro.jinja" import dlFeedback %}
23-
{% set subject = "Feedback on removed entity with number " + entity %}
24-
{{ dlFeedback({
25-
"text": "Spotted an issue? Let us know so we can improve the data.",
26-
"action": {
27-
"text": "There is something wrong with the data",
28-
"href": "mailto:" + templateVar.email + "?subject=" + subject
29-
},
30-
"container": true
31-
})
32-
}}
33-
{% endblock footerStart %}
34-
35-
{%- block pageScripts %}{%- endblock %}
15+
{%- from "components/feedback/macro.jinja" import dlFeedback %}
16+
{% set subject = "Feedback on removed entity with number " + entity %}
17+
<div class="govuk-body">
18+
Spotted an issue? You can
19+
<a href="mailto:{{ templateVar.email }}?subject={{ subject }}" class="govuk-link"> contact the Planning Data team </a>
20+
if you need to speak to someone about this page.
21+
</div>
22+
</div>
23+
</div>
24+
{%- endblock %}

tests/integration/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_old_entity_gone_shown(test_data_old_entities, client, exclude_middlewar
120120
"""
121121
old_entity = test_data_old_entities["old_entities"][410][0]
122122
response = client.get(f"/entity/{old_entity.old_entity_id}", allow_redirects=False)
123-
assert response.status_code == 200
123+
assert response.status_code == 410
124124
assert (
125125
f"This entity (#{old_entity.old_entity_id}) has been removed." in response.text
126126
)

tests/unit/routers/test_entity.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,11 @@ def test_get_entity_old_entity_gone_returned_json(mocker):
212212
request = MagicMock()
213213
extension = MagicMock()
214214
extension.value = "json"
215-
result = get_entity(request=request, entity="11000000", extension=extension)
216215
try:
217-
result.template.render(result.context)
216+
get_entity(request=request, entity="11000000", extension=extension)
217+
assert False, "Expected HTTPException to be raised"
218+
except HTTPException:
218219
assert True
219-
except Exception:
220-
if hasattr(result, "context"):
221-
logging.warning(f"context:{result.context}")
222-
else:
223-
logging.warning("result has no context")
224-
assert False, "template unable to render, missing variable(s) from context"
225220

226221

227222
def test_get_entity_old_entity_gone_returned_geojson(mocker):
@@ -231,16 +226,11 @@ def test_get_entity_old_entity_gone_returned_geojson(mocker):
231226
request = MagicMock()
232227
extension = MagicMock()
233228
extension.value = "geojson"
234-
result = get_entity(request=request, entity="11000000", extension=extension)
235229
try:
236-
result.template.render(result.context)
230+
get_entity(request=request, entity="11000000", extension=extension)
231+
assert False, "Expected HTTPException to be raised"
232+
except HTTPException:
237233
assert True
238-
except Exception:
239-
if hasattr(result, "context"):
240-
logging.warning(f"context:{result.context}")
241-
else:
242-
logging.warning("result has no context")
243-
assert False, "template unable to render, missing variable(s) from context"
244234

245235

246236
def test_get_entity_old_entity_redirect_returned_html(mocker):

0 commit comments

Comments
 (0)