Skip to content

Commit 20c480b

Browse files
committed
Bugzilla: Move login success printing into interactive_login
We already do some printing there, this unifies it. Extend the printing to report when we actually save the token to disk, and where we save it. Signed-off-by: Cole Robinson <[email protected]>
1 parent 52d9255 commit 20c480b

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

bugzilla/_cli.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,11 +1053,6 @@ def _handle_login(opt, action, bz):
10531053
sys.exit(1)
10541054

10551055
if is_login_command:
1056-
msg = "Login successful."
1057-
if (bz.cookiefile or bz.tokenfile) and not use_key:
1058-
msg = "Login successful, token cache updated."
1059-
1060-
print(msg)
10611056
sys.exit(0)
10621057

10631058

bugzilla/base.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,12 @@ def _ask_api_key(self):
629629
log.info('API Key accepted')
630630

631631
wrote_filename = self._rcfile.save_api_key(self.url, self.api_key)
632+
log.info("API key written to filename=%s", wrote_filename)
633+
634+
msg = "Login successful."
632635
if wrote_filename:
633-
log.info("API key written to %s", wrote_filename)
634-
print("API key written to %s" % wrote_filename)
635-
else: # pragma: no cover
636-
log.info("API Key won't be updated because use_creds=False")
636+
msg += " API key written to %s" % wrote_filename
637+
print(msg)
637638

638639
def interactive_login(self, user=None, password=None, force=False,
639640
restrict_login=None, use_api_key=False):
@@ -661,7 +662,11 @@ def interactive_login(self, user=None, password=None, force=False,
661662
password = getpass.getpass('Bugzilla Password: ')
662663

663664
log.info('Logging in... ')
664-
self.login(user, password, restrict_login)
665+
out = self.login(user, password, restrict_login)
666+
msg = "Login successful."
667+
if "token" in out and self.tokenfile:
668+
msg += " Token cache saved to %s" % self.tokenfile
669+
print(msg)
665670

666671
def logout(self):
667672
"""

tests/test_cli_login.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ def test_login(run_cli):
5858

5959
# Returns success for logged_in check and hits a tokenfile line
6060
cmd = "bugzilla --ensure-logged-in "
61-
cmd += "--user FOO --password BAR login"
61+
cmd += "login FOO BAR"
6262
fakebz = tests.mockbackend.make_bz(
6363
bz_kwargs={"use_creds": True},
6464
user_login_args="data/mockargs/test_login.txt",
65-
user_login_return={},
65+
user_login_return={'id': 1234, 'token': 'my-fake-token'},
6666
user_get_args=None,
6767
user_get_return={})
6868
out = run_cli(cmd, fakebz)
69-
assert "token cache updated" in out
69+
assert "Token cache saved" in out
70+
assert fakebz.tokenfile in out

0 commit comments

Comments
 (0)