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

test: add test for url with trailing slash #7952

Merged
merged 2 commits into from
May 19, 2023
Merged
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
12 changes: 10 additions & 2 deletions tests/repositories/test_legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import base64
import re
import shutil
import urllib.parse as urlparse

from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -14,6 +13,7 @@
from packaging.utils import canonicalize_name
from poetry.core.constraints.version import Version
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.utils.link import Link

from poetry.factory import Factory
from poetry.repositories.exceptions import PackageNotFound
Expand Down Expand Up @@ -51,7 +51,7 @@ def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage:
return SimpleRepositoryPage(self._url + f"/{name}/", f.read())

def _download(self, url: str, dest: Path) -> None:
filename = urlparse.urlparse(url).path.rsplit("/")[-1]
filename = Link(url).filename
filepath = self.FIXTURES.parent / "pypi.org" / "dists" / filename

shutil.copyfile(str(filepath), dest)
Expand Down Expand Up @@ -462,6 +462,14 @@ def test_find_links_for_package_yanked(
assert link.yanked_reason == yanked_reason


def test_cached_or_downloaded_file_supports_trailing_slash() -> None:
repo = MockRepository()
with repo._cached_or_downloaded_file(
Link("https://foo.bar/pytest-3.5.0-py2.py3-none-any.whl/")
) as filepath:
assert filepath.name == "pytest-3.5.0-py2.py3-none-any.whl"


class MockHttpRepository(LegacyRepository):
def __init__(
self, endpoint_responses: dict[str, int], http: type[httpretty.httpretty]
Expand Down