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):