@@ -3053,73 +3053,10 @@ class ActivityApiTest(unittest.TestCase):
3053
3053
def setUpClass (cls ) -> None :
3054
3054
cls .api = HfApi () # no auth!
3055
3055
3056
- def test_like_and_unlike_repo (self ) -> None :
3057
- # Create and like a private and a public repo
3058
- repo_id_private = self .api .create_repo (repo_name (), token = TOKEN , private = True ).repo_id
3059
- self .api .like (repo_id_private , token = TOKEN )
3060
-
3061
- repo_id_public = self .api .create_repo (repo_name (), token = TOKEN , private = False ).repo_id
3062
- self .api .like (repo_id_public , token = TOKEN )
3063
-
3064
- # Get likes as public and authenticated
3065
- likes = self .api .list_liked_repos (USER )
3066
- likes_with_auth = self .api .list_liked_repos (USER , token = TOKEN )
3067
-
3068
- # Public repo is shown in liked repos
3069
- self .assertIn (repo_id_public , likes .models )
3070
- self .assertIn (repo_id_public , likes_with_auth .models )
3071
-
3072
- # Private repo is NOT shown in liked repos, even when authenticated
3073
- # This is by design. See https://github.com/huggingface/moon-landing/pull/4879 (internal link)
3074
- self .assertNotIn (repo_id_private , likes .models )
3075
- self .assertNotIn (repo_id_private , likes_with_auth .models )
3076
-
3077
- # Unlike repo and check not in liked list
3078
- self .api .unlike (repo_id_public , token = TOKEN )
3079
- self .api .unlike (repo_id_private , token = TOKEN )
3080
- likes_after_unlike = self .api .list_liked_repos (USER )
3081
- self .assertNotIn (repo_id_public , likes_after_unlike .models ) # Unliked
3082
-
3083
- # Cleanup
3084
- self .api .delete_repo (repo_id_public , token = TOKEN )
3085
- self .api .delete_repo (repo_id_private , token = TOKEN )
3086
-
3087
- def test_like_missing_repo (self ) -> None :
3088
- with self .assertRaises (RepositoryNotFoundError ):
3089
- self .api .like ("missing_repo_id" , token = TOKEN )
3090
-
3056
+ def test_unlike_missing_repo (self ) -> None :
3091
3057
with self .assertRaises (RepositoryNotFoundError ):
3092
3058
self .api .unlike ("missing_repo_id" , token = TOKEN )
3093
3059
3094
- def test_like_twice (self ) -> None :
3095
- # Create and like repo
3096
- repo_id = self .api .create_repo (repo_name (), token = TOKEN , private = True ).repo_id
3097
-
3098
- # Can like twice
3099
- self .api .like (repo_id , token = TOKEN )
3100
- self .api .like (repo_id , token = TOKEN )
3101
-
3102
- # Can unlike twice
3103
- self .api .unlike (repo_id , token = TOKEN )
3104
- self .api .unlike (repo_id , token = TOKEN )
3105
-
3106
- # Cleanup
3107
- self .api .delete_repo (repo_id , token = TOKEN )
3108
-
3109
- def test_list_liked_repos_no_auth (self ) -> None :
3110
- # Create a repo + like
3111
- repo_id = self .api .create_repo (repo_name (), exist_ok = True , token = TOKEN ).repo_id
3112
- self .api .like (repo_id , token = TOKEN )
3113
-
3114
- # Fetch liked repos without auth
3115
- likes = self .api .list_liked_repos (USER , token = False )
3116
- self .assertEqual (likes .user , USER )
3117
- self .assertGreater (len (likes .models ) + len (likes .datasets ) + len (likes .spaces ), 0 )
3118
- self .assertIn (repo_id , likes .models )
3119
-
3120
- # Cleanup
3121
- self .api .delete_repo (repo_id , token = TOKEN )
3122
-
3123
3060
def test_list_likes_repos_auth_and_implicit_user (self ) -> None :
3124
3061
# User is implicit
3125
3062
likes = self .api .list_liked_repos (token = TOKEN )
@@ -3364,9 +3301,12 @@ def test_commit_to_repo_in_background(self, repo_url: RepoUrl) -> None:
3364
3301
@use_tmp_repo ()
3365
3302
def test_run_as_future (self , repo_url : RepoUrl ) -> None :
3366
3303
repo_id = repo_url .repo_id
3367
- self ._api .run_as_future (self ._api .like , repo_id )
3304
+ # update repo visibility to private
3305
+ self ._api .run_as_future (self ._api .update_repo_settings , repo_id = repo_id , private = True )
3368
3306
future_1 = self ._api .run_as_future (self ._api .model_info , repo_id = repo_id )
3369
- self ._api .run_as_future (self ._api .unlike , repo_id )
3307
+
3308
+ # update repo visibility to public
3309
+ self ._api .run_as_future (self ._api .update_repo_settings , repo_id = repo_id , private = False )
3370
3310
future_2 = self ._api .run_as_future (self ._api .model_info , repo_id = repo_id )
3371
3311
3372
3312
self .assertIsInstance (future_1 , Future )
@@ -3381,8 +3321,8 @@ def test_run_as_future(self, repo_url: RepoUrl) -> None:
3381
3321
assert future_2 .done ()
3382
3322
3383
3323
# Like/unlike is correct
3384
- self .assertEqual (info_1 .likes , 1 )
3385
- self .assertEqual (info_2 .likes , 0 )
3324
+ self .assertEqual (info_1 .private , True )
3325
+ self .assertEqual (info_2 .private , False )
3386
3326
3387
3327
3388
3328
class TestDownloadHfApiAlias (unittest .TestCase ):
0 commit comments