1+ import logging
2+
13import pytest
24
35from twine import auth
46from twine import exceptions
57from twine import utils
68
7- cred = auth .CredentialInput
8-
99
1010@pytest .fixture
1111def config () -> utils .RepositoryConfig :
@@ -20,7 +20,7 @@ def get_password(system, user):
2020
2121 monkeypatch .setattr (auth , "keyring" , MockKeyring )
2222
23- pw = auth .Resolver (config , cred ("user" )).password
23+ pw = auth .Resolver (config , auth . CredentialInput ("user" )).password
2424 assert pw == "user@system sekure pa55word"
2525
2626
@@ -32,37 +32,41 @@ def get_password(system, user):
3232
3333 monkeypatch .setattr (auth , "keyring" , MockKeyring )
3434
35- pw = auth .Resolver (config , cred ("user" )).password
35+ pw = auth .Resolver (config , auth . CredentialInput ("user" )).password
3636 assert pw == "entered pw"
3737
3838
3939def test_no_password_defers_to_prompt (monkeypatch , entered_password , config ):
4040 config .update (password = None )
41- pw = auth .Resolver (config , cred ("user" )).password
41+ pw = auth .Resolver (config , auth . CredentialInput ("user" )).password
4242 assert pw == "entered pw"
4343
4444
4545def test_empty_password_bypasses_prompt (monkeypatch , entered_password , config ):
4646 config .update (password = "" )
47- pw = auth .Resolver (config , cred ("user" )).password
47+ pw = auth .Resolver (config , auth . CredentialInput ("user" )).password
4848 assert pw == ""
4949
5050
5151def test_no_username_non_interactive_aborts (config ):
5252 with pytest .raises (exceptions .NonInteractive ):
53- auth .Private (config , cred ("user" )).password
53+ auth .Private (config , auth . CredentialInput ("user" )).password
5454
5555
5656def test_no_password_non_interactive_aborts (config ):
5757 with pytest .raises (exceptions .NonInteractive ):
58- auth .Private (config , cred ("user" )).password
58+ auth .Private (config , auth . CredentialInput ("user" )).password
5959
6060
61- def test_get_username_and_password_keyring_overrides_prompt (monkeypatch , config ):
61+ def test_get_username_and_password_keyring_overrides_prompt (
62+ monkeypatch , config , caplog
63+ ):
64+ caplog .set_level (logging .INFO , "twine" )
65+
6266 class MockKeyring :
6367 @staticmethod
6468 def get_credential (system , user ):
65- return cred (
69+ return auth . CredentialInput (
6670 "real_user" , "real_user@{system} sekure pa55word" .format (** locals ())
6771 )
6872
@@ -75,10 +79,16 @@ def get_password(system, user):
7579
7680 monkeypatch .setattr (auth , "keyring" , MockKeyring )
7781
78- res = auth .Resolver (config , cred ())
82+ res = auth .Resolver (config , auth .CredentialInput ())
83+
7984 assert res .username == "real_user"
8085 assert res .password == "real_user@system sekure pa55word"
8186
87+ assert caplog .messages == [
88+ "username set from keyring" ,
89+ "password set from keyring" ,
90+ ]
91+
8292
8393@pytest .fixture
8494def keyring_missing_get_credentials (monkeypatch ):
@@ -94,21 +104,21 @@ def entered_username(monkeypatch):
94104def test_get_username_keyring_missing_get_credentials_prompts (
95105 entered_username , keyring_missing_get_credentials , config
96106):
97- assert auth .Resolver (config , cred ()).username == "entered user"
107+ assert auth .Resolver (config , auth . CredentialInput ()).username == "entered user"
98108
99109
100110def test_get_username_keyring_missing_non_interactive_aborts (
101111 entered_username , keyring_missing_get_credentials , config
102112):
103113 with pytest .raises (exceptions .NonInteractive ):
104- auth .Private (config , cred ()).username
114+ auth .Private (config , auth . CredentialInput ()).username
105115
106116
107117def test_get_password_keyring_missing_non_interactive_aborts (
108118 entered_username , keyring_missing_get_credentials , config
109119):
110120 with pytest .raises (exceptions .NonInteractive ):
111- auth .Private (config , cred ("user" )).password
121+ auth .Private (config , auth . CredentialInput ("user" )).password
112122
113123
114124@pytest .fixture
@@ -138,7 +148,7 @@ def get_credential(system, username):
138148def test_get_username_runtime_error_suppressed (
139149 entered_username , keyring_no_backends_get_credential , recwarn , config
140150):
141- assert auth .Resolver (config , cred ()).username == "entered user"
151+ assert auth .Resolver (config , auth . CredentialInput ()).username == "entered user"
142152 assert len (recwarn ) == 1
143153 warning = recwarn .pop (UserWarning )
144154 assert "fail!" in str (warning )
@@ -147,7 +157,7 @@ def test_get_username_runtime_error_suppressed(
147157def test_get_password_runtime_error_suppressed (
148158 entered_password , keyring_no_backends , recwarn , config
149159):
150- assert auth .Resolver (config , cred ("user" )).password == "entered pw"
160+ assert auth .Resolver (config , auth . CredentialInput ("user" )).password == "entered pw"
151161 assert len (recwarn ) == 1
152162 warning = recwarn .pop (UserWarning )
153163 assert "fail!" in str (warning )
@@ -162,4 +172,33 @@ def get_credential(system, username):
162172 return None
163173
164174 monkeypatch .setattr (auth , "keyring" , FailKeyring ())
165- assert auth .Resolver (config , cred ()).username == "entered user"
175+ assert auth .Resolver (config , auth .CredentialInput ()).username == "entered user"
176+
177+
178+ def test_logs_cli_values (caplog ):
179+ caplog .set_level (logging .INFO , "twine" )
180+
181+ res = auth .Resolver (config , auth .CredentialInput ("username" , "password" ))
182+
183+ assert res .username == "username"
184+ assert res .password == "password"
185+
186+ assert caplog .messages == [
187+ "username set by command options" ,
188+ "password set by command options" ,
189+ ]
190+
191+
192+ def test_logs_config_values (config , caplog ):
193+ caplog .set_level (logging .INFO , "twine" )
194+
195+ config .update (username = "username" , password = "password" )
196+ res = auth .Resolver (config , auth .CredentialInput ())
197+
198+ assert res .username == "username"
199+ assert res .password == "password"
200+
201+ assert caplog .messages == [
202+ "username set from config file" ,
203+ "password set from config file" ,
204+ ]
0 commit comments