Skip to content

Commit 7ed9933

Browse files
committed
fix(user): rename reset password command/function
the implementation expects command name and function name to match for the auto-discovery to work previously we had 'reset-password' as the command name and 'reset_password' as the function name this normalizes them both to 'reset'
1 parent f0c5bf8 commit 7ed9933

File tree

7 files changed

+26
-29
lines changed

7 files changed

+26
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ The following commands are available to work with users in the Compiler domain:
114114
115115
```bash
116116
$ compiler-admin user -h
117-
usage: compiler-admin user [-h] {create,convert,delete,offboard,reset-password,restore,signout} ...
117+
usage: compiler-admin user [-h] {create,convert,delete,offboard,reset,restore,signout} ...
118118
119119
positional arguments:
120-
{create,convert,delete,offboard,reset-password,restore,signout}
120+
{create,convert,delete,offboard,reset,restore,signout}
121121
The user command to run.
122122
create Create a new user in the Compiler domain.
123123
convert Convert a user account to a new type.
124124
delete Delete a user account.
125125
offboard Offboard a user account.
126-
reset-password Reset a user's password to a randomly generated string.
126+
reset Reset a user's password to a randomly generated string.
127127
restore Restore an email backup from a prior offboarding.
128128
signout Signs a user out from all active sessions.
129129

compiler_admin/commands/user/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from compiler_admin.commands.user.convert import convert # noqa: F401
55
from compiler_admin.commands.user.delete import delete # noqa: F401
66
from compiler_admin.commands.user.offboard import offboard # noqa: F401
7-
from compiler_admin.commands.user.reset_password import reset_password # noqa: F401
7+
from compiler_admin.commands.user.reset import reset # noqa: F401
88
from compiler_admin.commands.user.restore import restore # noqa: F401
99
from compiler_admin.commands.user.signout import signout # noqa: F401
1010

compiler_admin/commands/user/reset_password.py renamed to compiler_admin/commands/user/reset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from compiler_admin.services.google import USER_HELLO, CallGAMCommand, user_account_name, user_exists
66

77

8-
def reset_password(args: Namespace) -> int:
8+
def reset(args: Namespace) -> int:
99
"""Reset a user's password.
1010
1111
Optionally notify an email address with the new randomly generated password.

compiler_admin/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def setup_user_command(cmd_parsers: _SubParsersAction):
149149
)
150150

151151
user_reset = add_sub_cmd_with_username_arg(
152-
user_subcmds, "reset-password", help="Reset a user's password to a randomly generated string."
152+
user_subcmds, "reset", help="Reset a user's password to a randomly generated string."
153153
)
154154
user_reset.add_argument("--notify", help="An email address to send the newly generated password.")
155155

tests/commands/user/test_reset_password.py renamed to tests/commands/user/test_reset.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
from compiler_admin import RESULT_FAILURE, RESULT_SUCCESS
5-
from compiler_admin.commands.user.reset_password import reset_password, __name__ as MODULE
5+
from compiler_admin.commands.user.reset import reset, __name__ as MODULE
66
from compiler_admin.services.google import USER_HELLO
77

88

@@ -21,27 +21,27 @@ def mock_google_CallGAMCommand(mock_google_CallGAMCommand):
2121
return mock_google_CallGAMCommand(MODULE)
2222

2323

24-
def test_reset_password_user_username_required():
24+
def test_reset_user_username_required():
2525
args = Namespace()
2626

2727
with pytest.raises(ValueError, match="username is required"):
28-
reset_password(args)
28+
reset(args)
2929

3030

31-
def test_reset_password_user_does_not_exist(mock_google_user_exists):
31+
def test_reset_user_does_not_exist(mock_google_user_exists):
3232
mock_google_user_exists.return_value = False
3333

3434
args = Namespace(username="username")
35-
res = reset_password(args)
35+
res = reset(args)
3636

3737
assert res == RESULT_FAILURE
3838

3939

40-
def test_reset_password_user_exists(mock_google_user_exists, mock_google_CallGAMCommand, mock_commands_signout):
40+
def test_reset_user_exists(mock_google_user_exists, mock_google_CallGAMCommand, mock_commands_signout):
4141
mock_google_user_exists.return_value = True
4242

4343
args = Namespace(username="username")
44-
res = reset_password(args)
44+
res = reset(args)
4545

4646
assert res == RESULT_SUCCESS
4747

@@ -53,11 +53,11 @@ def test_reset_password_user_exists(mock_google_user_exists, mock_google_CallGAM
5353
mock_commands_signout.assert_called_once_with(args)
5454

5555

56-
def test_reset_password_notify(mock_google_user_exists, mock_google_CallGAMCommand, mock_commands_signout):
56+
def test_reset_notify(mock_google_user_exists, mock_google_CallGAMCommand, mock_commands_signout):
5757
mock_google_user_exists.return_value = True
5858

5959
args = Namespace(username="username", notify="notification@example.com")
60-
res = reset_password(args)
60+
res = reset(args)
6161

6262
assert res == RESULT_SUCCESS
6363

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ def mock_commands_offboard(mock_module_name):
7070

7171

7272
@pytest.fixture
73-
def mock_commands_reset_password(mock_module_name):
74-
"""Fixture returns a function that patches the reset_password command function in a given module."""
75-
return mock_module_name("reset_password")
73+
def mock_commands_reset(mock_module_name):
74+
"""Fixture returns a function that patches the reset command function in a given module."""
75+
return mock_module_name("reset")
7676

7777

7878
@pytest.fixture

tests/test_main.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,33 +388,30 @@ def test_main_user_offboard_no_username(mock_commands_user):
388388
assert mock_commands_user.call_count == 0
389389

390390

391-
def test_main_user_reset_password(mock_commands_user):
392-
main(argv=["user", "reset-password", "username"])
391+
def test_main_user_reset(mock_commands_user):
392+
main(argv=["user", "reset", "username"])
393393

394394
mock_commands_user.assert_called_once()
395395
call_args = mock_commands_user.call_args.args
396396
assert (
397-
Namespace(func=mock_commands_user, command="user", subcommand="reset-password", username="username", notify=None)
398-
in call_args
397+
Namespace(func=mock_commands_user, command="user", subcommand="reset", username="username", notify=None) in call_args
399398
)
400399

401400

402-
def test_main_user_reset_password_notify(mock_commands_user):
403-
main(argv=["user", "reset-password", "username", "--notify", "notification"])
401+
def test_main_user_reset_notify(mock_commands_user):
402+
main(argv=["user", "reset", "username", "--notify", "notification"])
404403

405404
mock_commands_user.assert_called_once()
406405
call_args = mock_commands_user.call_args.args
407406
assert (
408-
Namespace(
409-
func=mock_commands_user, command="user", subcommand="reset-password", username="username", notify="notification"
410-
)
407+
Namespace(func=mock_commands_user, command="user", subcommand="reset", username="username", notify="notification")
411408
in call_args
412409
)
413410

414411

415-
def test_main_user_reset_password_no_username(mock_commands_user):
412+
def test_main_user_reset_no_username(mock_commands_user):
416413
with pytest.raises(SystemExit):
417-
main(argv=["user", "reset-password"])
414+
main(argv=["user", "reset"])
418415
assert mock_commands_user.call_count == 0
419416

420417

0 commit comments

Comments
 (0)