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.

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
  • Loading branch information
1nF0rmed and neersighted committed Sep 18, 2022
1 parent a06381c commit cd8457f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/poetry/publishing/uploader.py
Expand Up @@ -212,8 +212,6 @@ def _upload(
skip_existing: bool = False,
) -> None:
for file in self.files:
# TODO: Check existence

self._upload_file(session, url, file, dry_run, skip_existing)

def _upload_file(
Expand All @@ -226,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
11 changes: 11 additions & 0 deletions tests/publishing/test_uploader.py
Expand Up @@ -119,3 +119,14 @@ def test_uploader_skip_existing_bubbles_unskippable_errors(

with pytest.raises(UploadError):
uploader.upload("https://foo.com", skip_existing=True)


def test_uploader_properly_handles_file_not_existing(
mocker: MockerFixture, http: type[httpretty.httpretty], uploader: 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 cd8457f

Please sign in to comment.