Skip to content

Commit 22fc599

Browse files
committed
tests: Do interactive login tests through the cli
Signed-off-by: Cole Robinson <crobinso@redhat.com>
1 parent 20c480b commit 22fc599

2 files changed

Lines changed: 34 additions & 35 deletions

File tree

tests/test_api_misc.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
Test miscellaneous API bits
1010
"""
1111

12-
import sys
13-
import tempfile
14-
1512
import pytest
1613

1714
import bugzilla
@@ -202,43 +199,13 @@ def test_api_login():
202199
bz = tests.mockbackend.make_bz(
203200
bz_kwargs={"user": "FOO", "password": "BAR"},
204201
user_login_args="data/mockargs/test_api_login2.txt",
205-
user_login_return={})
206-
207-
208-
def test_interactive_login(capsys, monkeypatch):
209-
bz = tests.mockbackend.make_bz(
210-
user_login_args="data/mockargs/test_interactive_login.txt",
211202
user_login_return={},
212203
user_logout_args=None,
213-
user_logout_return={},
214-
user_get_args=None,
215-
user_get_return={})
216-
217-
tests.utils.monkeypatch_getpass(monkeypatch)
204+
user_logout_return={})
218205

219-
fakestdin = tests.utils.fake_stream("fakeuser\nfakepass\n")
220-
monkeypatch.setattr(sys, "stdin", fakestdin)
221-
bz.interactive_login()
206+
# Test logout
222207
bz.logout()
223208

224-
out = capsys.readouterr()[0]
225-
assert "Bugzilla Username:" in out
226-
assert "Bugzilla Password:" in out
227-
228-
# API key prompting and saving
229-
tmp = tempfile.NamedTemporaryFile()
230-
bz.configpath = [tmp.name]
231-
bz.url = "https://example.com"
232-
233-
fakestdin = tests.utils.fake_stream("MY-FAKE-KEY\n")
234-
monkeypatch.setattr(sys, "stdin", fakestdin)
235-
bz.interactive_login(use_api_key=True)
236-
out = capsys.readouterr()[0]
237-
assert "API Key:" in out
238-
assert tmp.name in out
239-
tests.utils.diff_compare(open(tmp.name).read(),
240-
"data/clioutput/test_interactive_login_apikey_rcfile.txt")
241-
242209

243210
def test_version_bad():
244211
# Hit version error handling

tests/test_cli_login.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# This work is licensed under the GNU GPLv2 or later.
22
# See the COPYING file in the top-level directory.
33

4+
import tempfile
5+
46
import pytest
57

68
import bugzilla
@@ -68,3 +70,33 @@ def test_login(run_cli):
6870
out = run_cli(cmd, fakebz)
6971
assert "Token cache saved" in out
7072
assert fakebz.tokenfile in out
73+
74+
75+
def test_interactive_login(monkeypatch, run_cli):
76+
bz = tests.mockbackend.make_bz(
77+
user_login_args="data/mockargs/test_interactive_login.txt",
78+
user_login_return={},
79+
user_logout_args=None,
80+
user_logout_return={},
81+
user_get_args=None,
82+
user_get_return={})
83+
84+
tests.utils.monkeypatch_getpass(monkeypatch)
85+
cmd = "bugzilla login"
86+
fakestdin = "fakeuser\nfakepass\n"
87+
out = run_cli(cmd, bz, stdin=fakestdin)
88+
assert "Bugzilla Username:" in out
89+
assert "Bugzilla Password:" in out
90+
91+
# API key prompting and saving
92+
tmp = tempfile.NamedTemporaryFile()
93+
bz.configpath = [tmp.name]
94+
bz.url = "https://example.com"
95+
96+
cmd = "bugzilla login --api-key"
97+
fakestdin = "MY-FAKE-KEY\n"
98+
out = run_cli(cmd, bz, stdin=fakestdin)
99+
assert "API Key:" in out
100+
assert tmp.name in out
101+
tests.utils.diff_compare(open(tmp.name).read(),
102+
"data/clioutput/test_interactive_login_apikey_rcfile.txt")

0 commit comments

Comments
 (0)