Skip to content

Commit a01e05c

Browse files
committed
feat(user): expose alumni in convert command
1 parent bfbb112 commit a01e05c

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

compiler_admin/commands/user/convert.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from argparse import Namespace
22

33
from compiler_admin import RESULT_SUCCESS, RESULT_FAILURE
4+
from compiler_admin.commands.user.alumni import alumni
45
from compiler_admin.services.google import (
56
GROUP_PARTNERS,
67
GROUP_STAFF,
8+
OU_ALUMNI,
79
OU_CONTRACTORS,
810
OU_PARTNERS,
911
OU_STAFF,
@@ -17,7 +19,7 @@
1719
)
1820

1921

20-
ACCOUNT_TYPE_OU = {"contractor": OU_CONTRACTORS, "partner": OU_PARTNERS, "staff": OU_STAFF}
22+
ACCOUNT_TYPE_OU = {"alumni": OU_ALUMNI, "contractor": OU_CONTRACTORS, "partner": OU_PARTNERS, "staff": OU_STAFF}
2123

2224

2325
def convert(args: Namespace) -> int:
@@ -48,7 +50,10 @@ def convert(args: Namespace) -> int:
4850
print(f"User exists, converting to: {account_type} for {account}")
4951
res = RESULT_SUCCESS
5052

51-
if account_type == "contractor":
53+
if account_type == "alumni":
54+
res = alumni(args)
55+
56+
elif account_type == "contractor":
5257
if user_is_partner(account):
5358
res += remove_user_from_group(account, GROUP_PARTNERS)
5459
res += remove_user_from_group(account, GROUP_STAFF)

compiler_admin/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ def setup_user_command(cmd_parsers: _SubParsersAction):
144144

145145
user_convert = add_sub_cmd_with_username_arg(user_subcmds, "convert", help="Convert a user account to a new type.")
146146
user_convert.add_argument("account_type", choices=ACCOUNT_TYPE_OU.keys(), help="Target account type for this conversion.")
147+
user_convert.add_argument(
148+
"--force", action="store_true", default=False, help="Don't ask for confirmation before conversion."
149+
)
150+
user_convert.add_argument("--notify", help="An email address to send the alumni's new password.")
147151

148152
user_delete = add_sub_cmd_with_username_arg(user_subcmds, "delete", help="Delete a user account.")
149153
user_delete.add_argument("--force", action="store_true", default=False, help="Don't ask for confirmation before deletion.")

tests/commands/user/test_convert.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
from compiler_admin.commands.user.convert import convert, __name__ as MODULE
66

77

8+
@pytest.fixture
9+
def mock_commands_alumni(mock_commands_alumni):
10+
return mock_commands_alumni(MODULE)
11+
12+
813
@pytest.fixture
914
def mock_google_user_exists(mock_google_user_exists):
1015
return mock_google_user_exists(MODULE)
@@ -98,6 +103,16 @@ def test_convert_user_exists_bad_account_type(mock_google_move_user_ou):
98103
assert mock_google_move_user_ou.call_count == 0
99104

100105

106+
@pytest.mark.usefixtures("mock_google_user_exists_true")
107+
def test_convert_alumni(mock_commands_alumni, mock_google_move_user_ou):
108+
args = Namespace(username="username", account_type="alumni")
109+
res = convert(args)
110+
111+
assert res == RESULT_SUCCESS
112+
mock_commands_alumni.assert_called_once_with(args)
113+
mock_google_move_user_ou.assert_called_once()
114+
115+
101116
@pytest.mark.usefixtures(
102117
"mock_google_user_exists_true", "mock_google_user_is_partner_false", "mock_google_user_is_staff_false"
103118
)

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def mock_input(mock_module_name):
3333
return mock_module_name("input")
3434

3535

36+
@pytest.fixture
37+
def mock_commands_alumni(mock_module_name):
38+
"""Fixture returns a function that patches the alumni function in a given module."""
39+
return mock_module_name("alumni")
40+
41+
3642
@pytest.fixture
3743
def mock_commands_create(mock_module_name):
3844
"""Fixture returns a function that patches the create function in a given module."""

tests/test_main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,13 @@ def test_main_user_convert(mock_commands_user):
345345
call_args = mock_commands_user.call_args.args
346346
assert (
347347
Namespace(
348-
func=mock_commands_user, command="user", subcommand="convert", username="username", account_type="contractor"
348+
func=mock_commands_user,
349+
command="user",
350+
subcommand="convert",
351+
username="username",
352+
account_type="contractor",
353+
force=False,
354+
notify=None,
349355
)
350356
in call_args
351357
)

0 commit comments

Comments
 (0)