Skip to content

Commit 67d80cd

Browse files
committed
alter lookup_rule source
1 parent 8503be2 commit 67d80cd

2 files changed

Lines changed: 29 additions & 24 deletions

File tree

digital_land/pipeline/main.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(self, path, dataset, specification=None, config=None):
106106
self.load_combine_fields()
107107
self.load_migrate()
108108
self.load_lookup()
109+
self.load_lookup_rule()
109110
self.load_redirect_lookup()
110111
self.load_filter()
111112

@@ -266,10 +267,32 @@ def load_lookup(self):
266267
entity = row.get("entity", "")
267268
resource = row.get("resource", "")
268269

269-
# rows with no entity are treated as range-based rules
270+
# composite key, ordered by specificity
271+
resource_lookup = self.lookup.setdefault(resource, {})
272+
resource_lookup[
273+
lookup_key(
274+
entry_number=entry_number,
275+
prefix=prefix,
276+
reference=reference,
277+
organisation=organisation,
278+
)
279+
] = entity
280+
281+
def load_lookup_rule(self):
282+
for row in self.file_reader("lookup-rule.csv"):
283+
prefix = (
284+
row.get("prefix", "")
285+
or row.get("dataset", "")
286+
or row.get("pipeline", "")
287+
)
288+
organisation = row.get("organisation", "")
289+
organisation = organisation.replace(
290+
"local-authority-eng", "local-authority"
291+
)
292+
resource = row.get("resource", "")
293+
270294
if (
271-
not entity
272-
and row.get("offset", "")
295+
row.get("offset", "")
273296
and row.get("entity-minimum", "")
274297
and row.get("entity-maximum", "")
275298
):
@@ -281,18 +304,6 @@ def load_lookup(self):
281304
"entity-maximum": int(row.get("entity-maximum", 0)),
282305
}
283306
self.rule_lookup.setdefault(resource, []).append(rule)
284-
continue
285-
286-
# composite key, ordered by specificity
287-
resource_lookup = self.lookup.setdefault(resource, {})
288-
resource_lookup[
289-
lookup_key(
290-
entry_number=entry_number,
291-
prefix=prefix,
292-
reference=reference,
293-
organisation=organisation,
294-
)
295-
] = entity
296307

297308
def load_redirect_lookup(self):
298309
for row in self.file_reader("old-entity.csv"):

tests/unit/test_pipeline.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ def mock_file_reader(self, filepath):
4747

4848
def test_load_lookup_rule_with_all_fields(self, mocker):
4949
def mock_file_reader(self, filepath):
50-
if filepath == "lookup.csv":
50+
if filepath == "lookup-rule.csv":
5151
return [
5252
{
5353
"prefix": "listed-building",
5454
"organisation": "",
55-
"reference": "",
56-
"entity": "",
5755
"offset": "1000000",
5856
"entity-minimum": "1000000",
5957
"entity-maximum": "2000000",
@@ -75,13 +73,11 @@ def mock_file_reader(self, filepath):
7573

7674
def test_load_lookup_rule_missing_entity_minimum(self, mocker):
7775
def mock_file_reader(self, filepath):
78-
if filepath == "lookup.csv":
76+
if filepath == "lookup-rule.csv":
7977
return [
8078
{
8179
"prefix": "listed-building",
8280
"organisation": "",
83-
"reference": "",
84-
"entity": "",
8581
"offset": "1000000",
8682
"entity-minimum": "",
8783
"entity-maximum": "2000000",
@@ -99,13 +95,11 @@ def mock_file_reader(self, filepath):
9995

10096
def test_load_lookup_rule_missing_entity_maximum(self, mocker):
10197
def mock_file_reader(self, filepath):
102-
if filepath == "lookup.csv":
98+
if filepath == "lookup-rule.csv":
10399
return [
104100
{
105101
"prefix": "listed-building",
106102
"organisation": "",
107-
"reference": "",
108-
"entity": "",
109103
"offset": "1000000",
110104
"entity-minimum": "1000000",
111105
"entity-maximum": "",

0 commit comments

Comments
 (0)