Path: blob/develop/tests/functional/cloudfront/test_update_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 TestUpdateDistribution(BaseAWSCommandParamsTest):1819prefix = 'cloudfront update-distribution --id myid '2021def test_default_root_object(self):22cmdline = self.prefix + '--default-root-object index.html'23self.parsed_response = {24# A get-distribution-config response, contains a minimal config25'ETag': '__etag__',26'DistributionConfig': {27'Origins': {28'Quantity': 1,29'Items': [{'Id': 'foo', 'DomainName': 'bar'}]30},31'CallerReference': 'abcd',32'Comment': '',33'Enabled': True,34'DefaultCacheBehavior': {35'TargetOriginId': 'foo',36'ForwardedValues': {37'QueryString': True, 'Cookies': {'Forward': 'none'}},38'TrustedSigners': {'Enabled': True, 'Quantity': 0},39'ViewerProtocolPolicy': 'allow-all',40'MinTTL': 0,41},42},43}44result = {45'DistributionConfig': {46'DefaultRootObject': 'index.html',47'Origins': {48'Quantity': 1,49'Items': [{'Id': 'foo', 'DomainName': 'bar'}]50},51'CallerReference': 'abcd',52'Comment': '',53'Enabled': True,54'DefaultCacheBehavior': mock.ANY,55},56'Id': 'myid',57'IfMatch': '__etag__',58}59self.run_cmd(cmdline)60self.assertEqual(self.last_kwargs, result)6162def test_distribution_config(self):63# To demonstrate the original --distribution-config still works64cmdline = self.prefix + ('--distribution-config '65'Origins={Quantity=1,Items=[{Id=foo,DomainName=bar}]},'66'DefaultCacheBehavior={'67'TargetOriginId=foo,'68'ForwardedValues={QueryString=False,Cookies={Forward=none}},'69'TrustedSigners={Enabled=True,Quantity=0},'70'ViewerProtocolPolicy=allow-all,'71'MinTTL=0'72'},'73'CallerReference=abcd,'74'Enabled=True,'75'Comment='76)77result = {78'DistributionConfig': {79'Origins': {80'Quantity': 1,81'Items': [{'Id': 'foo', 'DomainName': 'bar'}]82},83'CallerReference': 'abcd',84'Comment': '',85'Enabled': True,86'DefaultCacheBehavior': mock.ANY,87},88'Id': 'myid',89}90self.run_cmd(cmdline)91self.assertEqual(self.last_kwargs, result)9293def test_both_distribution_config_and_default_root_object(self):94self.assert_params_for_cmd(95self.prefix + '--distribution-config {} --default-root-object foo',96expected_rc=255,97stderr_contains='cannot be specified when one of the following')9899def test_no_input(self):100self.run_cmd(self.prefix, expected_rc=255)101102103