Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/test_arguments.py
1566 views
1
# Copyright 2014 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.testutils import mock
14
from awscli.testutils import unittest
15
from awscli import arguments
16
from botocore.model import StringShape, OperationModel, ServiceModel
17
18
19
class DemoArgument(arguments.CustomArgument):
20
pass
21
22
23
class TestArgumentClasses(unittest.TestCase):
24
def test_can_set_required(self):
25
arg = DemoArgument('test-arg')
26
self.assertFalse(arg.required)
27
arg.required = True
28
self.assertTrue(arg.required)
29
30
31
class TestCLIArgument(unittest.TestCase):
32
def setUp(self):
33
self.service_name = 'baz'
34
self.service_model = ServiceModel({
35
'metadata': {
36
'endpointPrefix': 'bad',
37
},
38
'operations': {
39
'SampleOperation': {
40
'name': 'SampleOperation',
41
'input': {'shape': 'Input'}
42
}
43
},
44
'shapes': {
45
'StringShape': {'type': 'string'},
46
'Input': {
47
'type': 'structure',
48
'members': {
49
'Foo': {'shape': 'StringShape'}
50
}
51
}
52
}
53
}, self.service_name)
54
self.operation_model = self.service_model.operation_model(
55
'SampleOperation')
56
self.argument_model = self.operation_model.input_shape.members['Foo']
57
self.event_emitter = mock.Mock()
58
59
def create_argument(self):
60
return arguments.CLIArgument(
61
self.argument_model.name, self.argument_model,
62
self.operation_model, self.event_emitter)
63
64
def test_unpack_uses_service_name_in_event(self):
65
self.event_emitter.emit.return_value = ['value']
66
argument = self.create_argument()
67
params = {}
68
argument.add_to_params(params, 'value')
69
expected_event_name = 'process-cli-arg.%s.%s' % (
70
self.service_name, 'sample-operation')
71
actual_event_name = self.event_emitter.emit.call_args[0][0]
72
self.assertEqual(actual_event_name, expected_event_name)
73
74
75