From 1fd78320f12684a62f8ac7f5f0f791b66db517d8 Mon Sep 17 00:00:00 2001 From: 1nF0rmed Date: Fri, 20 Aug 2021 23:13:19 +0530 Subject: [PATCH] Adds File existence check to Uploader This handles the TODO for checking the existence of the files being uploaded by the Uploader class. In the case that a file does not exist, it raises an UploadError. --- src/poetry/publishing/uploader.py | 4 +++- tests/publishing/test_uploader.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py index 8de42e9cebb..ffa2adde6cb 100644 --- a/src/poetry/publishing/uploader.py +++ b/src/poetry/publishing/uploader.py @@ -212,7 +212,6 @@ def _upload( self, session: requests.Session, url: str, dry_run: Optional[bool] = False ) -> None: for file in self.files: - # TODO: Check existence self._upload_file(session, url, file, dry_run) @@ -225,6 +224,9 @@ def _upload_file( ) -> None: from cleo.ui.progress_bar import ProgressBar + if not file.is_file(): + raise UploadError(f"Archive ({file}) does not exist") + data = self.post_data(file) data.update( { diff --git a/tests/publishing/test_uploader.py b/tests/publishing/test_uploader.py index e4deb372884..f129be230cb 100644 --- a/tests/publishing/test_uploader.py +++ b/tests/publishing/test_uploader.py @@ -60,3 +60,12 @@ def test_uploader_registers_for_appropriate_400_errors(mocker, http, uploader): uploader.upload("https://foo.com") assert 1 == register.call_count + + +def test_uploader_properly_handles_file_not_existing(mocker, http, uploader): + mocker.patch("pathlib.Path.is_file", return_value=False) + + with pytest.raises(UploadError) as e: + uploader.upload("https://foo.com") + + assert f"Archive ({uploader.files[0]}) does not exist" == str(e.value)