From 3e3eb7193ed0befe39524460ac005e5adf22fb87 Mon Sep 17 00:00:00 2001 From: lineman60 Date: Wed, 7 Dec 2022 21:45:01 -0600 Subject: [PATCH 1/3] Fix: HTTP Upload status codes --- src/poetry/publishing/uploader.py | 2 +- tests/publishing/test_uploader.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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..7878ac52368 100644 --- a/tests/publishing/test_uploader.py +++ b/tests/publishing/test_uploader.py @@ -65,6 +65,24 @@ 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) + + def test_uploader_properly_handles_301_redirects( http: type[httpretty.httpretty], uploader: Uploader ): From 79fd3fd712fdc6f7b2c851c649cd680efa42e853 Mon Sep 17 00:00:00 2001 From: Beryl S Date: Wed, 11 Jan 2023 23:51:13 -0600 Subject: [PATCH 2/3] fix(test) --- tests/publishing/test_uploader.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/publishing/test_uploader.py b/tests/publishing/test_uploader.py index 7878ac52368..cb1f0fe24f4 100644 --- a/tests/publishing/test_uploader.py +++ b/tests/publishing/test_uploader.py @@ -81,6 +81,14 @@ 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( From 409d57d45bb467ddcb98ceb41544c7ffa2b617bb Mon Sep 17 00:00:00 2001 From: Beryl S Date: Thu, 12 Jan 2023 00:35:46 -0600 Subject: [PATCH 3/3] fix white space --- tests/publishing/test_uploader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/publishing/test_uploader.py b/tests/publishing/test_uploader.py index cb1f0fe24f4..f0721d8f12d 100644 --- a/tests/publishing/test_uploader.py +++ b/tests/publishing/test_uploader.py @@ -81,7 +81,7 @@ 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")