1- import pandas as pd
21import pytest
32
43from digital_land .phase .lookup import LookupPhase , EntityLookupPhase , PrintLookupPhase
@@ -20,22 +19,6 @@ def get_input_stream():
2019 ]
2120
2221
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-
3922@pytest .fixture
4023def get_lookup ():
4124 return {",dataset,1,test" : "1" }
@@ -140,103 +123,6 @@ def test_process_empty_prefix(self, get_lookup):
140123
141124 assert output [0 ]["row" ]["entity" ] == "10"
142125
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 (
161- {
162- "organisation" : ["local-authority:ABC" ],
163- "dataset" : ["article-4-direction" ],
164- }
165- )
166- mocker .patch ("pandas.read_csv" , return_value = mock_df )
167- output = [block for block in phase .process (input_stream )]
168-
169- assert output [0 ]["row" ]["entity" ] == "2"
170- assert (
171- issues .rows [0 ]["issue-type" ]
172- == "no associated documents found for this area"
173- )
174- assert issues .rows [0 ]["value" ] == "a4d2"
175-
176- def test_no_associated_documents_issue_for_missing_dataset (
177- self , get_input_stream_with_linked_field , mocker
178- ):
179- input_stream = get_input_stream_with_linked_field
180-
181- lookups = {
182- ",article-4-direction,a4d1,local-authorityabc" : "1" ,
183- ",article-4-direction-area,1,local-authorityabc" : "2" ,
184- }
185- issues = IssueLog ()
186-
187- phase = LookupPhase (
188- lookups = lookups ,
189- issue_log = issues ,
190- provision_summary_dir = "var/cache/provision-summary/" ,
191- )
192- phase .entity_field = "entity"
193- mock_df = pd .DataFrame (
194- {
195- "organisation" : ["local-authority:XYZ" , "local-authority:ABC" ],
196- "dataset" : ["article-4-direction" , "article-4-direction-area" ],
197- }
198- )
199- mocker .patch ("pandas.read_csv" , return_value = mock_df )
200- output = [block for block in phase .process (input_stream )]
201-
202- assert output [0 ]["row" ]["entity" ] == "2"
203- assert len (issues .rows ) == 0
204-
205- def test_no_associated_documents_issue_for_retired_entity (
206- self , get_input_stream_with_linked_field , mocker
207- ):
208- input_stream = get_input_stream_with_linked_field
209-
210- lookups = {
211- ",article-4-direction,a4d2,local-authorityabc" : "1" ,
212- ",article-4-direction-area,1,local-authorityabc" : "2" ,
213- }
214- issues = IssueLog ()
215- redirect_lookups = {"1" : {"entity" : "" , "status" : "410" }}
216-
217- phase = LookupPhase (
218- lookups = lookups ,
219- redirect_lookups = redirect_lookups ,
220- issue_log = issues ,
221- provision_summary_dir = "var/cache/provision-summary/" ,
222- )
223- phase .entity_field = "entity"
224- mock_df = pd .DataFrame (
225- {
226- "organisation" : ["local-authority:ABC" ],
227- "dataset" : ["article-4-direction" ],
228- }
229- )
230- mocker .patch ("pandas.read_csv" , return_value = mock_df )
231- output = [block for block in phase .process (input_stream )]
232-
233- assert output [0 ]["row" ]["entity" ] == "2"
234- assert (
235- issues .rows [0 ]["issue-type" ]
236- == "no associated documents found for this area"
237- )
238- assert issues .rows [0 ]["value" ] == "a4d2"
239-
240126
241127class TestPrintLookupPhase :
242128 def test_process_does_not_produce_new_lookup (self , get_input_stream , get_lookup ):
0 commit comments