diff --git a/tests/test_register.py b/tests/test_register.py index bd925bd5..791be27f 100644 --- a/tests/test_register.py +++ b/tests/test_register.py @@ -79,7 +79,8 @@ def test_non_existent_package(register_settings): register.register(register_settings, package) -def test_values_from_env(monkeypatch): +@pytest.mark.parametrize("repo", ["pypi", "testpypi"]) +def test_values_from_env_pypi(monkeypatch, repo): """Use env vars for settings when run from command line.""" def none_register(*args, **settings_kwargs): @@ -88,6 +89,8 @@ def none_register(*args, **settings_kwargs): replaced_register = pretend.call_recorder(none_register) monkeypatch.setattr(register, "register", replaced_register) testenv = { + "TWINE_REPOSITORY": repo, + # Ignored because the TWINE_REPOSITORY is PyPI/TestPyPI "TWINE_USERNAME": "this-is-ignored", "TWINE_PASSWORD": "pypipassword", "TWINE_CERT": "/foo/bar.crt", @@ -98,3 +101,38 @@ def none_register(*args, **settings_kwargs): assert "pypipassword" == register_settings.password assert "__token__" == register_settings.username assert "/foo/bar.crt" == register_settings.cacert + + +def test_values_from_env_not_pypi(monkeypatch, write_config_file): + """Use env vars for settings when run from command line.""" + + write_config_file( + """ + [distutils] + index-servers = + notpypi + + [notpypi] + repository: https://upload.example.org/legacy/ + username:someusername + password:password + """ + ) + + def none_register(*args, **settings_kwargs): + pass + + replaced_register = pretend.call_recorder(none_register) + monkeypatch.setattr(register, "register", replaced_register) + testenv = { + "TWINE_REPOSITORY": "notpypi", + "TWINE_USERNAME": "someusername", + "TWINE_PASSWORD": "pypipassword", + "TWINE_CERT": "/foo/bar.crt", + } + with helpers.set_env(**testenv): + cli.dispatch(["register", helpers.WHEEL_FIXTURE]) + register_settings = replaced_register.calls[0].args[0] + assert "pypipassword" == register_settings.password + assert "someusername" == register_settings.username + assert "/foo/bar.crt" == register_settings.cacert diff --git a/tests/test_settings.py b/tests/test_settings.py index fc64474b..52eb92e9 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -27,8 +27,11 @@ def test_settings_takes_no_positional_arguments(): settings.Settings("a", "b", "c") -def test_settings_transforms_repository_config(write_config_file): - """Set repository config and defaults when .pypirc is provided.""" +def test_settings_transforms_repository_config_pypi(write_config_file): + """Set repository config and defaults when .pypirc is provided. + + Ignores the username setting due to PyPI being the index. + """ config_file = write_config_file( """ [pypi] @@ -50,6 +53,33 @@ def test_settings_transforms_repository_config(write_config_file): assert s.disable_progress_bar is False +def test_settings_transforms_repository_config_non_pypi(write_config_file): + """Set repository config and defaults when .pypirc is provided.""" + config_file = write_config_file( + """ + [distutils] + index-servers = + notpypi + + [notpypi] + repository: https://upload.example.org/legacy/ + username:someusername + password:password + """ + ) + + s = settings.Settings(config_file=config_file, repository_name="notpypi") + assert s.repository_config["repository"] == "https://upload.example.org/legacy/" + assert s.sign is False + assert s.sign_with == "gpg" + assert s.identity is None + assert s.username == "someusername" + assert s.password == "password" + assert s.cacert is None + assert s.client_cert is None + assert s.disable_progress_bar is False + + @pytest.mark.parametrize( "verbose, log_level", [(True, logging.INFO), (False, logging.WARNING)] )