Skip to content

Commit

Permalink
Adds File existence check to Uploader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
1nF0rmed committed Nov 15, 2021
1 parent d3bc0eb commit 1fd7832
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/poetry/publishing/uploader.py
Expand Up @@ -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)

Expand All @@ -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(
{
Expand Down
9 changes: 9 additions & 0 deletions tests/publishing/test_uploader.py
Expand Up @@ -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)

0 comments on commit 1fd7832

Please sign in to comment.