Skip to content

Commit

Permalink
tests: begin adding non-PyPI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
woodruffw committed Jan 5, 2024
1 parent 9ce7892 commit e912312
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
40 changes: 39 additions & 1 deletion tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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",
Expand All @@ -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
34 changes: 32 additions & 2 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)]
)
Expand Down

0 comments on commit e912312

Please sign in to comment.