11import pytest
22
3- from digital_land .phase .lookup import LookupPhase , EntityLookupPhase , PrintLookupPhase
3+ from digital_land .phase .lookup import (
4+ LookupPhase ,
5+ EntityLookupPhase ,
6+ PrintLookupPhase ,
7+ FactLookupPhase ,
8+ )
49from digital_land .log import IssueLog
510
611
@@ -24,13 +29,15 @@ def get_input_stream_with_linked_field():
2429 return [
2530 {
2631 "row" : {
27- "prefix" : "article-4-direction-area" ,
28- "reference" : "1" ,
29- "organisation" : "local-authority:ABC" ,
30- "article-4-direction" : "a4d2" ,
31- },
32- "entry-number" : 1 ,
33- "line-number" : 2 ,
32+ "fact" : "abc" ,
33+ "entity" : "10" ,
34+ "field" : "article-4-direction" ,
35+ "value" : "a4d1" ,
36+ "prefix" : "article-4-direction" ,
37+ "reference" : "a4d1" ,
38+ "entry-number" : 1 ,
39+ "line-number" : 2 ,
40+ }
3441 }
3542 ]
3643
@@ -139,56 +146,6 @@ def test_process_empty_prefix(self, get_lookup):
139146
140147 assert output [0 ]["row" ]["entity" ] == "10"
141148
142- def test_no_associated_documents_issue (self , get_input_stream_with_linked_field ):
143- input_stream = get_input_stream_with_linked_field
144-
145- lookups = {
146- ",article-4-direction,a4d1,local-authorityabc" : "1" ,
147- ",article-4-direction-area,1,local-authorityabc" : "2" ,
148- }
149- issues = IssueLog ()
150-
151- phase = LookupPhase (
152- lookups = lookups ,
153- issue_log = issues ,
154- )
155- phase .entity_field = "entity"
156- output = [block for block in phase .process (input_stream )]
157-
158- assert output [0 ]["row" ]["entity" ] == "2"
159- assert (
160- issues .rows [0 ]["issue-type" ]
161- == "no associated documents found for this area"
162- )
163- assert issues .rows [0 ]["value" ] == "a4d2"
164-
165- def test_no_associated_documents_issue_for_retired_entity (
166- self , get_input_stream_with_linked_field
167- ):
168- input_stream = get_input_stream_with_linked_field
169-
170- lookups = {
171- ",article-4-direction,a4d2,local-authorityabc" : "1" ,
172- ",article-4-direction-area,1,local-authorityabc" : "2" ,
173- }
174- issues = IssueLog ()
175- redirect_lookups = {"1" : {"entity" : "" , "status" : "410" }}
176-
177- phase = LookupPhase (
178- lookups = lookups ,
179- redirect_lookups = redirect_lookups ,
180- issue_log = issues ,
181- )
182- phase .entity_field = "entity"
183- output = [block for block in phase .process (input_stream )]
184-
185- assert output [0 ]["row" ]["entity" ] == "2"
186- assert (
187- issues .rows [0 ]["issue-type" ]
188- == "no associated documents found for this area"
189- )
190- assert issues .rows [0 ]["value" ] == "a4d2"
191-
192149
193150class TestPrintLookupPhase :
194151 def test_process_does_not_produce_new_lookup (self , get_input_stream , get_lookup ):
@@ -262,3 +219,76 @@ def test_entity_lookup_phase_blank(self):
262219 output = [block for block in phase .process (input_stream )]
263220
264221 assert len (output ) == 0
222+
223+
224+ class TestFactLookupPhase :
225+ def test_no_associated_documents_issue_raised (
226+ self , get_input_stream_with_linked_field
227+ ):
228+ input_stream = get_input_stream_with_linked_field
229+ lookups = {
230+ ",article-4-direction,a4d2,local-authorityabc" : "1" ,
231+ ",article-4-direction-area,1,local-authorityabc" : "10" ,
232+ }
233+ issues = IssueLog ()
234+
235+ phase = FactLookupPhase (
236+ lookups = lookups ,
237+ issue_log = issues ,
238+ )
239+ phase .entity_field = "reference-entity"
240+ output = [block for block in phase .process (input_stream )]
241+
242+ assert "reference-entity" not in output
243+ assert (
244+ issues .rows [0 ]["issue-type" ]
245+ == "no associated documents found for this area"
246+ )
247+ assert issues .rows [0 ]["value" ] == "a4d1"
248+
249+ def test_no_associated_documents_issue_for_retired_entity (
250+ self , get_input_stream_with_linked_field
251+ ):
252+ input_stream = get_input_stream_with_linked_field
253+
254+ lookups = {
255+ ",article-4-direction,a4d1,local-authorityabc" : "1" ,
256+ ",article-4-direction-area,1,local-authorityabc" : "10" ,
257+ }
258+ issues = IssueLog ()
259+ redirect_lookups = {"1" : {"entity" : "" , "status" : "410" }}
260+
261+ phase = FactLookupPhase (
262+ lookups = lookups ,
263+ redirect_lookups = redirect_lookups ,
264+ issue_log = issues ,
265+ )
266+ phase .entity_field = "reference-entity"
267+ output = [block for block in phase .process (input_stream )]
268+
269+ assert "reference-entity" not in output
270+ assert (
271+ issues .rows [0 ]["issue-type" ]
272+ == "no associated documents found for this area"
273+ )
274+ assert issues .rows [0 ]["value" ] == "a4d1"
275+
276+ def test_no_associated_documents_issue_not_raised (
277+ self , get_input_stream_with_linked_field
278+ ):
279+ input_stream = get_input_stream_with_linked_field
280+ lookups = {
281+ ",article-4-direction,a4d1,local-authorityabc" : "1" ,
282+ ",article-4-direction-area,1,local-authorityabc" : "10" ,
283+ }
284+ issues = IssueLog ()
285+
286+ phase = FactLookupPhase (
287+ lookups = lookups ,
288+ issue_log = issues ,
289+ )
290+ phase .entity_field = "reference-entity"
291+ output = [block for block in phase .process (input_stream )]
292+
293+ assert output [0 ]["row" ]["reference-entity" ] == "1"
294+ assert len (issues .rows ) == 0
0 commit comments