Skip to content

Commit

Permalink
Fix: HTTP Upload status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
lineman60 authored and lineman60 committed Dec 9, 2022
1 parent 0ca8b7e commit 994a6a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ def _upload_file(
headers={"Content-Type": monitor.content_type},
timeout=REQUESTS_TIMEOUT,
)
if resp is None or 200 <= resp.status_code < 300:
if resp is None or 200 <= resp.status_code < 299:
bar.set_format(
f" - Uploading <c1>{file.name}</c1> <fg=green>%percent%%</>"
)
bar.finish()
elif resp.status_code == 301:
elif 300 <= resp.status_code < 399:
if self._io.output.is_decorated():
self._io.overwrite(
f" - Uploading <c1>{file.name}</c1> <error>FAILED</>"
Expand All @@ -275,7 +275,7 @@ def _upload_file(
"Redirects are not supported. "
"Is the URL missing a trailing slash?"
)
elif resp.status_code == 400 and "was ever registered" in resp.text:
elif 400 <= resp.status_code < 499 and "was ever registered" in resp.text:
self._register(session, url)
resp.raise_for_status()
elif skip_existing and self._is_file_exists_error(resp):
Expand Down
21 changes: 21 additions & 0 deletions tests/publishing/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ def test_uploader_properly_handles_nonstandard_errors(
assert str(e.value) == f"HTTP Error 400: Bad Request | {content}"


@pytest.mark.parametrize(
"status, body",
[
(308, "Permanent Redirect"),
(307, "Temporary Redirect"),
(304, "Not Modified"),
(303, "See Other"),
(302, "Found"),
(301, "Moved Permanently"),
(300, "Multiple Choices"),
],
)
def test_uploader_properly_handles_redirects(
http: type[httpretty.httpretty], uploader: Uploader, status: int, body: str
):
http.register_uri(http.POST, "https://foo.com", status=status, body=body)

with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")


def test_uploader_properly_handles_301_redirects(
http: type[httpretty.httpretty], uploader: Uploader
):
Expand Down

0 comments on commit 994a6a8

Please sign in to comment.