|
7 | 7 | from code42cli.main import cli |
8 | 8 |
|
9 | 9 |
|
| 10 | +_SELECTED_PROFILE_NAME = "test_profile" |
| 11 | + |
| 12 | + |
10 | 13 | @pytest.fixture |
11 | 14 | def user_agreement(mocker): |
12 | 15 | mock = mocker.patch("code42cli.cmds.profile.does_user_agree") |
@@ -50,6 +53,13 @@ def invalid_connection(mock_verify): |
50 | 53 | return mock_verify |
51 | 54 |
|
52 | 55 |
|
| 56 | +@pytest.fixture |
| 57 | +def profile_name_selector(mocker): |
| 58 | + mock = mocker.patch("code42cli.cmds.profile.click.prompt") |
| 59 | + mock.return_value = _SELECTED_PROFILE_NAME |
| 60 | + return mock |
| 61 | + |
| 62 | + |
53 | 63 | def test_show_profile_outputs_profile_info(runner, mock_cliprofile_namespace, profile): |
54 | 64 | profile.name = "testname" |
55 | 65 | profile.authority_url = "example.com" |
@@ -511,6 +521,29 @@ def test_use_profile(runner, mock_cliprofile_namespace, profile): |
511 | 521 | assert f"{profile.name} has been set as the default profile." in result.output |
512 | 522 |
|
513 | 523 |
|
| 524 | +def test_use_profile_when_not_given_profile_name_arg_sets_selected_profile_as_default( |
| 525 | + runner, mock_cliprofile_namespace, profile_name_selector |
| 526 | +): |
| 527 | + runner.invoke(cli, ["profile", "use"]) |
| 528 | + mock_cliprofile_namespace.switch_default_profile.assert_called_once_with( |
| 529 | + _SELECTED_PROFILE_NAME |
| 530 | + ) |
| 531 | + |
| 532 | + |
| 533 | +def test_use_profile_when_not_given_profile_name_outputs_expected_text( |
| 534 | + runner, mock_cliprofile_namespace, profile_name_selector |
| 535 | +): |
| 536 | + mock_cliprofile_namespace.get_all_profiles.return_value = [ |
| 537 | + create_mock_profile("test1"), |
| 538 | + create_mock_profile("test2"), |
| 539 | + ] |
| 540 | + result = runner.invoke(cli, ["profile", "use"]) |
| 541 | + expected_prompt = "1. test1\n2. test2" |
| 542 | + expected_result_message = "test_profile has been set as the default profile." |
| 543 | + assert expected_prompt in result.output |
| 544 | + assert expected_result_message in result.output |
| 545 | + |
| 546 | + |
514 | 547 | def test_totp_option_passes_token_to_sdk_on_profile_cmds_that_init_sdk( |
515 | 548 | runner, mocker, mock_cliprofile_namespace, cli_state |
516 | 549 | ): |
|
0 commit comments