Skip to content

Commit 0aff11f

Browse files
committed
feat(commands/signout): confirm unless forced
1 parent ab1eb52 commit 0aff11f

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

compiler_admin/commands/signout.py

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def signout(args: Namespace) -> int:
2121
print(f"User does not exist: {account}")
2222
return RESULT_FAILURE
2323

24+
if getattr(args, "force", False) is False:
25+
cont = input(f"Signout account {account} from all active sessions? (Y/n)")
26+
if not cont.lower().startswith("y"):
27+
print("Aborting signout.")
28+
return RESULT_SUCCESS
29+
2430
print(f"User exists, signing out from all active sessions: {account}")
2531

2632
res = CallGAMCommand(("user", account, "signout"))

compiler_admin/main.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ def _subcmd(name, help, add_username_arg=True) -> argparse.ArgumentParser:
6262

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

65-
_subcmd("signout", help="Signs a user out from all active sessions.")
65+
signout_parser = _subcmd("signout", help="Signs a user out from all active sessions.")
66+
signout_parser.add_argument(
67+
"--force", action="store_true", default=False, help="Don't ask for confirmation before signout."
68+
)
6669

6770
if len(argv) == 0:
6871
argv = ["info"]

tests/commands/test_signout.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
from compiler_admin.commands.signout import signout, __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_google_user_exists(mock_google_user_exists):
1024
return mock_google_user_exists(MODULE)
@@ -22,7 +36,8 @@ def test_signout_user_username_required():
2236
signout(args)
2337

2438

25-
def test_signout_user_exists(mock_google_user_exists, mock_google_CallGAMCommand):
39+
@pytest.mark.usefixtures("mock_input_yes")
40+
def test_signout_confirm_yes(mock_google_user_exists, mock_google_CallGAMCommand):
2641
mock_google_user_exists.return_value = True
2742

2843
args = Namespace(username="username")
@@ -34,11 +49,22 @@ def test_signout_user_exists(mock_google_user_exists, mock_google_CallGAMCommand
3449
assert "user" in call_args and "signout" in call_args
3550

3651

52+
@pytest.mark.usefixtures("mock_input_no")
53+
def test_signout_confirm_no(mock_google_user_exists, mock_google_CallGAMCommand):
54+
mock_google_user_exists.return_value = True
55+
56+
args = Namespace(username="username")
57+
res = signout(args)
58+
59+
assert res == RESULT_SUCCESS
60+
mock_google_CallGAMCommand.assert_not_called()
61+
62+
3763
def test_signout_user_does_not_exist(mock_google_user_exists, mock_google_CallGAMCommand):
3864
mock_google_user_exists.return_value = False
3965

4066
args = Namespace(username="username")
4167
res = signout(args)
4268

4369
assert res == RESULT_FAILURE
44-
assert mock_google_CallGAMCommand.call_count == 0
70+
mock_google_CallGAMCommand.assert_not_called()

tests/test_main.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,15 @@ def test_main_signout(mock_commands_signout):
196196

197197
mock_commands_signout.assert_called_once()
198198
call_args = mock_commands_signout.call_args.args
199-
assert Namespace(command="signout", username="username") in call_args
199+
assert Namespace(command="signout", username="username", force=False) in call_args
200+
201+
202+
def test_main_signout_force(mock_commands_signout):
203+
main(argv=["signout", "username", "--force"])
204+
205+
mock_commands_signout.assert_called_once()
206+
call_args = mock_commands_signout.call_args.args
207+
assert Namespace(command="signout", username="username", force=True) in call_args
200208

201209

202210
def test_main_signout_no_username(mock_commands_signout):

0 commit comments

Comments
 (0)