def test_session_says_profile_does_not_exist(self): # Whenever you try to get a config value from botocore, # it will raise an exception complaining about ProfileNotFound. # We should handle this case, and write out a new profile section # in the config file. session = FakeSession({'config_file': 'myconfigfile'}, profile_does_not_exist=True) self.configure = configure.ConfigureCommand(session, prompter=self.precanned, config_writer=self.writer) self.global_args.profile = 'profile-does-not-exist' self.configure(args=[], parsed_globals=self.global_args) self.assert_credentials_file_updated_with({ 'aws_access_key_id': 'new_value', 'aws_secret_access_key': 'new_value', '__section__': 'profile-does-not-exist' }) self.writer.update_config.assert_called_with( { '__section__': 'profile profile-does-not-exist', 'region': 'new_value', 'output': 'new_value' }, 'myconfigfile')
def test_same_values_are_not_changed(self): # If the user enters the same value as the current value, we don't need # to write anything to the config. self.configure = configure.ConfigureCommand(self.session, prompter=EchoPrompter(), config_writer=self.writer) self.configure(args=[], parsed_globals=self.global_args) self.assertFalse(self.writer.update_config.called)
def setUp(self): self.writer = mock.Mock() self.global_args = mock.Mock() self.global_args.profile = None self.precanned = PrecannedPrompter(value='new_value') self.session = FakeSession({'config_file': 'myconfigfile'}) self.configure = configure.ConfigureCommand(self.session, prompter=self.precanned, config_writer=self.writer)
def test_none_values_are_not_changed(self): # If a user hits enter, this will result in a None value which means # don't change the existing values. In this case, we don't need # to write anything out to the config. user_presses_enter = None precanned = PrecannedPrompter(value=user_presses_enter) self.configure = configure.ConfigureCommand(self.session, prompter=precanned, config_writer=self.writer) self.configure(args=[], parsed_globals=self.global_args) self.assertFalse(self.writer.update_config.called)
def test_some_values_changed(self): # Test the case where the user only wants to change a single_value. responses = { "AWS Access Key ID": None, "AWS Secert Access Key": None, "Default region name": None, "Default output format": "NEW OUTPUT FORMAT", } prompter = KeyValuePrompter(responses) self.configure = configure.ConfigureCommand(self.session, prompter=prompter, config_writer=self.writer) self.configure(args=[], parsed_globals=self.global_args) # We only need to write out the default output format. self.writer.update_config.assert_called_with( {'output': 'NEW OUTPUT FORMAT'}, 'myconfigfile')
def test_create_configure_cmd_session_only(self): self.configure = configure.ConfigureCommand(self.session) self.assertIsInstance(self.configure, configure.ConfigureCommand)
def test_configure_command_has_arg_table(self): m = mock.Mock() command = configure.ConfigureCommand(m) self.assertEqual(command.arg_table, {})