@@ -4022,15 +4022,17 @@ def test_collection_items(self) -> None:
40224022 # Create some repos
40234023 model_id = self ._api .create_repo (repo_name ()).repo_id
40244024 dataset_id = self ._api .create_repo (repo_name (), repo_type = "dataset" ).repo_id
4025+ collection_id = self ._api .create_collection ("nested collection" , exists_ok = True ).slug
40254026
40264027 # Create collection + add items to it
40274028 collection = self ._api .create_collection (self .title )
40284029 self ._api .add_collection_item (collection .slug , model_id , "model" , note = "This is my model" )
40294030 self ._api .add_collection_item (collection .slug , dataset_id , "dataset" ) # note is optional
4031+ self ._api .add_collection_item (collection .slug , collection_id , "collection" )
40304032
40314033 # Check consistency
40324034 collection = self ._api .get_collection (collection .slug )
4033- self .assertEqual (len (collection .items ), 2 )
4035+ self .assertEqual (len (collection .items ), 3 )
40344036 self .assertEqual (collection .items [0 ].item_id , model_id )
40354037 self .assertEqual (collection .items [0 ].item_type , "model" )
40364038 self .assertEqual (collection .items [0 ].note , "This is my model" )
@@ -4039,6 +4041,9 @@ def test_collection_items(self) -> None:
40394041 self .assertEqual (collection .items [1 ].item_type , "dataset" )
40404042 self .assertIsNone (collection .items [1 ].note )
40414043
4044+ self .assertEqual (collection .items [2 ].item_id , collection_id )
4045+ self .assertEqual (collection .items [2 ].item_type , "collection" )
4046+
40424047 # Add existing item fails (except if ignore error)
40434048 with self .assertRaises (HfHubHTTPError ):
40444049 self ._api .add_collection_item (collection .slug , model_id , "model" )
@@ -4065,7 +4070,7 @@ def test_collection_items(self) -> None:
40654070
40664071 # Check consistency
40674072 collection = self ._api .get_collection (collection .slug )
4068- self .assertEqual (len (collection .items ), 1 ) # only 1 item remaining
4073+ self .assertEqual (len (collection .items ), 2 ) # only 1 item remaining
40694074 self .assertEqual (collection .items [0 ].item_id , dataset_id ) # position got updated
40704075
40714076 # Delete everything
0 commit comments