@@ -214,6 +214,145 @@ def test_update_variable_base_catalog(self):
214214 # self link must remain in place
215215 self .assertEqual (result ["links" ][0 ]["rel" ], "self" )
216216
217+ # ------------------------------------------------------------------
218+ # osc_project parameter
219+ # ------------------------------------------------------------------
220+
221+ def test_osc_project_default (self ):
222+ """Default osc_project is 'deep-earth-system-data-lab'."""
223+ self .assertEqual (self .generator .osc_project , "deep-earth-system-data-lab" )
224+
225+ @patch ("deep_code.utils.dataset_stac_generator.open_dataset" )
226+ def test_osc_project_custom (self , mock_open_ds ):
227+ """A custom osc_project is stored on the generator."""
228+ mock_open_ds .return_value = self .mock_dataset
229+ gen = OscDatasetStacGenerator (
230+ dataset_id = "mock-dataset-id" ,
231+ collection_id = "mock-collection-id" ,
232+ workflow_id = "dummy" ,
233+ workflow_title = "test" ,
234+ license_type = "proprietary" ,
235+ osc_project = "my-custom-project" ,
236+ )
237+ self .assertEqual (gen .osc_project , "my-custom-project" )
238+
239+ def test_build_dataset_stac_collection_osc_project_in_related_link (self ):
240+ """The project-related link in the collection uses the configured osc_project."""
241+ collection = self .generator .build_dataset_stac_collection (mode = "dataset" )
242+ project_links = [
243+ lnk
244+ for lnk in collection .links
245+ if lnk .rel == "related" and "projects" in str (lnk .target )
246+ ]
247+ self .assertEqual (len (project_links ), 1 )
248+ self .assertIn ("deep-earth-system-data-lab" , project_links [0 ].target )
249+
250+ # ------------------------------------------------------------------
251+ # build_project_collection
252+ # ------------------------------------------------------------------
253+
254+ def test_build_project_collection_structure (self ):
255+ """build_project_collection returns a minimal valid STAC Collection dict."""
256+ result = self .generator .build_project_collection ()
257+
258+ self .assertIsInstance (result , dict )
259+ self .assertEqual (result ["type" ], "Collection" )
260+ self .assertEqual (result ["id" ], "deep-earth-system-data-lab" )
261+ self .assertEqual (result ["stac_version" ], "1.0.0" )
262+ self .assertIn ("extent" , result )
263+
264+ rels = [lnk ["rel" ] for lnk in result ["links" ]]
265+ self .assertIn ("self" , rels )
266+ self .assertIn ("root" , rels )
267+ self .assertIn ("parent" , rels )
268+
269+ self_link = next (lnk for lnk in result ["links" ] if lnk ["rel" ] == "self" )
270+ self .assertIn ("deep-earth-system-data-lab" , self_link ["href" ])
271+ self .assertTrue (self_link ["href" ].endswith ("collection.json" ))
272+
273+ @patch ("deep_code.utils.dataset_stac_generator.open_dataset" )
274+ def test_build_project_collection_custom_project (self , mock_open_ds ):
275+ """build_project_collection reflects a custom osc_project."""
276+ mock_open_ds .return_value = self .mock_dataset
277+ gen = OscDatasetStacGenerator (
278+ dataset_id = "mock-dataset-id" ,
279+ collection_id = "mock-collection-id" ,
280+ workflow_id = "dummy" ,
281+ workflow_title = "test" ,
282+ license_type = "proprietary" ,
283+ osc_project = "my-project" ,
284+ )
285+ result = gen .build_project_collection ()
286+
287+ self .assertEqual (result ["id" ], "my-project" )
288+ self_link = next (lnk for lnk in result ["links" ] if lnk ["rel" ] == "self" )
289+ self .assertIn ("my-project" , self_link ["href" ])
290+
291+ # ------------------------------------------------------------------
292+ # update_project_base_catalog
293+ # ------------------------------------------------------------------
294+
295+ def test_update_project_base_catalog (self ):
296+ """Child link for the project is appended to the projects base catalog."""
297+ import json as _json , os , tempfile
298+
299+ base = {
300+ "type" : "Catalog" ,
301+ "id" : "projects" ,
302+ "stac_version" : "1.0.0" ,
303+ "description" : "Projects" ,
304+ "links" : [
305+ {
306+ "rel" : "self" ,
307+ "href" : "https://esa-earthcode.github.io/open-science-catalog-metadata/projects/catalog.json" ,
308+ "type" : "application/json" ,
309+ }
310+ ],
311+ }
312+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".json" , delete = False ) as tmp :
313+ _json .dump (base , tmp )
314+ tmp_path = tmp .name
315+
316+ result = self .generator .update_project_base_catalog (tmp_path )
317+ os .unlink (tmp_path )
318+
319+ self .assertIsInstance (result , dict )
320+ child_links = [lnk for lnk in result ["links" ] if lnk ["rel" ] == "child" ]
321+ self .assertEqual (len (child_links ), 1 )
322+ self .assertIn ("deep-earth-system-data-lab" , child_links [0 ]["href" ])
323+ self .assertTrue (child_links [0 ]["href" ].endswith ("collection.json" ))
324+ # existing self link is preserved
325+ self .assertEqual (result ["links" ][0 ]["rel" ], "self" )
326+
327+ def test_update_project_base_catalog_no_duplicate (self ):
328+ """Calling update_project_base_catalog when the child link already exists
329+ does not produce a duplicate."""
330+ import json as _json , os , tempfile
331+
332+ base = {
333+ "type" : "Catalog" ,
334+ "id" : "projects" ,
335+ "stac_version" : "1.0.0" ,
336+ "description" : "Projects" ,
337+ "links" : [
338+ {
339+ "rel" : "child" ,
340+ "href" : "./deep-earth-system-data-lab/collection.json" ,
341+ "type" : "application/json" ,
342+ "title" : "Deep Earth System Data Lab" ,
343+ }
344+ ],
345+ }
346+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".json" , delete = False ) as tmp :
347+ _json .dump (base , tmp )
348+ tmp_path = tmp .name
349+
350+ result = self .generator .update_project_base_catalog (tmp_path )
351+ os .unlink (tmp_path )
352+
353+ child_links = [lnk for lnk in result ["links" ] if lnk ["rel" ] == "child" ]
354+ self .assertEqual (len (child_links ), 1 )
355+
217356 def test_update_deepesdl_collection (self ):
218357 """Child and theme-related links are appended; existing links kept."""
219358 base = {
0 commit comments