コード例 #1
0
ファイル: test_auth.py プロジェクト: sunjianzhou/twine
def test_get_password_keyring_defers_to_prompt(monkeypatch, entered_password,
                                               config):
    class MockKeyring:
        @staticmethod
        def get_password(system, user):
            return

    monkeypatch.setattr(auth, "keyring", MockKeyring)

    pw = auth.Resolver(config, cred("user")).password
    assert pw == "entered pw"
コード例 #2
0
ファイル: test_auth.py プロジェクト: hugovk/twine
def test_logs_cli_values(caplog):
    caplog.set_level(logging.INFO, "twine")

    res = auth.Resolver(config, auth.CredentialInput("username", "password"))

    assert res.username == "username"
    assert res.password == "password"

    assert caplog.messages == [
        "username set by command options",
        "password set by command options",
    ]
コード例 #3
0
ファイル: test_auth.py プロジェクト: hugovk/twine
def test_logs_config_values(config, caplog):
    caplog.set_level(logging.INFO, "twine")

    config.update(username="******", password="******")
    res = auth.Resolver(config, auth.CredentialInput())

    assert res.username == "username"
    assert res.password == "password"

    assert caplog.messages == [
        "username set from config file",
        "password set from config file",
    ]
コード例 #4
0
ファイル: test_auth.py プロジェクト: adityasaky/pypa-twine
def test_get_username_and_password_keyring_overrides_prompt(monkeypatch, config):
    class MockKeyring:
        @staticmethod
        def get_credential(system, user):
            return cred(
                "real_user", "real_user@{system} sekure pa55word".format(**locals())
            )

        @staticmethod
        def get_password(system, user):
            cred = MockKeyring.get_credential(system, user)
            if user != cred.username:
                raise RuntimeError("unexpected username")
            return cred.password

    monkeypatch.setattr(auth, "keyring", MockKeyring)

    res = auth.Resolver(config, cred())
    assert res.username == "real_user"
    assert res.password == "real_user@system sekure pa55word"
コード例 #5
0
ファイル: test_auth.py プロジェクト: rkm/twine
def test_empty_password_bypasses_prompt(monkeypatch, entered_password, config):
    config.update(password="")
    pw = auth.Resolver(config, cred("user")).password
    assert pw == ""
コード例 #6
0
ファイル: test_auth.py プロジェクト: rkm/twine
def test_no_password_defers_to_prompt(monkeypatch, entered_password, config):
    config.update(password=None)
    pw = auth.Resolver(config, cred("user")).password
    assert pw == "entered pw"
コード例 #7
0
ファイル: test_auth.py プロジェクト: rkm/twine
def test_get_username_runtime_error_suppressed(
        entered_username, keyring_no_backends_get_credential, recwarn, config):
    assert auth.Resolver(config, cred()).username == "entered user"
    assert len(recwarn) == 1
    warning = recwarn.pop(UserWarning)
    assert "fail!" in str(warning)
コード例 #8
0
ファイル: test_auth.py プロジェクト: rkm/twine
def test_get_username_keyring_missing_get_credentials_prompts(
        entered_username, keyring_missing_get_credentials, config):
    assert auth.Resolver(config, cred()).username == "entered user"