Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LFS tests after password auth deprecation #1713

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, Union
from unittest.mock import Mock, patch
from urllib.parse import quote
from urllib.parse import quote, urlparse

import pytest
import requests
Expand Down Expand Up @@ -81,7 +81,6 @@

from .testing_constants import (
ENDPOINT_STAGING,
ENDPOINT_STAGING_BASIC_AUTH,
FULL_NAME,
OTHER_TOKEN,
OTHER_USER,
Expand Down Expand Up @@ -2132,9 +2131,11 @@ def tearDown(self):
self._api.delete_repo(repo_id=self.repo_id)

def setup_local_clone(self) -> None:
REMOTE_URL_AUTH = self.repo_url.replace(ENDPOINT_STAGING, ENDPOINT_STAGING_BASIC_AUTH)
scheme = urlparse(self.repo_url).scheme
repo_url_auth = self.repo_url.replace(f"{scheme}://", f"{scheme}://user:{TOKEN}@")

subprocess.run(
["git", "clone", REMOTE_URL_AUTH, str(self.cache_dir)],
["git", "clone", repo_url_auth, str(self.cache_dir)],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
29 changes: 12 additions & 17 deletions tests/test_repocard.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from pathlib import Path

import pytest
import requests
import yaml

from huggingface_hub import (
Expand All @@ -30,6 +29,8 @@
RepoCard,
SpaceCard,
SpaceCardData,
get_hf_file_metadata,
hf_hub_url,
metadata_eval_result,
metadata_load,
metadata_save,
Expand All @@ -40,11 +41,10 @@
from huggingface_hub.hf_api import HfApi
from huggingface_hub.repocard import REGEX_YAML_BLOCK
from huggingface_hub.repocard_data import CardData
from huggingface_hub.utils import SoftTemporaryDirectory, is_jinja_available, logging
from huggingface_hub.utils import EntryNotFoundError, SoftTemporaryDirectory, is_jinja_available, logging

from .testing_constants import (
ENDPOINT_STAGING,
ENDPOINT_STAGING_BASIC_AUTH,
TOKEN,
USER,
)
Expand Down Expand Up @@ -653,19 +653,16 @@ def test_push_to_hub(self):
content = f"---\n{card_data.to_yaml()}\n---\n\n# MyModel\n\nHello, world!"
card = RepoCard(content)

url = f"{ENDPOINT_STAGING_BASIC_AUTH}/{repo_id}/resolve/main/README.md"

# Check this file doesn't exist (sanity check)
with pytest.raises(requests.exceptions.HTTPError):
r = requests.get(url)
r.raise_for_status()
readme_url = hf_hub_url(repo_id, "README.md")
with self.assertRaises(EntryNotFoundError):
get_hf_file_metadata(readme_url)

# Push the card up to README.md in the repo
card.push_to_hub(repo_id, token=TOKEN)

# No error should occur now, as README.md should exist
r = requests.get(url)
r.raise_for_status()
get_hf_file_metadata(readme_url)

self._api.delete_repo(repo_id=repo_id)

Expand All @@ -684,14 +681,12 @@ def test_push_and_create_pr(self):
content = f"---\n{card_data.to_yaml()}\n---\n\n# MyModel\n\nHello, world!"
card = RepoCard(content)

url = f"{ENDPOINT_STAGING_BASIC_AUTH}/api/models/{repo_id}/discussions"
r = requests.get(url)
data = r.json()
self.assertEqual(data["count"], 0)
discussions = list(self._api.get_repo_discussions(repo_id))
self.assertEqual(len(discussions), 0)

card.push_to_hub(repo_id, token=TOKEN, create_pr=True)
r = requests.get(url)
data = r.json()
self.assertEqual(data["count"], 1)
discussions = list(self._api.get_repo_discussions(repo_id))
self.assertEqual(len(discussions), 1)

self._api.delete_repo(repo_id=repo_id)

Expand Down
1 change: 0 additions & 1 deletion tests/testing_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

ENDPOINT_PRODUCTION = "https://huggingface.co"
ENDPOINT_STAGING = "https://hub-ci.huggingface.co"
ENDPOINT_STAGING_BASIC_AUTH = f"https://{USER}:{PASS}@hub-ci.huggingface.co"

ENDPOINT_PRODUCTION_URL_SCHEME = ENDPOINT_PRODUCTION + "/{repo_id}/resolve/{revision}/{filename}"

Expand Down