Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/configure/test_set.py
1569 views
1
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import os
14
15
from awscli.customizations.configure.set import ConfigureSetCommand
16
from awscli.testutils import mock, unittest
17
from . import FakeSession
18
19
20
class TestConfigureSetCommand(unittest.TestCase):
21
22
def setUp(self):
23
self.session = FakeSession({'config_file': 'myconfigfile'})
24
self.fake_credentials_filename = os.path.expanduser(
25
'~/fake_credentials_filename')
26
self.session.profile = None
27
self.config_writer = mock.Mock()
28
29
def test_configure_set_command(self):
30
set_command = ConfigureSetCommand(
31
self.session, self.config_writer)
32
set_command(args=['region', 'us-west-2'], parsed_globals=None)
33
self.config_writer.update_config.assert_called_with(
34
{'__section__': 'default', 'region': 'us-west-2'}, 'myconfigfile')
35
36
def test_configure_set_command_dotted(self):
37
set_command = ConfigureSetCommand(
38
self.session, self.config_writer)
39
set_command(args=['preview.emr', 'true'], parsed_globals=None)
40
self.config_writer.update_config.assert_called_with(
41
{'__section__': 'preview', 'emr': 'true'}, 'myconfigfile')
42
43
def test_configure_set_command_dotted_with_default_profile(self):
44
self.session.variables['profile'] = 'default'
45
set_command = ConfigureSetCommand(
46
self.session, self.config_writer)
47
set_command(
48
args=['emr.instance_profile', 'my_ip_emr'], parsed_globals=None)
49
self.config_writer.update_config.assert_called_with(
50
{'__section__': 'default',
51
'emr': {'instance_profile': 'my_ip_emr'}}, 'myconfigfile')
52
53
def test_configure_set_handles_predefined_plugins_section(self):
54
self.session.variables['profile'] = 'default'
55
set_command = ConfigureSetCommand(
56
self.session, self.config_writer)
57
set_command(
58
args=['plugins.foo', 'mypackage'], parsed_globals=None)
59
self.config_writer.update_config.assert_called_with(
60
{'__section__': 'plugins',
61
'foo': 'mypackage'}, 'myconfigfile')
62
63
def test_configure_set_command_dotted_with_profile(self):
64
self.session.profile = 'emr-dev'
65
set_command = ConfigureSetCommand(
66
self.session, self.config_writer)
67
set_command(
68
args=['emr.instance_profile', 'my_ip_emr'], parsed_globals=None)
69
self.config_writer.update_config.assert_called_with(
70
{'__section__': 'profile emr-dev', 'emr':
71
{'instance_profile': 'my_ip_emr'}}, 'myconfigfile')
72
73
def test_configure_set_with_profile(self):
74
self.session.profile = 'testing'
75
set_command = ConfigureSetCommand(
76
self.session, self.config_writer)
77
set_command(args=['region', 'us-west-2'], parsed_globals=None)
78
self.config_writer.update_config.assert_called_with(
79
{'__section__': 'profile testing', 'region': 'us-west-2'},
80
'myconfigfile')
81
82
def test_configure_set_triple_dotted(self):
83
# aws configure set default.s3.signature_version s3v4
84
set_command = ConfigureSetCommand(
85
self.session, self.config_writer)
86
set_command(args=['default.s3.signature_version', 's3v4'],
87
parsed_globals=None)
88
self.config_writer.update_config.assert_called_with(
89
{'__section__': 'default', 's3': {'signature_version': 's3v4'}},
90
'myconfigfile')
91
92
def test_configure_set_with_profile_nested(self):
93
# aws configure set default.s3.signature_version s3v4
94
set_command = ConfigureSetCommand(
95
self.session, self.config_writer)
96
set_command(args=['profile.foo.s3.signature_version', 's3v4'],
97
parsed_globals=None)
98
self.config_writer.update_config.assert_called_with(
99
{'__section__': 'profile foo',
100
's3': {'signature_version': 's3v4'}}, 'myconfigfile')
101
102
def test_access_key_written_to_shared_credentials_file(self):
103
set_command = ConfigureSetCommand(
104
self.session, self.config_writer)
105
set_command(args=['aws_access_key_id', 'foo'],
106
parsed_globals=None)
107
self.config_writer.update_config.assert_called_with(
108
{'__section__': 'default',
109
'aws_access_key_id': 'foo'}, self.fake_credentials_filename)
110
111
def test_secret_key_written_to_shared_credentials_file(self):
112
set_command = ConfigureSetCommand(
113
self.session, self.config_writer)
114
set_command(args=['aws_secret_access_key', 'foo'],
115
parsed_globals=None)
116
self.config_writer.update_config.assert_called_with(
117
{'__section__': 'default',
118
'aws_secret_access_key': 'foo'}, self.fake_credentials_filename)
119
120
def test_session_token_written_to_shared_credentials_file(self):
121
set_command = ConfigureSetCommand(
122
self.session, self.config_writer)
123
set_command(args=['aws_session_token', 'foo'],
124
parsed_globals=None)
125
self.config_writer.update_config.assert_called_with(
126
{'__section__': 'default',
127
'aws_session_token': 'foo'}, self.fake_credentials_filename)
128
129
def test_access_key_written_to_shared_credentials_file_profile(self):
130
set_command = ConfigureSetCommand(
131
self.session, self.config_writer)
132
set_command(args=['profile.foo.aws_access_key_id', 'bar'],
133
parsed_globals=None)
134
self.config_writer.update_config.assert_called_with(
135
{'__section__': 'foo',
136
'aws_access_key_id': 'bar'}, self.fake_credentials_filename)
137
138
def test_credential_set_profile_with_space(self):
139
self.session.profile = 'some profile'
140
set_command = ConfigureSetCommand(self.session, self.config_writer)
141
set_command(args=['aws_session_token', 'foo'], parsed_globals=None)
142
self.config_writer.update_config.assert_called_with(
143
{'__section__': 'some profile',
144
'aws_session_token': 'foo'}, self.fake_credentials_filename)
145
146
def test_credential_set_profile_with_space_dotted(self):
147
set_command = ConfigureSetCommand(self.session, self.config_writer)
148
set_command(args=['profile.some profile.aws_session_token', 'foo'],
149
parsed_globals=None)
150
self.config_writer.update_config.assert_called_with(
151
{'__section__': 'some profile',
152
'aws_session_token': 'foo'}, self.fake_credentials_filename)
153
154
def test_configure_set_with_profile_with_space(self):
155
self.session.profile = 'some profile'
156
set_command = ConfigureSetCommand(self.session, self.config_writer)
157
set_command(args=['region', 'us-west-2'], parsed_globals=None)
158
self.config_writer.update_config.assert_called_with(
159
{'__section__': "profile 'some profile'", 'region': 'us-west-2'},
160
'myconfigfile')
161
162
def test_configure_set_with_profile_with_space_dotted(self):
163
set_command = ConfigureSetCommand(self.session, self.config_writer)
164
set_command(args=['profile.some profile.region', 'us-west-2'],
165
parsed_globals=None)
166
self.config_writer.update_config.assert_called_with(
167
{'__section__': "profile 'some profile'", 'region': 'us-west-2'},
168
'myconfigfile')
169
170
def test_credential_set_profile_with_tab(self):
171
self.session.profile = 'some\tprofile'
172
set_command = ConfigureSetCommand(self.session, self.config_writer)
173
set_command(args=['aws_session_token', 'foo'], parsed_globals=None)
174
self.config_writer.update_config.assert_called_with(
175
{'__section__': 'some\tprofile',
176
'aws_session_token': 'foo'}, self.fake_credentials_filename)
177
178
def test_configure_set_with_profile_with_tab_dotted(self):
179
set_command = ConfigureSetCommand(self.session, self.config_writer)
180
set_command(args=['profile.some\tprofile.region', 'us-west-2'],
181
parsed_globals=None)
182
self.config_writer.update_config.assert_called_with(
183
{'__section__': "profile 'some\tprofile'", 'region': 'us-west-2'},
184
'myconfigfile')
185
186