Path: blob/develop/tests/unit/customizations/configservice/test_putconfigurationrecorder.py
1569 views
# Copyright 2015 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.12from awscli.clidriver import create_clidriver13from awscli.arguments import CLIArgument14from awscli.testutils import unittest15from awscli.customizations.configservice.putconfigurationrecorder import \16extract_recording_group, ConfigurationRecorderArgument, \17RecordingGroupArgument181920class TestPutConfigurationRecorder(unittest.TestCase):21def setUp(self):22self.clidriver = create_clidriver()23self.session = self.clidriver.session24self.argument_table = {}25self.service_model = self.session.get_service_model('config')26self.operation_model = self.service_model.operation_model(27'PutConfigurationRecorder')28configuration_recorder_model = self.operation_model.\29input_shape.members['ConfigurationRecorder']30self.old_configuration_recorder_argument = CLIArgument(31name='configuration-recorder',32argument_model=configuration_recorder_model,33operation_model=self.operation_model,34is_required=True,35event_emitter=self.session.get_component('event_emitter'),36serialized_name='ConfigurationRecorder'37)38self.argument_table['configuration-recorder'] = \39self.old_configuration_recorder_argument4041def test_extract_recording_group(self):42extract_recording_group(self.session, self.argument_table)43self.assertEqual(len(self.argument_table), 2)4445# Ensure the original argument was replaced with the updated argument.46self.assertIn('configuration-recorder', self.argument_table)47new_configuration_recorder_argument = self.argument_table[48'configuration-recorder']49self.assertIsNot(50new_configuration_recorder_argument,51self.old_configuration_recorder_argument52)53self.assertIsInstance(54new_configuration_recorder_argument,55ConfigurationRecorderArgument56)5758# Ensure the recording group member was extracted to an argument59self.assertIn('recording-group', self.argument_table)60recording_group_argument = self.argument_table['recording-group']61self.assertIsInstance(62recording_group_argument,63RecordingGroupArgument64)6566def test_configuration_recorder_when_new_value(self):67value = '{"name":"myname","roleARN":"myarn"}'68parameters = {}69extract_recording_group(self.session, self.argument_table)70configuration_recorder_argument = self.argument_table[71'configuration-recorder']72configuration_recorder_argument.add_to_params(parameters, value)73self.assertEqual(74{'ConfigurationRecorder': {75'name': 'myname',76'roleARN': 'myarn'}},77parameters)7879def test_configuration_recorder_when_update_value(self):80value = '{"name":"myname","roleARN":"myarn"}'81parameters = {82'ConfigurationRecorder': {83'recordingGroup': {84'allSupported': True,85'resourceTypes': ['AWS::EC2::Volume']86}87}88}89extract_recording_group(self.session, self.argument_table)90configuration_recorder_argument = self.argument_table[91'configuration-recorder']92configuration_recorder_argument.add_to_params(parameters, value)93self.assertEqual(94{'ConfigurationRecorder': {95'name': 'myname',96'roleARN': 'myarn',97'recordingGroup': {98'allSupported': True,99'resourceTypes': ['AWS::EC2::Volume']}}},100parameters)101102def test_recording_group_when_new_value(self):103value = '{"allSupported":true,"resourceTypes":["AWS::EC2::Volume"]}'104parameters = {}105extract_recording_group(self.session, self.argument_table)106recording_group_argument = self.argument_table['recording-group']107recording_group_argument.add_to_params(parameters, value)108self.assertEqual(109{'ConfigurationRecorder': {110'recordingGroup': {111'allSupported': True,112'resourceTypes': ['AWS::EC2::Volume']}}},113parameters)114115def test_recording_group_when_update_value(self):116value = '{"allSupported":true,"resourceTypes":["AWS::EC2::Volume"]}'117parameters = {118'ConfigurationRecorder': {119'name': 'myname',120'roleARN': 'myarn',121}122}123extract_recording_group(self.session, self.argument_table)124recording_group_argument = self.argument_table['recording-group']125recording_group_argument.add_to_params(parameters, value)126self.assertEqual(127{'ConfigurationRecorder': {128'name': 'myname',129'roleARN': 'myarn',130'recordingGroup': {131'allSupported': True,132'resourceTypes': ['AWS::EC2::Volume']}}},133parameters)134135136