Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/cloudfront/test_create_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 TestCreateDistribution(BaseAWSCommandParamsTest):
19
20
prefix = 'cloudfront create-distribution '
21
22
def test_origin_domain_name_with_custom_domain(self):
23
cmdline = self.prefix + '--origin-domain-name foo.com'
24
result = {
25
'DistributionConfig': {
26
'Origins': {
27
'Quantity': 1,
28
'Items': [{
29
'CustomOriginConfig': mock.ANY,
30
'DomainName': 'foo.com',
31
'Id': mock.ANY,
32
'OriginPath': '',
33
}]
34
},
35
'CallerReference': mock.ANY,
36
'Comment': '',
37
'Enabled': True,
38
'DefaultCacheBehavior': mock.ANY,
39
},
40
}
41
self.run_cmd(cmdline)
42
self.assertEqual(self.last_kwargs, result)
43
44
def test_origin_domain_name_with_s3_domain(self):
45
cmdline = self.prefix + '--origin-domain-name foo.s3.amazonaws.com'
46
result = {
47
'DistributionConfig': {
48
'Origins': {
49
'Quantity': 1,
50
'Items': [{
51
'S3OriginConfig': mock.ANY,
52
'DomainName': 'foo.s3.amazonaws.com',
53
'Id': mock.ANY,
54
'OriginPath': '',
55
}]
56
},
57
'CallerReference': mock.ANY,
58
'Comment': '',
59
'Enabled': True,
60
'DefaultCacheBehavior': mock.ANY,
61
},
62
}
63
self.run_cmd(cmdline)
64
self.assertEqual(self.last_kwargs, result)
65
66
def test_s3_domain_with_default_root_object(self):
67
cmdline = (self.prefix + '--origin-domain-name foo.s3.amazonaws.com '
68
+ '--default-root-object index.html')
69
result = {
70
'DistributionConfig': {
71
'Origins': {
72
'Quantity': 1,
73
'Items': [{
74
'S3OriginConfig': mock.ANY,
75
'DomainName': 'foo.s3.amazonaws.com',
76
'Id': mock.ANY,
77
'OriginPath': '',
78
}]
79
},
80
'CallerReference': mock.ANY,
81
'Comment': '',
82
'Enabled': True,
83
'DefaultCacheBehavior': mock.ANY,
84
'DefaultRootObject': 'index.html',
85
},
86
}
87
self.run_cmd(cmdline)
88
self.assertEqual(self.last_kwargs, result)
89
90
def test_distribution_config(self):
91
# To demonstrate the original --distribution-config still works
92
cmdline = self.prefix + ('--distribution-config '
93
'Origins={Quantity=1,Items=[{Id=foo,DomainName=bar}]},'
94
'DefaultCacheBehavior={'
95
'TargetOriginId=foo,'
96
'ForwardedValues={QueryString=False,Cookies={Forward=none}},'
97
'TrustedSigners={Enabled=True,Quantity=0},'
98
'ViewerProtocolPolicy=allow-all,'
99
'MinTTL=0'
100
'},'
101
'CallerReference=abcd,'
102
'Enabled=True,'
103
'Comment='
104
)
105
result = {
106
'DistributionConfig': {
107
'Origins': {
108
'Quantity': 1,
109
'Items': [{'Id': 'foo', 'DomainName': 'bar'}]
110
},
111
'CallerReference': 'abcd',
112
'Comment': '',
113
'Enabled': True,
114
'DefaultCacheBehavior': mock.ANY,
115
},
116
}
117
self.run_cmd(cmdline)
118
self.assertEqual(self.last_kwargs, result)
119
120
def test_both_distribution_config_and_origin_domain_name(self):
121
self.assert_params_for_cmd(
122
self.prefix + '--distribution-config {} --origin-domain-name a.us',
123
expected_rc=255,
124
stderr_contains='cannot be specified when one of the following')
125
126
def test_no_input(self):
127
self.run_cmd(self.prefix, expected_rc=255)
128
129