Skip to content

Commit ab1eb52

Browse files
committed
feat(commands/offboard): confirm unless forced
1 parent bb44a92 commit ab1eb52

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

compiler_admin/commands/offboard.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def offboard(args: Namespace) -> int:
3939
print(f"Alias target user does not exist: {alias_account}")
4040
return RESULT_FAILURE
4141

42+
if getattr(args, "force", False) is False:
43+
cont = input(f"Offboard account {account} {' (assigning alias to '+ alias_account +')' if alias else ''}? (Y/n)")
44+
if not cont.lower().startswith("y"):
45+
print("Aborting offboard.")
46+
return RESULT_SUCCESS
47+
4248
print(f"User exists, offboarding: {account}")
4349
res = RESULT_SUCCESS
4450

compiler_admin/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def _subcmd(name, help, add_username_arg=True) -> argparse.ArgumentParser:
5656

5757
offboard_parser = _subcmd("offboard", help="Offboard a user account.")
5858
offboard_parser.add_argument("--alias", help="Account to assign username as an alias.")
59+
offboard_parser.add_argument(
60+
"--force", action="store_true", default=False, help="Don't ask for confirmation before offboarding."
61+
)
5962

6063
_subcmd("restore", help="Restore an email backup from a prior offboarding.")
6164

tests/commands/test_offboard.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
from compiler_admin.commands.offboard import offboard, __name__ as MODULE
66

77

8+
@pytest.fixture
9+
def mock_input_yes(mock_input):
10+
fix = mock_input(MODULE)
11+
fix.return_value = "y"
12+
return fix
13+
14+
15+
@pytest.fixture
16+
def mock_input_no(mock_input):
17+
fix = mock_input(MODULE)
18+
fix.return_value = "n"
19+
return fix
20+
21+
822
@pytest.fixture
923
def mock_NamedTemporaryFile(mock_NamedTemporaryFile):
1024
return mock_NamedTemporaryFile(MODULE, ["Overall Transfer Status: completed"])
@@ -42,7 +56,8 @@ def test_offboard_user_username_required():
4256
offboard(args)
4357

4458

45-
def test_offboard_user_exists(
59+
@pytest.mark.usefixtures("mock_input_yes")
60+
def test_offboard_confirm_yes(
4661
mock_google_user_exists,
4762
mock_google_CallGAMCommand,
4863
mock_google_CallGYBCommand,
@@ -64,6 +79,27 @@ def test_offboard_user_exists(
6479
mock_commands_delete.assert_called_once()
6580

6681

82+
@pytest.mark.usefixtures("mock_input_no")
83+
def test_offboard_confirm_no(
84+
mock_google_user_exists,
85+
mock_google_CallGAMCommand,
86+
mock_google_CallGYBCommand,
87+
mock_commands_signout,
88+
mock_commands_delete,
89+
):
90+
mock_google_user_exists.return_value = True
91+
92+
args = Namespace(username="username")
93+
res = offboard(args)
94+
95+
assert res == RESULT_SUCCESS
96+
mock_google_CallGAMCommand.assert_not_called()
97+
mock_google_CallGYBCommand.assert_not_called()
98+
99+
mock_commands_signout.assert_not_called()
100+
mock_commands_delete.assert_not_called()
101+
102+
67103
def test_offboard_user_does_not_exist(mock_google_user_exists, mock_google_CallGAMCommand):
68104
mock_google_user_exists.return_value = False
69105

tests/test_main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,23 @@ def test_main_offboard(mock_commands_offboard):
152152

153153
mock_commands_offboard.assert_called_once()
154154
call_args = mock_commands_offboard.call_args.args
155-
assert Namespace(command="offboard", username="username", alias=None) in call_args
155+
assert Namespace(command="offboard", username="username", alias=None, force=False) in call_args
156+
157+
158+
def test_main_offboard_force(mock_commands_offboard):
159+
main(argv=["offboard", "username", "--force"])
160+
161+
mock_commands_offboard.assert_called_once()
162+
call_args = mock_commands_offboard.call_args.args
163+
assert Namespace(command="offboard", username="username", alias=None, force=True) in call_args
156164

157165

158166
def test_main_offboard_with_alias(mock_commands_offboard):
159167
main(argv=["offboard", "username", "--alias", "anotheruser"])
160168

161169
mock_commands_offboard.assert_called_once()
162170
call_args = mock_commands_offboard.call_args.args
163-
assert Namespace(command="offboard", username="username", alias="anotheruser") in call_args
171+
assert Namespace(command="offboard", username="username", alias="anotheruser", force=False) in call_args
164172

165173

166174
def test_main_offboard_no_username(mock_commands_offboard):

0 commit comments

Comments
 (0)