@@ -47,35 +47,82 @@ def test_publisher_license(self):
4747class TestAdditionalDataSourceLicences (TestCase ):
4848 fixtures = ["test_data.json" ]
4949
50- def _assert_licence (self , source , expected_licence ):
50+ def test_source_licenses_aggregation (self ):
51+ """Test that GrantMetadataSource aggregates licenses from all sources"""
5152 grant = Grant .objects .first ()
5253 additional_data = {}
5354
54- source .update_additional_data (
55- grant .data , grant .source_file .data , additional_data
56- )
55+ # Create source instances
56+ sources = {
57+ "find_that_charity_source" : FindThatCharitySource (),
58+ "geo_lookup" : GeoLookupSource (),
59+ "nspl_source" : NSPLSource (),
60+ "code_lists" : CodeListSource (),
61+ }
5762
58- licence_key = f"{ source .ADDITIONAL_DATA_KEY } _LICENCE"
63+ grant_metadata_source = GrantMetadataSource ()
64+
65+ # Call with sources parameter
66+ grant_metadata_source .update_additional_data (
67+ grant .data , grant .source_file .data , additional_data , sources = sources
68+ )
5969
70+ # Verify the structure
6071 self .assertIn (
61- licence_key ,
72+ "metadata" ,
6273 additional_data ,
63- f" { licence_key } was not added by { source . __class__ . __name__ } ." ,
74+ "metadata key was not added." ,
6475 )
65- self .assertEqual (
66- additional_data [licence_key ],
67- expected_licence ,
68- f"{ source .__class__ .__name__ } set the wrong licence value." ,
76+
77+ self .assertIn (
78+ "sources_metadata" ,
79+ additional_data ["metadata" ],
80+ "sources_metadata was not aggregated by GrantMetadataSource." ,
6981 )
7082
71- def test_find_that_charity_licence (self ):
72- self ._assert_licence (FindThatCharitySource (), OGL_V3 )
83+ sources_metadata = additional_data ["metadata" ]["sources_metadata" ]
7384
74- def test_geo_lookup_licence (self ):
75- self ._assert_licence (GeoLookupSource (), OGL_V3 )
85+ # Verify each source's license is present
86+ self .assertIn (
87+ "recipientOrgInfos" ,
88+ sources_metadata ,
89+ "FindThatCharitySource license not aggregated." ,
90+ )
91+ self .assertEqual (
92+ sources_metadata ["recipientOrgInfos" ]["license" ],
93+ OGL_V3 ,
94+ "FindThatCharitySource has wrong license." ,
95+ )
7696
77- def test_nspl_licence (self ):
78- self ._assert_licence (NSPLSource (), OGL_V3 )
97+ self .assertIn (
98+ "locationLookup" ,
99+ sources_metadata ,
100+ "GeoLookupSource license not aggregated." ,
101+ )
102+ self .assertEqual (
103+ sources_metadata ["locationLookup" ]["license" ],
104+ OGL_V3 ,
105+ "GeoLookupSource has wrong license." ,
106+ )
79107
80- def test_codelist_lookup_licence (self ):
81- self ._assert_licence (CodeListSource (), CC_BY_4 )
108+ self .assertIn (
109+ "recipientOrganizationLocation" ,
110+ sources_metadata ,
111+ "NSPLSource license not aggregated." ,
112+ )
113+ self .assertEqual (
114+ sources_metadata ["recipientOrganizationLocation" ]["license" ],
115+ OGL_V3 ,
116+ "NSPLSource has wrong license." ,
117+ )
118+
119+ self .assertIn (
120+ "codeListLookup" ,
121+ sources_metadata ,
122+ "CodeListSource license not aggregated." ,
123+ )
124+ self .assertEqual (
125+ sources_metadata ["codeListLookup" ]["license" ],
126+ CC_BY_4 ,
127+ "CodeListSource has wrong license." ,
128+ )
0 commit comments