@@ -74,3 +74,60 @@ def test_round_trip_multi_file():
74
74
p = person .to_jsonld (include_empty_properties = False , embed_linked_nodes = True )
75
75
np = new_person .to_jsonld (include_empty_properties = False , embed_linked_nodes = True )
76
76
assert p == np
77
+
78
+
79
+ def test_collection_sort_by_id ():
80
+ person = omcore .Person (given_name = "A" , family_name = "Professor" , id = "_:004" )
81
+ uni1 = omcore .Organization (full_name = "University of This Place" , id = "_:002" )
82
+ uni2 = omcore .Organization (full_name = "University of That Place" , id = "_:001" )
83
+ person .affiliations = [
84
+ omcore .Affiliation (member_of = uni1 ),
85
+ omcore .Affiliation (member_of = uni2 ),
86
+ ]
87
+
88
+ c = Collection (person ,uni1 ,uni2 )
89
+ output_paths = c .save ("test_collection_sort_by_id.jsonld" , individual_files = False , include_empty_properties = False )
90
+
91
+ assert output_paths == ["test_collection_sort_by_id.jsonld" ]
92
+
93
+ with open (output_paths [0 ]) as fp :
94
+ saved_data = json .load (fp )
95
+ os .remove ("test_collection_sort_by_id.jsonld" )
96
+
97
+ expected_saved_data = {
98
+ "@context" : {"@vocab" : "https://openminds.ebrains.eu/vocab/" },
99
+ "@graph" : [
100
+ {
101
+ "@id" : "_:001" ,
102
+ "@type" : "https://openminds.ebrains.eu/core/Organization" ,
103
+ "fullName" : "University of That Place"
104
+ },
105
+ {
106
+ "@id" : "_:002" ,
107
+ "@type" : "https://openminds.ebrains.eu/core/Organization" ,
108
+ "fullName" : "University of This Place"
109
+ },
110
+ {
111
+ "@id" : "_:004" ,
112
+ "@type" : "https://openminds.ebrains.eu/core/Person" ,
113
+ "affiliation" : [
114
+ {
115
+ "@type" : "https://openminds.ebrains.eu/core/Affiliation" ,
116
+ "memberOf" : {
117
+ "@id" : "_:002"
118
+ }
119
+ },
120
+ {
121
+ "@type" : "https://openminds.ebrains.eu/core/Affiliation" ,
122
+ "memberOf" : {
123
+ "@id" : "_:001"
124
+ }
125
+ }
126
+ ],
127
+ "familyName" : "Professor" ,
128
+ "givenName" : "A"
129
+ }
130
+ ]
131
+ }
132
+
133
+ assert saved_data == expected_saved_data
0 commit comments