|
1 | 1 | from django.test import TestCase |
2 | 2 |
|
3 | 3 | 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 |
4 | 8 | from db.models import Grant |
5 | 9 |
|
| 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 | + |
6 | 13 |
|
7 | 14 | class TestAdditionalDataLicense(TestCase): |
8 | 15 | fixtures = ["test_data.json"] |
@@ -35,3 +42,40 @@ def test_publisher_license(self): |
35 | 42 | expected_additional_data, |
36 | 43 | "The additional license data added is not correct.", |
37 | 44 | ) |
| 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) |
0 commit comments