Skip to content

Commit fda34e0

Browse files
committed
additional_data: sources: add licence info
#213
1 parent 9968958 commit fda34e0

7 files changed

Lines changed: 73 additions & 3 deletions

File tree

datastore/additional_data/sources/codelist_code.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class CodeListSource(object):
2323
responsible for field: codeListLookup
2424
"""
2525

26+
ADDITIONAL_DATA_KEY = "codeListLookup"
27+
LICENCE = "https://creativecommons.org/licenses/by/4.0/"
28+
2629
def import_codelists(self):
2730
with transaction.atomic():
2831
CodelistCode.objects.all().delete()
@@ -136,3 +139,5 @@ def update_additional_data(self, grant, source_file, additional_data):
136139
"recipientOrg_location_countryCode": recipientOrg_location_countryCode,
137140
"fundingOrg_location_countryCode": fundingOrg_location_countryCode,
138141
}
142+
143+
additional_data[f"{self.ADDITIONAL_DATA_KEY}_LICENCE"] = self.LICENCE

datastore/additional_data/sources/find_that_charity.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class FindThatCharitySource(object):
7474
FindThatCharity (FTC) organisation info data sources"""
7575

7676
ADDITIONAL_DATA_KEY = "recipientOrgInfos"
77+
LICENCE = (
78+
"https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/"
79+
)
7780

7881
def __init__(self, *args, **kwargs):
7982
# A basic internal memory cache to avoid hitting the db on duplicate
@@ -83,6 +86,8 @@ def __init__(self, *args, **kwargs):
8386
self._cache = {}
8487

8588
def update_additional_data(self, grant, source_file, additional_data):
89+
additional_data[f"{self.ADDITIONAL_DATA_KEY}_LICENCE"] = self.LICENCE
90+
8691
# We can't do anything if this grant doesn't have a recipientOrganization
8792
if not grant.get("recipientOrganization"):
8893
return

datastore/additional_data/sources/geo_lookup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class GeoLookupSource(object):
1313
"""Imports geographical lookups from https://github.com/drkane/geo-lookups/
1414
These allow for looking up from lower-level geography like Ward to a standard local authority, region, etc"""
1515

16+
ADDITIONAL_DATA_KEY = "locationLookup"
17+
LICENCE = (
18+
"https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/"
19+
)
20+
1621
# Source URLS
1722
SOURCE_URLS = {
1823
"lsoa": {
@@ -143,3 +148,5 @@ def update_additional_data(self, grant, source_file, additional_data):
143148
area["source"] = "recipientOrganizationPostcode"
144149
area["sourceCode"] = lsoa
145150
additional_data["locationLookup"].append(area)
151+
152+
additional_data[f"{self.ADDITIONAL_DATA_KEY}_LICENCE"] = self.LICENCE

datastore/additional_data/sources/nspl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class NSPLSource(object):
2424
# Search for the most recent "National Statistics Postcode Lookup 2021 Cencus"
2525
# https://geoportal.statistics.gov.uk/search?collection=Dataset&q=National%20Statistics%20Postcode%20Lookup%20-%202021%20Census&sort=-modified&source=office%20for%20national%20statistics&tags=national%20statistics%20postcode%20lookup%2C2021_cencus&type=csv%20collection
2626
NSPL_URL = "https://www.arcgis.com/sharing/rest/content/items/204e40244d4d4903ba1861d492f47d29/data"
27+
ADDITIONAL_DATA_KEY = "recipientOrganizationLocation"
28+
LICENCE = (
29+
"https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/"
30+
)
2731

2832
def __init__(self):
2933
self._nspl_cache = {}
@@ -204,3 +208,5 @@ def update_additional_data(self, grant, source_file, additional_data):
204208
self.update_location_data_code_names(location_data)
205209
additional_data["recipientOrganizationLocation"] = location_data
206210
break
211+
212+
additional_data[f"{self.ADDITIONAL_DATA_KEY}_LICENCE"] = self.LICENCE

datastore/tests/test_additional_data_codelist_code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def test_code_list(self):
3737
"beneficiaryLocation_countryCode": "Australia",
3838
"fundingOrg_location_countryCode": "France",
3939
"recipientOrg_location_countryCode": "United Kingdom of Great Britain and Northern Ireland",
40-
}
40+
},
41+
"codeListLookup_LICENCE": "https://creativecommons.org/licenses/by/4.0/",
4142
}
4243

4344
source.update_additional_data(grant, source_file, additional_data_in)

datastore/tests/test_additional_data_license.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
from django.test import TestCase
22

33
from additional_data.sources.grant_metadata import GrantMetadataSource
4+
from additional_data.sources.find_that_charity import FindThatCharitySource
5+
from additional_data.sources.geo_lookup import GeoLookupSource
6+
from additional_data.sources.nspl import NSPLSource
7+
from additional_data.sources.codelist_code import CodeListSource
48
from db.models import Grant
59

10+
OGL_V3 = "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/"
11+
CC_BY_4 = "https://creativecommons.org/licenses/by/4.0/"
12+
613

714
class TestAdditionalDataLicense(TestCase):
815
fixtures = ["test_data.json"]
@@ -35,3 +42,40 @@ def test_publisher_license(self):
3542
expected_additional_data,
3643
"The additional license data added is not correct.",
3744
)
45+
46+
47+
class TestAdditionalDataSourceLicences(TestCase):
48+
fixtures = ["test_data.json"]
49+
50+
def _assert_licence(self, source, expected_licence):
51+
grant = Grant.objects.first()
52+
additional_data = {}
53+
54+
source.update_additional_data(
55+
grant.data, grant.source_file.data, additional_data
56+
)
57+
58+
licence_key = f"{source.ADDITIONAL_DATA_KEY}_LICENCE"
59+
60+
self.assertIn(
61+
licence_key,
62+
additional_data,
63+
f"{licence_key} was not added by {source.__class__.__name__}.",
64+
)
65+
self.assertEqual(
66+
additional_data[licence_key],
67+
expected_licence,
68+
f"{source.__class__.__name__} set the wrong licence value.",
69+
)
70+
71+
def test_find_that_charity_licence(self):
72+
self._assert_licence(FindThatCharitySource(), OGL_V3)
73+
74+
def test_geo_lookup_licence(self):
75+
self._assert_licence(GeoLookupSource(), OGL_V3)
76+
77+
def test_nspl_licence(self):
78+
self._assert_licence(NSPLSource(), OGL_V3)
79+
80+
def test_codelist_lookup_licence(self):
81+
self._assert_licence(CodeListSource(), CC_BY_4)

datastore/tests/test_additional_data_nspl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def test_nspl_update_additional_data_with_not_existing_postcode(self):
200200
nspl.update_additional_data(grant.data, grant.source_file.data, additional_data)
201201

202202
self.assertNotIn("recipientOrganizationLocation", additional_data)
203-
self.assertEqual(len(additional_data), 0)
203+
self.assertEqual(len(additional_data), 1)
204+
self.assertIn("recipientOrganizationLocation_LICENCE", additional_data)
204205

205206
def test_nspl_update_additional_data_without_postcode(self):
206207
self.save_nspl_mock_data()
@@ -214,7 +215,8 @@ def test_nspl_update_additional_data_without_postcode(self):
214215
nspl.update_additional_data(grant.data, grant.source_file.data, additional_data)
215216

216217
self.assertNotIn("recipientOrganizationLocation", additional_data)
217-
self.assertEqual(len(additional_data), 0)
218+
self.assertEqual(len(additional_data), 1)
219+
self.assertIn("recipientOrganizationLocation_LICENCE", additional_data)
218220

219221
def test_nspl_update_additional_data_breaks_after_updating(self):
220222
# Once we have one recipient org location, the loop should break.

0 commit comments

Comments
 (0)