Path: blob/develop/tests/unit/customizations/configure/test_set.py
1569 views
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12import os1314from awscli.customizations.configure.set import ConfigureSetCommand15from awscli.testutils import mock, unittest16from . import FakeSession171819class TestConfigureSetCommand(unittest.TestCase):2021def setUp(self):22self.session = FakeSession({'config_file': 'myconfigfile'})23self.fake_credentials_filename = os.path.expanduser(24'~/fake_credentials_filename')25self.session.profile = None26self.config_writer = mock.Mock()2728def test_configure_set_command(self):29set_command = ConfigureSetCommand(30self.session, self.config_writer)31set_command(args=['region', 'us-west-2'], parsed_globals=None)32self.config_writer.update_config.assert_called_with(33{'__section__': 'default', 'region': 'us-west-2'}, 'myconfigfile')3435def test_configure_set_command_dotted(self):36set_command = ConfigureSetCommand(37self.session, self.config_writer)38set_command(args=['preview.emr', 'true'], parsed_globals=None)39self.config_writer.update_config.assert_called_with(40{'__section__': 'preview', 'emr': 'true'}, 'myconfigfile')4142def test_configure_set_command_dotted_with_default_profile(self):43self.session.variables['profile'] = 'default'44set_command = ConfigureSetCommand(45self.session, self.config_writer)46set_command(47args=['emr.instance_profile', 'my_ip_emr'], parsed_globals=None)48self.config_writer.update_config.assert_called_with(49{'__section__': 'default',50'emr': {'instance_profile': 'my_ip_emr'}}, 'myconfigfile')5152def test_configure_set_handles_predefined_plugins_section(self):53self.session.variables['profile'] = 'default'54set_command = ConfigureSetCommand(55self.session, self.config_writer)56set_command(57args=['plugins.foo', 'mypackage'], parsed_globals=None)58self.config_writer.update_config.assert_called_with(59{'__section__': 'plugins',60'foo': 'mypackage'}, 'myconfigfile')6162def test_configure_set_command_dotted_with_profile(self):63self.session.profile = 'emr-dev'64set_command = ConfigureSetCommand(65self.session, self.config_writer)66set_command(67args=['emr.instance_profile', 'my_ip_emr'], parsed_globals=None)68self.config_writer.update_config.assert_called_with(69{'__section__': 'profile emr-dev', 'emr':70{'instance_profile': 'my_ip_emr'}}, 'myconfigfile')7172def test_configure_set_with_profile(self):73self.session.profile = 'testing'74set_command = ConfigureSetCommand(75self.session, self.config_writer)76set_command(args=['region', 'us-west-2'], parsed_globals=None)77self.config_writer.update_config.assert_called_with(78{'__section__': 'profile testing', 'region': 'us-west-2'},79'myconfigfile')8081def test_configure_set_triple_dotted(self):82# aws configure set default.s3.signature_version s3v483set_command = ConfigureSetCommand(84self.session, self.config_writer)85set_command(args=['default.s3.signature_version', 's3v4'],86parsed_globals=None)87self.config_writer.update_config.assert_called_with(88{'__section__': 'default', 's3': {'signature_version': 's3v4'}},89'myconfigfile')9091def test_configure_set_with_profile_nested(self):92# aws configure set default.s3.signature_version s3v493set_command = ConfigureSetCommand(94self.session, self.config_writer)95set_command(args=['profile.foo.s3.signature_version', 's3v4'],96parsed_globals=None)97self.config_writer.update_config.assert_called_with(98{'__section__': 'profile foo',99's3': {'signature_version': 's3v4'}}, 'myconfigfile')100101def test_access_key_written_to_shared_credentials_file(self):102set_command = ConfigureSetCommand(103self.session, self.config_writer)104set_command(args=['aws_access_key_id', 'foo'],105parsed_globals=None)106self.config_writer.update_config.assert_called_with(107{'__section__': 'default',108'aws_access_key_id': 'foo'}, self.fake_credentials_filename)109110def test_secret_key_written_to_shared_credentials_file(self):111set_command = ConfigureSetCommand(112self.session, self.config_writer)113set_command(args=['aws_secret_access_key', 'foo'],114parsed_globals=None)115self.config_writer.update_config.assert_called_with(116{'__section__': 'default',117'aws_secret_access_key': 'foo'}, self.fake_credentials_filename)118119def test_session_token_written_to_shared_credentials_file(self):120set_command = ConfigureSetCommand(121self.session, self.config_writer)122set_command(args=['aws_session_token', 'foo'],123parsed_globals=None)124self.config_writer.update_config.assert_called_with(125{'__section__': 'default',126'aws_session_token': 'foo'}, self.fake_credentials_filename)127128def test_access_key_written_to_shared_credentials_file_profile(self):129set_command = ConfigureSetCommand(130self.session, self.config_writer)131set_command(args=['profile.foo.aws_access_key_id', 'bar'],132parsed_globals=None)133self.config_writer.update_config.assert_called_with(134{'__section__': 'foo',135'aws_access_key_id': 'bar'}, self.fake_credentials_filename)136137def test_credential_set_profile_with_space(self):138self.session.profile = 'some profile'139set_command = ConfigureSetCommand(self.session, self.config_writer)140set_command(args=['aws_session_token', 'foo'], parsed_globals=None)141self.config_writer.update_config.assert_called_with(142{'__section__': 'some profile',143'aws_session_token': 'foo'}, self.fake_credentials_filename)144145def test_credential_set_profile_with_space_dotted(self):146set_command = ConfigureSetCommand(self.session, self.config_writer)147set_command(args=['profile.some profile.aws_session_token', 'foo'],148parsed_globals=None)149self.config_writer.update_config.assert_called_with(150{'__section__': 'some profile',151'aws_session_token': 'foo'}, self.fake_credentials_filename)152153def test_configure_set_with_profile_with_space(self):154self.session.profile = 'some profile'155set_command = ConfigureSetCommand(self.session, self.config_writer)156set_command(args=['region', 'us-west-2'], parsed_globals=None)157self.config_writer.update_config.assert_called_with(158{'__section__': "profile 'some profile'", 'region': 'us-west-2'},159'myconfigfile')160161def test_configure_set_with_profile_with_space_dotted(self):162set_command = ConfigureSetCommand(self.session, self.config_writer)163set_command(args=['profile.some profile.region', 'us-west-2'],164parsed_globals=None)165self.config_writer.update_config.assert_called_with(166{'__section__': "profile 'some profile'", 'region': 'us-west-2'},167'myconfigfile')168169def test_credential_set_profile_with_tab(self):170self.session.profile = 'some\tprofile'171set_command = ConfigureSetCommand(self.session, self.config_writer)172set_command(args=['aws_session_token', 'foo'], parsed_globals=None)173self.config_writer.update_config.assert_called_with(174{'__section__': 'some\tprofile',175'aws_session_token': 'foo'}, self.fake_credentials_filename)176177def test_configure_set_with_profile_with_tab_dotted(self):178set_command = ConfigureSetCommand(self.session, self.config_writer)179set_command(args=['profile.some\tprofile.region', 'us-west-2'],180parsed_globals=None)181self.config_writer.update_config.assert_called_with(182{'__section__': "profile 'some\tprofile'", 'region': 'us-west-2'},183'myconfigfile')184185186