|
| 1 | +import os |
1 | 2 | from unittest.mock import mock_open, patch |
2 | 3 |
|
3 | 4 | import pytest |
@@ -29,50 +30,68 @@ def teardown_function(): |
29 | 30 | def test_get_type_configuration_with_not_exist_file(): |
30 | 31 | with patch("builtins.open", mock_open()) as f: |
31 | 32 | f.side_effect = FileNotFoundError() |
32 | | - assert TypeConfiguration.get_type_configuration() is None |
| 33 | + assert TypeConfiguration.get_type_configuration(None) is None |
| 34 | + |
| 35 | + |
| 36 | +def test_get_type_configuration_with_default_typeconfig_location(): |
| 37 | + with patch( |
| 38 | + "builtins.open", mock_open(read_data=TYPE_CONFIGURATION_TEST_SETTING) |
| 39 | + ) as f: |
| 40 | + TypeConfiguration.get_type_configuration(None) |
| 41 | + f.assert_called_with( |
| 42 | + os.path.expanduser("~/.cfn-cli/typeConfiguration.json"), encoding="utf-8" |
| 43 | + ) |
| 44 | + |
| 45 | + |
| 46 | +def test_get_type_configuration_with_set_typeconfig_location(): |
| 47 | + with patch( |
| 48 | + "builtins.open", mock_open(read_data=TYPE_CONFIGURATION_TEST_SETTING) |
| 49 | + ) as f: |
| 50 | + TypeConfiguration.get_type_configuration("./test.json") |
| 51 | + f.assert_called_with("./test.json", encoding="utf-8") |
33 | 52 |
|
34 | 53 |
|
35 | 54 | @patch("builtins.open", mock_open(read_data=TYPE_CONFIGURATION_TEST_SETTING)) |
36 | 55 | def test_get_type_configuration(): |
37 | | - type_configuration = TypeConfiguration.get_type_configuration() |
| 56 | + type_configuration = TypeConfiguration.get_type_configuration(None) |
38 | 57 | assert type_configuration["Credentials"]["ApiKey"] == "123" |
39 | 58 | assert type_configuration["Credentials"]["ApplicationKey"] == "123" |
40 | 59 |
|
41 | 60 | # get type config again, should be the same config |
42 | | - type_configuration = TypeConfiguration.get_type_configuration() |
| 61 | + type_configuration = TypeConfiguration.get_type_configuration(None) |
43 | 62 | assert type_configuration["Credentials"]["ApiKey"] == "123" |
44 | 63 | assert type_configuration["Credentials"]["ApplicationKey"] == "123" |
45 | 64 |
|
46 | 65 |
|
47 | 66 | @patch("builtins.open", mock_open(read_data=TYPE_CONFIGURATION_INVALID)) |
48 | 67 | def test_get_type_configuration_with_invalid_json(): |
49 | 68 | try: |
50 | | - TypeConfiguration.get_type_configuration() |
| 69 | + TypeConfiguration.get_type_configuration(None) |
51 | 70 | except InvalidProjectError: |
52 | 71 | pass |
53 | 72 |
|
54 | 73 |
|
55 | 74 | @patch("builtins.open", mock_open(read_data=HOOK_CONFIGURATION_TEST_SETTING)) |
56 | 75 | def test_get_hook_configuration(): |
57 | | - hook_configuration = TypeConfiguration.get_hook_configuration() |
| 76 | + hook_configuration = TypeConfiguration.get_hook_configuration(None) |
58 | 77 | assert hook_configuration["Credentials"]["ApiKey"] == "123" |
59 | 78 | assert hook_configuration["Credentials"]["ApplicationKey"] == "123" |
60 | 79 |
|
61 | 80 | # get type config again, should be the same config |
62 | | - hook_configuration = TypeConfiguration.get_hook_configuration() |
| 81 | + hook_configuration = TypeConfiguration.get_hook_configuration(None) |
63 | 82 | assert hook_configuration["Credentials"]["ApiKey"] == "123" |
64 | 83 | assert hook_configuration["Credentials"]["ApplicationKey"] == "123" |
65 | 84 |
|
66 | 85 |
|
67 | 86 | @patch("builtins.open", mock_open(read_data=HOOK_CONFIGURATION_INVALID)) |
68 | 87 | def test_get_hook_configuration_with_invalid_json(): |
69 | 88 | with pytest.raises(InvalidProjectError) as execinfo: |
70 | | - TypeConfiguration.get_hook_configuration() |
| 89 | + TypeConfiguration.get_hook_configuration(None) |
71 | 90 |
|
72 | 91 | assert "Hook configuration is invalid" in str(execinfo.value) |
73 | 92 |
|
74 | 93 |
|
75 | 94 | def test_get_hook_configuration_with_not_exist_file(): |
76 | 95 | with patch("builtins.open", mock_open()) as f: |
77 | 96 | f.side_effect = FileNotFoundError() |
78 | | - assert TypeConfiguration.get_hook_configuration() is None |
| 97 | + assert TypeConfiguration.get_hook_configuration(None) is None |
0 commit comments