Skip to content

Commit 4df26db

Browse files
authored
Add model info test for private models (#345)
* Add model info test for private models * Refactor
1 parent 10e7445 commit 4df26db

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/test_hf_api.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import unittest
2222
from io import BytesIO
2323

24+
import requests
2425
from huggingface_hub.constants import REPO_TYPE_DATASET, REPO_TYPE_SPACE
2526
from huggingface_hub.file_download import cached_download
2627
from huggingface_hub.hf_api import (
@@ -434,6 +435,25 @@ def test_dataset_info(self):
434435
self.assertEqual(dataset.sha, DUMMY_DATASET_ID_REVISION_ONE_SPECIFIC_COMMIT)
435436

436437

438+
class HfApiPrivateTest(HfApiCommonTestWithLogin):
439+
def setUp(self) -> None:
440+
super().setUp()
441+
self._api.create_repo(token=self._token, name=REPO_NAME, private=True)
442+
443+
def tearDown(self) -> None:
444+
self._api.delete_repo(token=self._token, name=REPO_NAME)
445+
446+
def test_model_info(self):
447+
# Test we cannot access model info without a token
448+
with self.assertRaisesRegex(requests.exceptions.HTTPError, "404 Client Error"):
449+
_ = self._api.model_info(repo_id=f"{USER}/{REPO_NAME}")
450+
# Test we can access model info with a token
451+
model_info = self._api.model_info(
452+
repo_id=f"{USER}/{REPO_NAME}", token=self._token
453+
)
454+
self.assertIsInstance(model_info, ModelInfo)
455+
456+
437457
class HfFolderTest(unittest.TestCase):
438458
def test_token_workflow(self):
439459
"""

0 commit comments

Comments
 (0)