diff --git a/digital_land/organisation.py b/digital_land/organisation.py index a9b3dfa6..fcb37dc5 100644 --- a/digital_land/organisation.py +++ b/digital_land/organisation.py @@ -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()] diff --git a/tests/integration/test_organisation.py b/tests/integration/test_organisation.py new file mode 100644 index 00000000..4490c54e --- /dev/null +++ b/tests/integration/test_organisation.py @@ -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" + ) diff --git a/tests/unit/test_organisation.py b/tests/unit/test_organisation.py deleted file mode 100644 index b11ec40c..00000000 --- a/tests/unit/test_organisation.py +++ /dev/null @@ -1,48 +0,0 @@ -from digital_land.organisation import Organisation - - -def test_organisation_lookup(): - 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"