Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/configservice/test_putconfigurationrecorder.py
1569 views
1
# Copyright 2015 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
from awscli.clidriver import create_clidriver
14
from awscli.arguments import CLIArgument
15
from awscli.testutils import unittest
16
from awscli.customizations.configservice.putconfigurationrecorder import \
17
extract_recording_group, ConfigurationRecorderArgument, \
18
RecordingGroupArgument
19
20
21
class TestPutConfigurationRecorder(unittest.TestCase):
22
def setUp(self):
23
self.clidriver = create_clidriver()
24
self.session = self.clidriver.session
25
self.argument_table = {}
26
self.service_model = self.session.get_service_model('config')
27
self.operation_model = self.service_model.operation_model(
28
'PutConfigurationRecorder')
29
configuration_recorder_model = self.operation_model.\
30
input_shape.members['ConfigurationRecorder']
31
self.old_configuration_recorder_argument = CLIArgument(
32
name='configuration-recorder',
33
argument_model=configuration_recorder_model,
34
operation_model=self.operation_model,
35
is_required=True,
36
event_emitter=self.session.get_component('event_emitter'),
37
serialized_name='ConfigurationRecorder'
38
)
39
self.argument_table['configuration-recorder'] = \
40
self.old_configuration_recorder_argument
41
42
def test_extract_recording_group(self):
43
extract_recording_group(self.session, self.argument_table)
44
self.assertEqual(len(self.argument_table), 2)
45
46
# Ensure the original argument was replaced with the updated argument.
47
self.assertIn('configuration-recorder', self.argument_table)
48
new_configuration_recorder_argument = self.argument_table[
49
'configuration-recorder']
50
self.assertIsNot(
51
new_configuration_recorder_argument,
52
self.old_configuration_recorder_argument
53
)
54
self.assertIsInstance(
55
new_configuration_recorder_argument,
56
ConfigurationRecorderArgument
57
)
58
59
# Ensure the recording group member was extracted to an argument
60
self.assertIn('recording-group', self.argument_table)
61
recording_group_argument = self.argument_table['recording-group']
62
self.assertIsInstance(
63
recording_group_argument,
64
RecordingGroupArgument
65
)
66
67
def test_configuration_recorder_when_new_value(self):
68
value = '{"name":"myname","roleARN":"myarn"}'
69
parameters = {}
70
extract_recording_group(self.session, self.argument_table)
71
configuration_recorder_argument = self.argument_table[
72
'configuration-recorder']
73
configuration_recorder_argument.add_to_params(parameters, value)
74
self.assertEqual(
75
{'ConfigurationRecorder': {
76
'name': 'myname',
77
'roleARN': 'myarn'}},
78
parameters)
79
80
def test_configuration_recorder_when_update_value(self):
81
value = '{"name":"myname","roleARN":"myarn"}'
82
parameters = {
83
'ConfigurationRecorder': {
84
'recordingGroup': {
85
'allSupported': True,
86
'resourceTypes': ['AWS::EC2::Volume']
87
}
88
}
89
}
90
extract_recording_group(self.session, self.argument_table)
91
configuration_recorder_argument = self.argument_table[
92
'configuration-recorder']
93
configuration_recorder_argument.add_to_params(parameters, value)
94
self.assertEqual(
95
{'ConfigurationRecorder': {
96
'name': 'myname',
97
'roleARN': 'myarn',
98
'recordingGroup': {
99
'allSupported': True,
100
'resourceTypes': ['AWS::EC2::Volume']}}},
101
parameters)
102
103
def test_recording_group_when_new_value(self):
104
value = '{"allSupported":true,"resourceTypes":["AWS::EC2::Volume"]}'
105
parameters = {}
106
extract_recording_group(self.session, self.argument_table)
107
recording_group_argument = self.argument_table['recording-group']
108
recording_group_argument.add_to_params(parameters, value)
109
self.assertEqual(
110
{'ConfigurationRecorder': {
111
'recordingGroup': {
112
'allSupported': True,
113
'resourceTypes': ['AWS::EC2::Volume']}}},
114
parameters)
115
116
def test_recording_group_when_update_value(self):
117
value = '{"allSupported":true,"resourceTypes":["AWS::EC2::Volume"]}'
118
parameters = {
119
'ConfigurationRecorder': {
120
'name': 'myname',
121
'roleARN': 'myarn',
122
}
123
}
124
extract_recording_group(self.session, self.argument_table)
125
recording_group_argument = self.argument_table['recording-group']
126
recording_group_argument.add_to_params(parameters, value)
127
self.assertEqual(
128
{'ConfigurationRecorder': {
129
'name': 'myname',
130
'roleARN': 'myarn',
131
'recordingGroup': {
132
'allSupported': True,
133
'resourceTypes': ['AWS::EC2::Volume']}}},
134
parameters)
135
136