Skip to content

Commit

Permalink
uploader: fix HTTP status code handling for redirects (#7160)
Browse files Browse the repository at this point in the history
  • Loading branch information
lineman60 authored Jan 15, 2023
1 parent df9d3c9 commit a5c3846
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def _upload_file(
f" - Uploading <c1>{file.name}</c1> <fg=green>%percent%%</>"
)
bar.finish()
elif resp.status_code == 301:
elif 300 <= resp.status_code < 400:
if self._io.output.is_decorated():
self._io.overwrite(
f" - Uploading <c1>{file.name}</c1> <error>FAILED</>"
Expand Down
26 changes: 26 additions & 0 deletions tests/publishing/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ 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")

assert (
str(e.value)
== "Redirects are not supported. Is the URL missing a trailing slash?"
)


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

0 comments on commit a5c3846

Please sign in to comment.