From 6e94d200e20f700fa2e905dd32afeb367d321b67 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Thu, 4 Jan 2024 21:26:58 -0500 Subject: [PATCH] tests: more non-PyPI tests --- tests/test_upload.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/test_upload.py b/tests/test_upload.py index 9c36c06e..c59bb4df 100644 --- a/tests/test_upload.py +++ b/tests/test_upload.py @@ -544,13 +544,16 @@ def test_skip_upload_respects_skip_existing(): ) -def test_values_from_env(monkeypatch): +@pytest.mark.parametrize("repo", ["pypi", "testpypi"]) +def test_values_from_env_pypi(monkeypatch, repo): def none_upload(*args, **settings_kwargs): pass replaced_upload = pretend.call_recorder(none_upload) monkeypatch.setattr(upload, "upload", replaced_upload) testenv = { + "TWINE_REPOSITORY": repo, + # Ignored because TWINE_REPOSITORY is PyPI/TestPyPI "TWINE_USERNAME": "this-is-ignored", "TWINE_PASSWORD": "pypipassword", "TWINE_CERT": "/foo/bar.crt", @@ -563,6 +566,39 @@ def none_upload(*args, **settings_kwargs): assert "/foo/bar.crt" == upload_settings.cacert +def test_values_from_env_non_pypi(monkeypatch, write_config_file): + write_config_file( + """ + [distutils] + index-servers = + notpypi + + [notpypi] + repository: https://upload.example.org/legacy/ + username:someusername + password:password + """ + ) + + def none_upload(*args, **settings_kwargs): + pass + + replaced_upload = pretend.call_recorder(none_upload) + monkeypatch.setattr(upload, "upload", replaced_upload) + testenv = { + "TWINE_REPOSITORY": "notpypi", + "TWINE_USERNAME": "someusername", + "TWINE_PASSWORD": "pypipassword", + "TWINE_CERT": "/foo/bar.crt", + } + with helpers.set_env(**testenv): + cli.dispatch(["upload", "path/to/file"]) + upload_settings = replaced_upload.calls[0].args[0] + assert "pypipassword" == upload_settings.password + assert "someusername" == upload_settings.username + assert "/foo/bar.crt" == upload_settings.cacert + + @pytest.mark.parametrize( "repo_url", ["https://upload.pypi.org/", "https://test.pypi.org/", "https://pypi.org/"],