Skip to content

Commit eb6679e

Browse files
committed
raise issue if the found entity is retired
1 parent e844ec7 commit eb6679e

File tree

2 files changed

+61
-27
lines changed

2 files changed

+61
-27
lines changed

digital_land/phase/lookup.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,16 @@ def process(self, stream):
212212
organisation=row.get("organisation", ""),
213213
reference=row.get(linked_dataset, ""),
214214
)
215-
if not find_entity:
215+
# raise issue if the found entity is retired in old-entity.csv
216+
if not find_entity or (
217+
str(find_entity) in self.redirect_lookups
218+
and int(
219+
self.redirect_lookups[str(find_entity)].get(
220+
"status", 0
221+
)
222+
)
223+
== 410
224+
):
216225
self.issues.log_issue(
217226
linked_dataset,
218227
"no associated documents found for this area",

tests/unit/phase/test_lookup.py

+51-26
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ def get_input_stream():
2020
]
2121

2222

23+
@pytest.fixture
24+
def get_input_stream_with_linked_field():
25+
return [
26+
{
27+
"row": {
28+
"prefix": "article-4-direction-area",
29+
"reference": "1",
30+
"organisation": "local-authority:ABC",
31+
"article-4-direction": "a4d2",
32+
},
33+
"entry-number": 1,
34+
"line-number": 2,
35+
}
36+
]
37+
38+
2339
@pytest.fixture
2440
def get_lookup():
2541
return {",dataset,1,test": "1"}
@@ -124,19 +140,10 @@ def test_process_empty_prefix(self, get_lookup):
124140

125141
assert output[0]["row"]["entity"] == "10"
126142

127-
def test_no_associated_documents_issue(self, mocker):
128-
input_stream = [
129-
{
130-
"row": {
131-
"prefix": "article-4-direction-area",
132-
"reference": "1",
133-
"organisation": "local-authority:ABC",
134-
"article-4-direction": "a4d2",
135-
},
136-
"entry-number": 1,
137-
"line-number": 2,
138-
}
139-
]
143+
def test_no_associated_documents_issue(
144+
self, get_input_stream_with_linked_field, mocker
145+
):
146+
input_stream = get_input_stream_with_linked_field
140147

141148
lookups = {
142149
",article-4-direction,a4d1,local-authorityabc": "1",
@@ -157,19 +164,10 @@ def test_no_associated_documents_issue(self, mocker):
157164
)
158165
assert issues.rows[0]["value"] == "a4d2"
159166

160-
def test_no_associated_documents_issue_for_missing_dataset(self, mocker):
161-
input_stream = [
162-
{
163-
"row": {
164-
"prefix": "article-4-direction-area",
165-
"reference": "1",
166-
"organisation": "local-authority:ABC",
167-
"article-4-direction": "a4d2",
168-
},
169-
"entry-number": 1,
170-
"line-number": 2,
171-
}
172-
]
167+
def test_no_associated_documents_issue_for_missing_dataset(
168+
self, get_input_stream_with_linked_field, mocker
169+
):
170+
input_stream = get_input_stream_with_linked_field
173171

174172
lookups = {
175173
",article-4-direction,a4d1,local-authorityabc": "1",
@@ -186,6 +184,33 @@ def test_no_associated_documents_issue_for_missing_dataset(self, mocker):
186184
assert output[0]["row"]["entity"] == "2"
187185
assert len(issues.rows) == 0
188186

187+
def test_no_associated_documents_issue_for_retired_entity(
188+
self, get_input_stream_with_linked_field, mocker
189+
):
190+
input_stream = get_input_stream_with_linked_field
191+
192+
lookups = {
193+
",article-4-direction,a4d2,local-authorityabc": "1",
194+
",article-4-direction-area,1,local-authorityabc": "2",
195+
}
196+
issues = IssueLog()
197+
redirect_lookups = {"1": {"entity": "", "status": "410"}}
198+
199+
phase = LookupPhase(
200+
lookups=lookups, redirect_lookups=redirect_lookups, issue_log=issues
201+
)
202+
phase.entity_field = "entity"
203+
mock_df = pd.DataFrame({"organisation": ["local-authority:ABC"]})
204+
mocker.patch("pandas.read_csv", return_value=mock_df)
205+
output = [block for block in phase.process(input_stream)]
206+
207+
assert output[0]["row"]["entity"] == "2"
208+
assert (
209+
issues.rows[0]["issue-type"]
210+
== "no associated documents found for this area"
211+
)
212+
assert issues.rows[0]["value"] == "a4d2"
213+
189214

190215
class TestPrintLookupPhase:
191216
def test_process_does_not_produce_new_lookup(self, get_input_stream, get_lookup):

0 commit comments

Comments
 (0)