Skip to content

Commit 0ae1c93

Browse files
committed
refactor(switch): update command func to take separate args
1 parent 6f5830c commit 0ae1c93

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

littlepay/commands/switch.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from littlepay.commands.configure import configure
2-
from littlepay.config import CONFIG_TYPES, Config
2+
from littlepay.config import Config
33

44

5-
def switch(switch_type: str, switch_arg: str) -> int:
6-
if switch_type not in CONFIG_TYPES:
7-
raise ValueError(f"Unsupported type: {switch_type}, must be one of: {', '.join(CONFIG_TYPES)}")
5+
def switch(env: str = None, participant: str = None) -> int:
6+
if not (participant or env):
7+
raise ValueError("Unsupported type: provide at least one of participant or env.")
88

99
config = Config()
1010

11-
if switch_type == "env":
12-
config.active_env_name = switch_arg
13-
elif switch_type == "participant":
14-
config.active_participant_id = switch_arg
11+
if env:
12+
config.active_env_name = env
13+
if participant:
14+
config.active_participant_id = participant
1515

1616
return configure()

tests/commands/test_switch.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,33 @@ def sample_config(custom_config_file: Path) -> dict:
2626

2727
def test_switch_env(mock_commands_config):
2828
assert Config().active_env_name == "e1"
29-
res = switch(switch_type="env", switch_arg="e2")
29+
assert Config().active_participant_id == "p1"
30+
res = switch(env="e2")
3031

3132
assert res == RESULT_SUCCESS
3233
mock_commands_config.assert_called_once_with()
33-
assert Config().active_env_name != "e1"
3434
assert Config().active_env_name == "e2"
35+
assert Config().active_participant_id == "p1"
3536

3637

3738
def test_switch_participant(mock_commands_config):
39+
assert Config().active_env_name == "e1"
3840
assert Config().active_participant_id == "p1"
39-
res = switch(switch_type="participant", switch_arg="p2")
41+
res = switch(participant="p2")
4042

4143
assert res == RESULT_SUCCESS
4244
mock_commands_config.assert_called_once_with()
43-
assert Config().active_participant_id != "p1"
45+
assert Config().active_env_name == "e1"
4446
assert Config().active_participant_id == "p2"
4547

4648

47-
def test_switch_unrecognized_type(mock_commands_config):
48-
env = Config().active_env_name
49-
participant = Config().active_participant_id
49+
def test_switch_both(mock_commands_config):
50+
assert Config().active_env_name == "e1"
51+
assert Config().active_participant_id == "p1"
5052

51-
with pytest.raises(ValueError):
52-
switch(switch_type="unrecognized", switch_arg="new_value")
53+
res = switch(env="e2", participant="p2")
5354

54-
assert Config().active_env_name == env
55-
assert Config().active_participant_id == participant
56-
assert mock_commands_config.call_count == 0
55+
assert res == RESULT_SUCCESS
56+
mock_commands_config.assert_called_once_with()
57+
assert Config().active_env_name == "e2"
58+
assert Config().active_participant_id == "p2"

0 commit comments

Comments
 (0)