@@ -291,6 +291,40 @@ def test_issue0008a(om):
291291 assert actual == expected
292292
293293
294+ @pytest .mark .parametrize ("om" , [openminds .v5 , openminds .latest ])
295+ def test_issue0008b (om ):
296+ # https://github.com/openMetadataInitiative/openMINDS_Python/issues/8
297+ # The instance of linked types in instances of embedded types are integrated as embedded not linked
298+ # (example: organization -> memberships (embedded) -> person (linked))
299+
300+ person = om .core .Person (
301+ id = "_:002" ,
302+ preferred_name = "A" ,
303+ family_name = "Professor"
304+ )
305+
306+ uni1 = om .core .Organization (
307+ name = "University of This Place" ,
308+ id = "_:001" ,
309+ memberships = om .core .Membership (member = person , end_date = date (2023 , 9 , 30 ))
310+ )
311+ actual = uni1 .to_jsonld (include_empty_properties = False , embed_linked_nodes = False , with_context = True )
312+ expected = {
313+ '@context' : {'@vocab' : 'https://openminds.om-i.org/props/' },
314+ '@id' : '_:001' ,
315+ '@type' : 'https://openminds.om-i.org/types/Organization' ,
316+ 'membership' : [
317+ {
318+ '@type' : 'https://openminds.om-i.org/types/Membership' ,
319+ 'endDate' : '2023-09-30' ,
320+ 'member' : {'@id' : '_:002' }
321+ }
322+ ],
323+ 'name' : 'University of This Place'
324+ }
325+ assert actual == expected
326+
327+
294328@pytest .mark .parametrize ("om" , [openminds .v4 ])
295329def test_issue0026a (om ):
296330 # https://github.com/openMetadataInitiative/openMINDS_Python/issues/26
@@ -317,6 +351,33 @@ def test_issue0026a(om):
317351 assert person_again .affiliations [0 ].member_of .full_name == "University of This Place"
318352
319353
354+ @pytest .mark .parametrize ("om" , [openminds .v5 , openminds .latest ])
355+ def test_issue0026b (om ):
356+ # https://github.com/openMetadataInitiative/openMINDS_Python/issues/26
357+ # When reading a JSON-LD file, the attributes of LinkedMetadata nodes
358+ # inside EmbeddedMetadata nodes are not set properly
359+
360+ person = om .core .Person (
361+ preferred_name = "A" , family_name = "Professor" , id = "_:ap"
362+ )
363+ uni1 = om .core .Organization (name = "University of This Place" ,
364+ id = "_:uthisp" ,
365+ memberships = [om .core .Membership (member = person )])
366+ c = Collection (uni1 )
367+
368+ # person was not added explicitly, but should nevertheless be included in the JSON-LD export
369+
370+ output_paths = c .save ("issue0026.jsonld" , individual_files = False , include_empty_properties = False )
371+
372+ new_collection = Collection ()
373+ new_collection .load (* output_paths , version = om .__name__ .split ("." )[1 ])
374+ os .remove ("issue0026.jsonld" )
375+
376+ uni_again = [item for item in new_collection if isinstance (item , om .core .Organization )][0 ]
377+ assert len (uni_again .memberships ) == 1
378+ assert uni_again .memberships [0 ].member .family_name == "Professor"
379+
380+
320381@pytest .mark .parametrize ("om" , [openminds .v4 ])
321382def test_issue0023a (om ):
322383 # https://github.com/openMetadataInitiative/openMINDS_Python/issues/23
@@ -351,6 +412,50 @@ def test_issue0023a(om):
351412 assert dv_again .custodians [0 ].affiliations [1 ].member_of .full_name == "University of That Place"
352413
353414
415+ @pytest .mark .parametrize ("om" , [openminds .v5 ])
416+ def test_issue0023b (om ):
417+ # https://github.com/openMetadataInitiative/openMINDS_Python/issues/23
418+ # If a user adds an instance/node to a collection, and then later adds linked types to the instance,
419+ # currently that is not added to the collection
420+
421+ person = om .core .Person (
422+ preferred_name = "A" , family_name = "Professor" , id = "_:ap"
423+ )
424+ uni1 = om .core .Organization (name = "University of This Place" ,
425+ id = "_:uthisp" ,
426+ memberships = [om .core .Membership (member = person )])
427+ dv = om .core .DatasetVersion (full_name = "The name of the dataset version" ,
428+ contributions = [om .core .Contribution (contributors = [uni1 ],
429+ type = om .controlled_terms .contribution_type .ContributionType .by_name ('custodianship' ))],
430+ id = "_:dv" )
431+
432+ c = Collection (dv )
433+
434+ # even though we add uni2 and the repository after creating the collection,
435+ # they should be included when we save the collection.
436+ person2 = om .core .Person (
437+ preferred_name = "B" , family_name = "Professor" , id = "_:bp"
438+ )
439+ uni1 .memberships .append (om .core .Membership (member = person2 ))
440+ #dv.contributions.append(om.core.Contribution(contributors=[uni2],
441+ #type=om.controlled_terms.contribution_type.ContributionType.by_name('ownership')))
442+ dv .repository = om .core .FileRepository (iri = "http://example.com" , id = "_:fr" )
443+
444+ output_paths = c .save ("issue0023.jsonld" , individual_files = False , include_empty_properties = False )
445+
446+ new_collection = Collection ()
447+ new_collection .load (* output_paths , version = om .__name__ .split ("." )[1 ])
448+ os .remove ("issue0023.jsonld" )
449+
450+ dv_again = [item for item in new_collection if isinstance (item , om .core .DatasetVersion )][0 ]
451+ assert isinstance (dv_again .repository , om .core .FileRepository )
452+ assert dv_again .repository .iri .value == "http://example.com"
453+ assert len (dv_again .contributions [0 ].contributors [0 ].memberships ) == 2
454+ assert (dv_again .contributions [0 ].contributors [0 ].name == "University of This Place" )
455+ assert dv_again .contributions [0 ].contributors [0 ].memberships [0 ].member .preferred_name == "A"
456+ assert dv_again .contributions [0 ].contributors [0 ].memberships [1 ].member .preferred_name == "B"
457+
458+
354459@pytest .mark .parametrize ("om" , [openminds .latest , openminds .v4 ])
355460def test_issue0056 (om ):
356461 # https://github.com/openMetadataInitiative/openMINDS_Python/issues/56
0 commit comments