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

uploader: fix HTTP status code handling for redirects #7160

Merged
merged 7 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
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
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)
lineman60 marked this conversation as resolved.
Show resolved Hide resolved

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