-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_reset_password.py
70 lines (44 loc) · 2.15 KB
/
test_reset_password.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from argparse import Namespace
import pytest
from compiler_admin.commands import RESULT_FAILURE, RESULT_SUCCESS
from compiler_admin.commands.reset_password import reset_password, __name__ as MODULE
from compiler_admin.services.google import USER_HELLO
@pytest.fixture
def mock_google_user_exists(mock_google_user_exists):
return mock_google_user_exists(MODULE)
@pytest.fixture
def mock_commands_signout(mock_commands_signout):
return mock_commands_signout(MODULE)
@pytest.fixture
def mock_google_CallGAMCommand(mock_google_CallGAMCommand):
return mock_google_CallGAMCommand(MODULE)
def test_reset_password_user_username_required():
args = Namespace()
with pytest.raises(ValueError, match="username is required"):
reset_password(args)
def test_reset_password_user_does_not_exist(mock_google_user_exists):
mock_google_user_exists.return_value = False
args = Namespace(username="username")
res = reset_password(args)
assert res == RESULT_FAILURE
def test_reset_password_user_exists(mock_google_user_exists, mock_google_CallGAMCommand, mock_commands_signout):
mock_google_user_exists.return_value = True
args = Namespace(username="username")
res = reset_password(args)
assert res == RESULT_SUCCESS
mock_google_CallGAMCommand.assert_called_once()
call_args = " ".join(mock_google_CallGAMCommand.call_args[0][0])
assert "update user" in call_args
assert "password random changepassword" in call_args
mock_commands_signout.assert_called_once_with(args)
def test_reset_password_notify(mock_google_user_exists, mock_google_CallGAMCommand, mock_commands_signout):
mock_google_user_exists.return_value = True
args = Namespace(username="username", notify="[email protected]")
res = reset_password(args)
assert res == RESULT_SUCCESS
mock_google_CallGAMCommand.assert_called_once()
call_args = " ".join(mock_google_CallGAMCommand.call_args[0][0])
assert "update user" in call_args
assert "password random changepassword" in call_args
assert f"notify [email protected] from {USER_HELLO}" in call_args
mock_commands_signout.assert_called_once_with(args)