Skip to content

Commit

Permalink
Feat/org lookup (#156)
Browse files Browse the repository at this point in the history
* add extra step to deal with migration from local-authority-eng to local-authoriity

* update key to match if statement

* move to integration tests as they are using the file system and add test or -eng removal
  • Loading branch information
eveleighoj authored Dec 5, 2023
1 parent a48cf31 commit 5416de4
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 50 deletions.
9 changes: 7 additions & 2 deletions digital_land/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def lookup(self, organisation):
organisation = organisation[len(leg) :]

if organisation.lower() not in self.organisation_lookup:
logging.info(f"unknown organisation {organisation}")
return ""
if organisation.lower().replace("-eng", "") in self.organisation_lookup:
return self.organisation_lookup[
organisation.lower().replace("-eng", "")
]
else:
logging.info(f"unknown organisation {organisation}")
return ""
return self.organisation_lookup[organisation.lower()]
75 changes: 75 additions & 0 deletions tests/integration/test_organisation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from digital_land.organisation import Organisation
import csv
import logging


class TestOrganisation:
def test_organisation_lookup(self):
organisation = Organisation(
organisation_path="tests/data/listed-building/organisation.csv"
)

assert organisation.lookup("Borchester") == ""
assert (
organisation.lookup("local-authority-eng:LBH") == "local-authority-eng:LBH"
)
assert (
organisation.lookup("government-organisation:PB1164")
== "government-organisation:PB1164"
)
assert (
organisation.lookup(
"http://opendatacommunities.org/id/district-council/brentwood"
)
== "local-authority-eng:BRW"
)

assert (
organisation.lookup(
"http://opendatacommunities.org/id/district-council/tamworth"
)
== "local-authority-eng:TAW"
)
assert (
organisation.lookup(
"http://opendatacommunities.org/doc/district-council/tamworth"
)
== "local-authority-eng:TAW"
)
assert (
organisation.lookup(
"https://opendatacommunities.org/id/district-council/tamworth"
)
== "local-authority-eng:TAW"
)
assert (
organisation.lookup(
"https://opendatacommunities.org/doc/district-council/tamworth"
)
== "local-authority-eng:TAW"
)

assert organisation.lookup("E07000068") == "local-authority-eng:BRW"
assert organisation.lookup("Lambeth") == "local-authority-eng:LBH"

def test_organisation_lookup_eng_removed(self, tmp_path):
org_match = {
"organisation": "development-corporation:Q20648596",
"entity": 1,
"wikidata": "Q20648596",
"name": "Example",
"statistical-geography": "E000001",
"opendatacommunities": "http://opendatacommunities.org/id/dev-corp/old-oak-and-park-royal",
}
logging.warning(type(org_match))
with open(tmp_path / "test.csv", "w") as f:
dictwriter = csv.DictWriter(f, fieldnames=org_match.keys())
dictwriter.writeheader()
logging.warning(type(org_match))
dictwriter.writerow(org_match)
organisation = Organisation(
organisation_path="tests/data/listed-building/organisation.csv"
)
assert (
organisation.lookup("local-authority-eng:BRW") == "local-authority-eng:BRW"
)
48 changes: 0 additions & 48 deletions tests/unit/test_organisation.py

This file was deleted.

0 comments on commit 5416de4

Please sign in to comment.