Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds File existence check to Uploader #4417

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)