Skip to content

Commit

Permalink
test: add test for url with trailing slash (#7952)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralbertazzi authored May 19, 2023
1 parent 3602b21 commit 277fa60
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 277fa60

Please sign in to comment.