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
Pradyumna Rahul authored and 1nF0rmed committed Nov 15, 2021
1 parent d3bc0eb commit 76a18de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ def _upload(
self, session: requests.Session, url: str, dry_run: Optional[bool] = False
) -> None:
for file in self.files:
# TODO: Check existence
if not file.is_file():
raise UploadError(
"Wheel or Tar files associated with the Project Package do not exist"
)

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

Expand Down
11 changes: 11 additions & 0 deletions tests/publishing/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ 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 "Wheel or Tar files associated with the Project Package do not exist" == str(
e.value
)

0 comments on commit 76a18de

Please sign in to comment.