@@ -4020,15 +4020,17 @@ def test_collection_items(self) -> None:
40204020 # Create some repos
40214021 model_id = self ._api .create_repo (repo_name ()).repo_id
40224022 dataset_id = self ._api .create_repo (repo_name (), repo_type = "dataset" ).repo_id
4023+ collection_id = self ._api .create_collection ("nested collection" , exists_ok = True ).slug
40234024
40244025 # Create collection + add items to it
40254026 collection = self ._api .create_collection (self .title )
40264027 self ._api .add_collection_item (collection .slug , model_id , "model" , note = "This is my model" )
40274028 self ._api .add_collection_item (collection .slug , dataset_id , "dataset" ) # note is optional
4029+ self ._api .add_collection_item (collection .slug , collection_id , "collection" )
40284030
40294031 # Check consistency
40304032 collection = self ._api .get_collection (collection .slug )
4031- self .assertEqual (len (collection .items ), 2 )
4033+ self .assertEqual (len (collection .items ), 3 )
40324034 self .assertEqual (collection .items [0 ].item_id , model_id )
40334035 self .assertEqual (collection .items [0 ].item_type , "model" )
40344036 self .assertEqual (collection .items [0 ].note , "This is my model" )
@@ -4037,6 +4039,9 @@ def test_collection_items(self) -> None:
40374039 self .assertEqual (collection .items [1 ].item_type , "dataset" )
40384040 self .assertIsNone (collection .items [1 ].note )
40394041
4042+ self .assertEqual (collection .items [2 ].item_id , collection_id )
4043+ self .assertEqual (collection .items [2 ].item_type , "collection" )
4044+
40404045 # Add existing item fails (except if ignore error)
40414046 with self .assertRaises (HfHubHTTPError ):
40424047 self ._api .add_collection_item (collection .slug , model_id , "model" )
@@ -4063,7 +4068,7 @@ def test_collection_items(self) -> None:
40634068
40644069 # Check consistency
40654070 collection = self ._api .get_collection (collection .slug )
4066- self .assertEqual (len (collection .items ), 1 ) # only 1 item remaining
4071+ self .assertEqual (len (collection .items ), 2 ) # only 1 item remaining
40674072 self .assertEqual (collection .items [0 ].item_id , dataset_id ) # position got updated
40684073
40694074 # Delete everything
0 commit comments