1+ import pandas as pd
12import pytest
23
34from digital_land .phase .lookup import LookupPhase , EntityLookupPhase , PrintLookupPhase
@@ -19,6 +20,22 @@ def get_input_stream():
1920 ]
2021
2122
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+
2239@pytest .fixture
2340def get_lookup ():
2441 return {",dataset,1,test" : "1" }
@@ -123,6 +140,88 @@ def test_process_empty_prefix(self, get_lookup):
123140
124141 assert output [0 ]["row" ]["entity" ] == "10"
125142
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
147+
148+ lookups = {
149+ ",article-4-direction,a4d1,local-authorityabc" : "1" ,
150+ ",article-4-direction-area,1,local-authorityabc" : "2" ,
151+ }
152+ issues = IssueLog ()
153+
154+ phase = LookupPhase (
155+ lookups = lookups ,
156+ issue_log = issues ,
157+ provision_summary_dir = "var/cache/provision-summary/" ,
158+ )
159+ phase .entity_field = "entity"
160+ mock_df = pd .DataFrame ({"organisation" : ["local-authority:ABC" ]})
161+ mocker .patch ("pandas.read_csv" , return_value = mock_df )
162+ output = [block for block in phase .process (input_stream )]
163+
164+ assert output [0 ]["row" ]["entity" ] == "2"
165+ assert (
166+ issues .rows [0 ]["issue-type" ]
167+ == "no associated documents found for this area"
168+ )
169+ assert issues .rows [0 ]["value" ] == "a4d2"
170+
171+ def test_no_associated_documents_issue_for_missing_dataset (
172+ self , get_input_stream_with_linked_field , mocker
173+ ):
174+ input_stream = get_input_stream_with_linked_field
175+
176+ lookups = {
177+ ",article-4-direction,a4d1,local-authorityabc" : "1" ,
178+ ",article-4-direction-area,1,local-authorityabc" : "2" ,
179+ }
180+ issues = IssueLog ()
181+
182+ phase = LookupPhase (
183+ lookups = lookups ,
184+ issue_log = issues ,
185+ provision_summary_dir = "var/cache/provision-summary/" ,
186+ )
187+ phase .entity_field = "entity"
188+ mock_df = pd .DataFrame ({"organisation" : ["local-authority:XYZ" ]})
189+ mocker .patch ("pandas.read_csv" , return_value = mock_df )
190+ output = [block for block in phase .process (input_stream )]
191+
192+ assert output [0 ]["row" ]["entity" ] == "2"
193+ assert len (issues .rows ) == 0
194+
195+ def test_no_associated_documents_issue_for_retired_entity (
196+ self , get_input_stream_with_linked_field , mocker
197+ ):
198+ input_stream = get_input_stream_with_linked_field
199+
200+ lookups = {
201+ ",article-4-direction,a4d2,local-authorityabc" : "1" ,
202+ ",article-4-direction-area,1,local-authorityabc" : "2" ,
203+ }
204+ issues = IssueLog ()
205+ redirect_lookups = {"1" : {"entity" : "" , "status" : "410" }}
206+
207+ phase = LookupPhase (
208+ lookups = lookups ,
209+ redirect_lookups = redirect_lookups ,
210+ issue_log = issues ,
211+ provision_summary_dir = "var/cache/provision-summary/" ,
212+ )
213+ phase .entity_field = "entity"
214+ mock_df = pd .DataFrame ({"organisation" : ["local-authority:ABC" ]})
215+ mocker .patch ("pandas.read_csv" , return_value = mock_df )
216+ output = [block for block in phase .process (input_stream )]
217+
218+ assert output [0 ]["row" ]["entity" ] == "2"
219+ assert (
220+ issues .rows [0 ]["issue-type" ]
221+ == "no associated documents found for this area"
222+ )
223+ assert issues .rows [0 ]["value" ] == "a4d2"
224+
126225
127226class TestPrintLookupPhase :
128227 def test_process_does_not_produce_new_lookup (self , get_input_stream , get_lookup ):
0 commit comments