From 05f4d7955b05548b58cc246c91e705ae0101b743 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sun, 11 Jul 2021 16:02:33 +0200 Subject: [PATCH] Print a message on successful login --- src/spoc_cli.py | 1 + tests/test_cli.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/spoc_cli.py b/src/spoc_cli.py index 5075e80..b3e861d 100644 --- a/src/spoc_cli.py +++ b/src/spoc_cli.py @@ -73,6 +73,7 @@ def login(host): username = input('Username: ') password = getpass.getpass() spoc.login(host, username, password) + print('Login OK') def prune(): spoc.prune() diff --git a/tests/test_cli.py b/tests/test_cli.py index 489e444..830cd63 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -165,12 +165,27 @@ def test_stop_all(stop_all): @patch('builtins.input', return_value='someuser') @patch('getpass.getpass', return_value='somepass') @patch('spoc.login') -def test_login(login, getpass, nput): +def test_login(login, getpass, nput, capsys): spoc_cli.login('somehost') nput.assert_called_once_with('Username: ') getpass.assert_called_once() login.assert_called_once_with('somehost', 'someuser', 'somepass') + captured = capsys.readouterr() + assert captured.out == 'Login OK\n' + +@patch('builtins.input', return_value='someuser') +@patch('getpass.getpass', return_value='somepass') +@patch('spoc.login', side_effect=requests.ConnectTimeout()) +def test_login_bad(login, getpass, nput, capsys): + with pytest.raises(requests.ConnectTimeout): + spoc_cli.login('somehost') + + nput.assert_called_once_with('Username: ') + getpass.assert_called_once() + login.assert_called_once_with('somehost', 'someuser', 'somepass') + captured = capsys.readouterr() + assert captured.out == '' @patch('spoc.prune') def test_prune(prune):