Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/cloudfront/test_update_distribution.py
1567 views
1
# Copyright 2016 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 BaseAWSPreviewCommandParamsTest as \
15
BaseAWSCommandParamsTest
16
17
18
class TestUpdateDistribution(BaseAWSCommandParamsTest):
19
20
prefix = 'cloudfront update-distribution --id myid '
21
22
def test_default_root_object(self):
23
cmdline = self.prefix + '--default-root-object index.html'
24
self.parsed_response = {
25
# A get-distribution-config response, contains a minimal config
26
'ETag': '__etag__',
27
'DistributionConfig': {
28
'Origins': {
29
'Quantity': 1,
30
'Items': [{'Id': 'foo', 'DomainName': 'bar'}]
31
},
32
'CallerReference': 'abcd',
33
'Comment': '',
34
'Enabled': True,
35
'DefaultCacheBehavior': {
36
'TargetOriginId': 'foo',
37
'ForwardedValues': {
38
'QueryString': True, 'Cookies': {'Forward': 'none'}},
39
'TrustedSigners': {'Enabled': True, 'Quantity': 0},
40
'ViewerProtocolPolicy': 'allow-all',
41
'MinTTL': 0,
42
},
43
},
44
}
45
result = {
46
'DistributionConfig': {
47
'DefaultRootObject': 'index.html',
48
'Origins': {
49
'Quantity': 1,
50
'Items': [{'Id': 'foo', 'DomainName': 'bar'}]
51
},
52
'CallerReference': 'abcd',
53
'Comment': '',
54
'Enabled': True,
55
'DefaultCacheBehavior': mock.ANY,
56
},
57
'Id': 'myid',
58
'IfMatch': '__etag__',
59
}
60
self.run_cmd(cmdline)
61
self.assertEqual(self.last_kwargs, result)
62
63
def test_distribution_config(self):
64
# To demonstrate the original --distribution-config still works
65
cmdline = self.prefix + ('--distribution-config '
66
'Origins={Quantity=1,Items=[{Id=foo,DomainName=bar}]},'
67
'DefaultCacheBehavior={'
68
'TargetOriginId=foo,'
69
'ForwardedValues={QueryString=False,Cookies={Forward=none}},'
70
'TrustedSigners={Enabled=True,Quantity=0},'
71
'ViewerProtocolPolicy=allow-all,'
72
'MinTTL=0'
73
'},'
74
'CallerReference=abcd,'
75
'Enabled=True,'
76
'Comment='
77
)
78
result = {
79
'DistributionConfig': {
80
'Origins': {
81
'Quantity': 1,
82
'Items': [{'Id': 'foo', 'DomainName': 'bar'}]
83
},
84
'CallerReference': 'abcd',
85
'Comment': '',
86
'Enabled': True,
87
'DefaultCacheBehavior': mock.ANY,
88
},
89
'Id': 'myid',
90
}
91
self.run_cmd(cmdline)
92
self.assertEqual(self.last_kwargs, result)
93
94
def test_both_distribution_config_and_default_root_object(self):
95
self.assert_params_for_cmd(
96
self.prefix + '--distribution-config {} --default-root-object foo',
97
expected_rc=255,
98
stderr_contains='cannot be specified when one of the following')
99
100
def test_no_input(self):
101
self.run_cmd(self.prefix, expected_rc=255)
102
103