|
10 | 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11 | 11 | # ANY KIND, either express or implied. See the License for the specific
|
12 | 12 | # language governing permissions and limitations under the License.
|
| 13 | +import mock |
| 14 | +import os |
13 | 15 | import unittest
|
14 | 16 |
|
15 | 17 | from awsshell.app import AWSShell
|
16 | 18 | from awsshell.config import Config
|
| 19 | +from awsshell.utils import build_config_file_path |
17 | 20 |
|
18 | 21 |
|
19 | 22 | class ConfigTest(unittest.TestCase):
|
20 | 23 |
|
21 |
| - def setUp(self): |
22 |
| - self.load_config() |
23 |
| - |
24 |
| - def load_config(self): |
25 |
| - config = Config() |
26 |
| - self.config_obj = config.load('awsshellrc', 'test-awsshellrc') |
27 |
| - self.config_section = self.config_obj['aws-shell'] |
28 |
| - |
29 | 24 | def test_config_off(self):
|
30 |
| - self.config_section['match_fuzzy'] = False |
31 |
| - self.config_section['enable_vi_bindings'] = False |
32 |
| - self.config_section['show_completion_columns'] = False |
33 |
| - self.config_section['show_help'] = False |
34 |
| - self.config_section['theme'] = 'none' |
35 |
| - self.config_obj.write() |
36 |
| - self.load_config() |
37 |
| - assert self.config_section.as_bool('match_fuzzy') == False |
38 |
| - assert self.config_section.as_bool('enable_vi_bindings') == False |
39 |
| - assert self.config_section.as_bool('show_completion_columns') == False |
40 |
| - assert self.config_section.as_bool('show_help') == False |
41 |
| - assert self.config_section['theme'] == 'none' |
| 25 | + try: |
| 26 | + os.remove(build_config_file_path('test-awsshellrc')) |
| 27 | + except OSError: |
| 28 | + pass |
| 29 | + self.aws_shell = AWSShell(None, mock.Mock(), |
| 30 | + None, mock.Mock()) |
| 31 | + self.aws_shell.model_completer.match_fuzzy = False |
| 32 | + self.aws_shell.enable_vi_bindings = False |
| 33 | + self.aws_shell.show_completion_columns = False |
| 34 | + self.aws_shell.show_help = False |
| 35 | + self.aws_shell.theme = 'none' |
| 36 | + self.aws_shell.save_config() |
| 37 | + self.aws_shell.load_config() |
| 38 | + assert self.aws_shell.model_completer.match_fuzzy == False |
| 39 | + assert self.aws_shell.enable_vi_bindings == False |
| 40 | + assert self.aws_shell.show_completion_columns == False |
| 41 | + assert self.aws_shell.show_help == False |
| 42 | + assert self.aws_shell.theme == 'none' |
42 | 43 |
|
43 | 44 | def test_config_on(self):
|
44 |
| - self.config_section['match_fuzzy'] = True |
45 |
| - self.config_section['enable_vi_bindings'] = True |
46 |
| - self.config_section['show_completion_columns'] = True |
47 |
| - self.config_section['show_help'] = True |
48 |
| - self.config_section['theme'] = 'vim' |
49 |
| - self.config_obj.write() |
50 |
| - self.load_config() |
51 |
| - assert self.config_section.as_bool('match_fuzzy') == True |
52 |
| - assert self.config_section.as_bool('enable_vi_bindings') == True |
53 |
| - assert self.config_section.as_bool('show_completion_columns') == True |
54 |
| - assert self.config_section.as_bool('show_help') == True |
55 |
| - assert self.config_section['theme'] == 'vim' |
| 45 | + self.aws_shell = AWSShell(None, mock.Mock(), |
| 46 | + None, mock.Mock()) |
| 47 | + self.aws_shell.model_completer.match_fuzzy = True |
| 48 | + self.aws_shell.enable_vi_bindings = True |
| 49 | + self.aws_shell.show_completion_columns = True |
| 50 | + self.aws_shell.show_help = True |
| 51 | + self.aws_shell.theme = 'vim' |
| 52 | + self.aws_shell.save_config() |
| 53 | + self.aws_shell.load_config() |
| 54 | + assert self.aws_shell.config_section.as_bool('match_fuzzy') == True |
| 55 | + assert self.aws_shell.config_section.as_bool( |
| 56 | + 'enable_vi_bindings') == True |
| 57 | + assert self.aws_shell.config_section.as_bool( |
| 58 | + 'show_completion_columns') == True |
| 59 | + assert self.aws_shell.config_section.as_bool('show_help') == True |
| 60 | + assert self.aws_shell.config_section['theme'] == 'vim' |
0 commit comments