diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py index 7b1e8e19048..1f3a6bd81b9 100644 --- a/src/poetry/publishing/uploader.py +++ b/src/poetry/publishing/uploader.py @@ -266,7 +266,7 @@ def _upload_file( f" - Uploading {file.name} %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 {file.name} FAILED" diff --git a/tests/publishing/test_uploader.py b/tests/publishing/test_uploader.py index be6256052a8..f0721d8f12d 100644 --- a/tests/publishing/test_uploader.py +++ b/tests/publishing/test_uploader.py @@ -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 ):