Skip to content

Commit e5da0fe

Browse files
committed
tests: run: Add test for get_login_id.
1 parent 700d4f1 commit e5da0fe

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/cli/test_run.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from zulipterminal.cli.run import main, in_color, THEMES
2+
from zulipterminal.cli.run import main, in_color, THEMES, get_login_id
33
from zulipterminal.model import ServerConnectionFailure
44
from zulipterminal.version import ZT_VERSION
55

@@ -16,6 +16,29 @@ def test_in_color(color, code, text="some text"):
1616
assert in_color(color, text) == code + text + "\x1b[0m"
1717

1818

19+
@pytest.mark.parametrize('json, label', [
20+
(dict(require_email_format_usernames=False, email_auth_enabled=True),
21+
'Email or Username'),
22+
(dict(require_email_format_usernames=False, email_auth_enabled=False),
23+
'Username'),
24+
(dict(require_email_format_usernames=True, email_auth_enabled=True),
25+
'Email'),
26+
(dict(require_email_format_usernames=True, email_auth_enabled=False),
27+
'Email'),
28+
])
29+
def test_get_login_id(mocker, json, label):
30+
response = mocker.Mock(json=lambda: json)
31+
mocked_get = mocker.patch('requests.get', return_value=response)
32+
mocked_styled_input = mocker.patch('zulipterminal.cli.run.styled_input',
33+
return_value='input return value')
34+
35+
result = get_login_id('REALM_URL')
36+
37+
assert result == 'input return value'
38+
mocked_get.assert_called_with(url='REALM_URL/api/v1/server_settings')
39+
mocked_styled_input.assert_called_with(label + ': ')
40+
41+
1942
@pytest.mark.parametrize('options', ['-h', '--help'])
2043
def test_main_help(capsys, options):
2144
with pytest.raises(SystemExit):

0 commit comments

Comments
 (0)