@@ -222,6 +222,54 @@ def test_add_child_throws_if_item(self) -> None:
222
222
with pytest .raises (pystac .STACError ):
223
223
cat .add_child (item ) # type:ignore
224
224
225
+ def test_add_child_override_parent (self ) -> None :
226
+ parent1 = Catalog (id = "parent1" , description = "test1" )
227
+ parent2 = Catalog (id = "parent2" , description = "test2" )
228
+ child = Catalog (id = "child" , description = "test3" )
229
+ assert child .get_parent () is None
230
+
231
+ parent1 .add_child (child )
232
+ assert child .get_parent () is parent1
233
+
234
+ parent2 .add_child (child )
235
+ assert child .get_parent () is parent2
236
+
237
+ def test_add_child_keep_parent (self ) -> None :
238
+ parent1 = Catalog (id = "parent1" , description = "test1" )
239
+ parent2 = Catalog (id = "parent2" , description = "test2" )
240
+ child = Catalog (id = "child" , description = "test3" )
241
+ assert child .get_parent () is None
242
+
243
+ parent1 .add_child (child , keep_parent = True )
244
+ assert child .get_parent () is parent1
245
+
246
+ parent2 .add_child (child , keep_parent = True )
247
+ assert child .get_parent () is parent1
248
+
249
+ def test_add_item_override_parent (self ) -> None :
250
+ parent1 = Catalog (id = "parent1" , description = "test1" )
251
+ parent2 = Catalog (id = "parent2" , description = "test2" )
252
+ child = Item (id = "child" , description = "test3" )
253
+ assert child .get_parent () is None
254
+
255
+ parent1 .add_item (child )
256
+ assert child .get_parent () is parent1
257
+
258
+ parent2 .add_item (child )
259
+ assert child .get_parent () is parent2
260
+
261
+ def test_add_item_keep_parent (self ) -> None :
262
+ parent1 = Catalog (id = "parent1" , description = "test1" )
263
+ parent2 = Catalog (id = "parent2" , description = "test2" )
264
+ child = Item (id = "child" , description = "test3" )
265
+ assert child .get_parent () is None
266
+
267
+ parent1 .add_item (child , keep_parent = True )
268
+ assert child .get_parent () is parent1
269
+
270
+ parent2 .add_item (child , keep_parent = True )
271
+ assert child .get_parent () is parent1
272
+
225
273
def test_add_item_throws_if_child (self ) -> None :
226
274
cat = TestCases .case_1 ()
227
275
child = next (iter (cat .get_children ()))
0 commit comments