Commit 277fa607 by Riccardo Albertazzi Committed by GitHub

test: add test for url with trailing slash (#7952)

parent 3602b217
......@@ -3,7 +3,6 @@ from __future__ import annotations
import base64
import re
import shutil
import urllib.parse as urlparse
from pathlib import Path
from typing import TYPE_CHECKING
......@@ -14,6 +13,7 @@ import requests
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
......@@ -51,7 +51,7 @@ class MockRepository(LegacyRepository):
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)
......@@ -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]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment