|
| 1 | +from argparse import Namespace |
| 2 | +import pytest |
| 3 | + |
| 4 | +from compiler_admin.commands import RESULT_FAILURE, RESULT_SUCCESS |
| 5 | +from compiler_admin.commands.reset_password import reset_password, __name__ as MODULE |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def mock_google_user_exists(mock_google_user_exists): |
| 10 | + return mock_google_user_exists(MODULE) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.fixture |
| 14 | +def mock_google_CallGAMCommand(mock_google_CallGAMCommand): |
| 15 | + return mock_google_CallGAMCommand(MODULE) |
| 16 | + |
| 17 | + |
| 18 | +def test_reset_password_user_username_required(): |
| 19 | + args = Namespace() |
| 20 | + |
| 21 | + with pytest.raises(ValueError, match="username is required"): |
| 22 | + reset_password(args) |
| 23 | + |
| 24 | + |
| 25 | +def test_reset_password_user_does_not_exist(mock_google_user_exists): |
| 26 | + mock_google_user_exists.return_value = False |
| 27 | + |
| 28 | + args = Namespace(username="username") |
| 29 | + res = reset_password(args) |
| 30 | + |
| 31 | + assert res == RESULT_FAILURE |
| 32 | + |
| 33 | + |
| 34 | +def test_reset_password_user_exists(mock_google_user_exists, mock_google_CallGAMCommand): |
| 35 | + mock_google_user_exists.return_value = True |
| 36 | + |
| 37 | + args = Namespace(username="username") |
| 38 | + res = reset_password(args) |
| 39 | + |
| 40 | + assert res == RESULT_SUCCESS |
| 41 | + |
| 42 | + mock_google_CallGAMCommand.assert_called_once() |
| 43 | + call_args = " ".join(mock_google_CallGAMCommand.call_args[0][0]) |
| 44 | + assert "update user" in call_args |
| 45 | + assert "password random" in call_args |
| 46 | + |
| 47 | + |
| 48 | +def test_reset_password_notify(mock_google_user_exists, mock_google_CallGAMCommand): |
| 49 | + mock_google_user_exists.return_value = True |
| 50 | + |
| 51 | + args = Namespace( username="username", notify="[email protected]") |
| 52 | + res = reset_password(args) |
| 53 | + |
| 54 | + assert res == RESULT_SUCCESS |
| 55 | + |
| 56 | + mock_google_CallGAMCommand.assert_called_once() |
| 57 | + call_args = " ".join(mock_google_CallGAMCommand.call_args[0][0]) |
| 58 | + assert "update user" in call_args |
| 59 | + assert "password random" in call_args |
| 60 | + assert "notify [email protected] from [email protected]" in call_args |
0 commit comments