Path: blob/develop/tests/functional/cloudfront/test_create_distribution.py
1567 views
# Copyright 2016 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.testutils import mock13from awscli.testutils import BaseAWSPreviewCommandParamsTest as \14BaseAWSCommandParamsTest151617class TestCreateDistribution(BaseAWSCommandParamsTest):1819prefix = 'cloudfront create-distribution '2021def test_origin_domain_name_with_custom_domain(self):22cmdline = self.prefix + '--origin-domain-name foo.com'23result = {24'DistributionConfig': {25'Origins': {26'Quantity': 1,27'Items': [{28'CustomOriginConfig': mock.ANY,29'DomainName': 'foo.com',30'Id': mock.ANY,31'OriginPath': '',32}]33},34'CallerReference': mock.ANY,35'Comment': '',36'Enabled': True,37'DefaultCacheBehavior': mock.ANY,38},39}40self.run_cmd(cmdline)41self.assertEqual(self.last_kwargs, result)4243def test_origin_domain_name_with_s3_domain(self):44cmdline = self.prefix + '--origin-domain-name foo.s3.amazonaws.com'45result = {46'DistributionConfig': {47'Origins': {48'Quantity': 1,49'Items': [{50'S3OriginConfig': mock.ANY,51'DomainName': 'foo.s3.amazonaws.com',52'Id': mock.ANY,53'OriginPath': '',54}]55},56'CallerReference': mock.ANY,57'Comment': '',58'Enabled': True,59'DefaultCacheBehavior': mock.ANY,60},61}62self.run_cmd(cmdline)63self.assertEqual(self.last_kwargs, result)6465def test_s3_domain_with_default_root_object(self):66cmdline = (self.prefix + '--origin-domain-name foo.s3.amazonaws.com '67+ '--default-root-object index.html')68result = {69'DistributionConfig': {70'Origins': {71'Quantity': 1,72'Items': [{73'S3OriginConfig': mock.ANY,74'DomainName': 'foo.s3.amazonaws.com',75'Id': mock.ANY,76'OriginPath': '',77}]78},79'CallerReference': mock.ANY,80'Comment': '',81'Enabled': True,82'DefaultCacheBehavior': mock.ANY,83'DefaultRootObject': 'index.html',84},85}86self.run_cmd(cmdline)87self.assertEqual(self.last_kwargs, result)8889def test_distribution_config(self):90# To demonstrate the original --distribution-config still works91cmdline = self.prefix + ('--distribution-config '92'Origins={Quantity=1,Items=[{Id=foo,DomainName=bar}]},'93'DefaultCacheBehavior={'94'TargetOriginId=foo,'95'ForwardedValues={QueryString=False,Cookies={Forward=none}},'96'TrustedSigners={Enabled=True,Quantity=0},'97'ViewerProtocolPolicy=allow-all,'98'MinTTL=0'99'},'100'CallerReference=abcd,'101'Enabled=True,'102'Comment='103)104result = {105'DistributionConfig': {106'Origins': {107'Quantity': 1,108'Items': [{'Id': 'foo', 'DomainName': 'bar'}]109},110'CallerReference': 'abcd',111'Comment': '',112'Enabled': True,113'DefaultCacheBehavior': mock.ANY,114},115}116self.run_cmd(cmdline)117self.assertEqual(self.last_kwargs, result)118119def test_both_distribution_config_and_origin_domain_name(self):120self.assert_params_for_cmd(121self.prefix + '--distribution-config {} --origin-domain-name a.us',122expected_rc=255,123stderr_contains='cannot be specified when one of the following')124125def test_no_input(self):126self.run_cmd(self.prefix, expected_rc=255)127128129