Skip to content

Commit

Permalink
Fix upload exit code (#405)
Browse files Browse the repository at this point in the history
* Fix a bad test

The assertion on the exception message was never being run

* Add failing test for upload

In the event that the upload is successful, the return should be
something falsey (such as the implicit None) as this value will
eventually be used to determine the exit code.

* Remove accidental return statement from upload cmd

This was added accidentally in #395 and was missed on review.

* Update changelog
  • Loading branch information
di authored and theacodes committed Sep 24, 2018
1 parent 48adf29 commit c67ace5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Changelog
=========

* :bug:`404` Fix regression with upload exit code
* :release:`1.12.0 <2018-09-24>`
* :feature:`395 major` Add ``twine check`` command to check long description
* :feature:`392 major` Drop support for Python 3.3
Expand Down
58 changes: 46 additions & 12 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,40 @@
WHEEL_FIXTURE = 'tests/fixtures/twine-1.5.0-py2.py3-none-any.whl'


def test_successful_upload(tmpdir):
pypirc = os.path.join(str(tmpdir), ".pypirc")
dists = ["tests/fixtures/twine-1.5.0-py2.py3-none-any.whl"]

with open(pypirc, "w") as fp:
fp.write(textwrap.dedent("""
[pypi]
username:foo
password:bar
"""))

upload_settings = settings.Settings(
repository_name="pypi", sign=None, identity=None, username=None,
password=None, comment=None, cert=None, client_cert=None,
sign_with=None, config_file=pypirc, skip_existing=False,
repository_url=None, verbose=False,
)

stub_response = pretend.stub(
is_redirect=False, status_code=201, raise_for_status=lambda: None
)
stub_repository = pretend.stub(
upload=lambda package: stub_response, close=lambda: None
)

upload_settings.create_repository = lambda: stub_repository

result = upload.upload(upload_settings, dists)

# Raising an exception or returning anything truthy would mean that the
# upload has failed
assert result is None


def test_get_config_old_format(tmpdir):
pypirc = os.path.join(str(tmpdir), ".pypirc")

Expand Down Expand Up @@ -77,18 +111,18 @@ def test_deprecated_repo(tmpdir):

upload.upload(upload_settings, dists)

assert err.args[0] == (
"You're trying to upload to the legacy PyPI site "
"'https://pypi.python.org/pypi/'. "
"Uploading to those sites is deprecated. \n "
"The new sites are pypi.org and test.pypi.org. Try using "
"https://upload.pypi.org/legacy/ "
"(or https://test.pypi.org/legacy/) "
"to upload your packages instead. "
"These are the default URLs for Twine now. \n "
"More at "
"https://packaging.python.org/guides/migrating-to-pypi-org/ ."
)
assert err.value.args[0] == (
"You're trying to upload to the legacy PyPI site "
"'https://pypi.python.org/pypi/'. "
"Uploading to those sites is deprecated. \n "
"The new sites are pypi.org and test.pypi.org. Try using "
"https://upload.pypi.org/legacy/ "
"(or https://test.pypi.org/legacy/) "
"to upload your packages instead. "
"These are the default URLs for Twine now. \n "
"More at "
"https://packaging.python.org/guides/migrating-to-pypi-org/ ."
)


def test_skip_existing_skips_files_already_on_PyPI(monkeypatch):
Expand Down
2 changes: 0 additions & 2 deletions twine/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ def upload(upload_settings, dists):
# pool.
repository.close()

return True


def main(args):
parser = argparse.ArgumentParser(prog="twine upload")
Expand Down

0 comments on commit c67ace5

Please sign in to comment.