Skip to content

Commit

Permalink
Map organisation to self
Browse files Browse the repository at this point in the history
  • Loading branch information
psd committed Apr 6, 2022
1 parent 3a47bea commit 2aebe6e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
3 changes: 3 additions & 0 deletions digital_land/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def load_organisation(self):
if row["field"] == "OrganisationURI":
self.organisation_uri[lower_uri(row["pattern"])] = row["value"]

for key in self.organisation:
self.organisation_lookup[key.lower()] = key

def lookup(self, organisation):
if not organisation:
return organisation
Expand Down
64 changes: 36 additions & 28 deletions tests/unit/test_organisation.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
import pytest
from digital_land.log import IssueLog
from digital_land.datatype.organisation import OrganisationURIDataType
from digital_land.organisation import Organisation


@pytest.mark.skip()
def test_OrganisationURI_normalise():
issues = IssueLog()

organisation_uri = OrganisationURIDataType()

assert "grape" not in organisation_uri.enum
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_uri.normalise(
organisation.lookup(
"http://opendatacommunities.org/id/district-council/brentwood"
)
== "http://opendatacommunities.org/id/district-council/brentwood"
== "local-authority-eng:BRW"
)

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

assert organisation_uri.normalise("foo") == ""

assert organisation_uri.normalise("foo", issues=issues) == ""
issue = issues.rows.pop()
assert issue["issue-type"] == "OrganisationURI"
assert issue["value"] == "foo"
assert issues.rows == []

with pytest.raises(ValueError):
organisation_uri.add_value(
"http://opendatacommunities.org/id/district-council/borchester", "ambridge"
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"

0 comments on commit 2aebe6e

Please sign in to comment.