| OLD | NEW |
| (Empty) | |
| 1 from tests.unit import unittest |
| 2 from tests.unit import AWSMockServiceTestCase |
| 3 |
| 4 from boto.cloudfront import CloudFrontConnection |
| 5 from boto.cloudfront.distribution import Distribution, DistributionConfig, Distr
ibutionSummary |
| 6 from boto.cloudfront.origin import CustomOrigin |
| 7 |
| 8 |
| 9 class TestCloudFrontConnection(AWSMockServiceTestCase): |
| 10 connection_class = CloudFrontConnection |
| 11 |
| 12 def setUp(self): |
| 13 super(TestCloudFrontConnection, self).setUp() |
| 14 |
| 15 def test_get_all_distributions(self): |
| 16 body = """ |
| 17 <DistributionList xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/
"> |
| 18 <Marker></Marker> |
| 19 <MaxItems>100</MaxItems> |
| 20 <IsTruncated>false</IsTruncated> |
| 21 <DistributionSummary> |
| 22 <Id>EEEEEEEEEEEEE</Id> |
| 23 <Status>InProgress</Status> |
| 24 <LastModifiedTime>2014-02-03T11:03:41.087Z</LastModifiedTime> |
| 25 <DomainName>abcdef12345678.cloudfront.net</DomainName> |
| 26 <CustomOrigin> |
| 27 <DNSName>example.com</DNSName> |
| 28 <HTTPPort>80</HTTPPort> |
| 29 <HTTPSPort>443</HTTPSPort> |
| 30 <OriginProtocolPolicy>http-only</OriginProtocolPolicy> |
| 31 </CustomOrigin> |
| 32 <CNAME>static.example.com</CNAME> |
| 33 <Enabled>true</Enabled> |
| 34 </DistributionSummary> |
| 35 </DistributionList> |
| 36 """ |
| 37 self.set_http_response(status_code=200, body=body) |
| 38 response = self.service_connection.get_all_distributions() |
| 39 |
| 40 self.assertTrue(isinstance(response, list)) |
| 41 self.assertEqual(len(response), 1) |
| 42 self.assertTrue(isinstance(response[0], DistributionSummary)) |
| 43 self.assertEqual(response[0].id, "EEEEEEEEEEEEE") |
| 44 self.assertEqual(response[0].domain_name, "abcdef12345678.cloudfront.net
") |
| 45 self.assertEqual(response[0].status, "InProgress") |
| 46 self.assertEqual(response[0].cnames, ["static.example.com"]) |
| 47 self.assertEqual(response[0].enabled, True) |
| 48 self.assertTrue(isinstance(response[0].origin, CustomOrigin)) |
| 49 self.assertEqual(response[0].origin.dns_name, "example.com") |
| 50 self.assertEqual(response[0].origin.http_port, 80) |
| 51 self.assertEqual(response[0].origin.https_port, 443) |
| 52 self.assertEqual(response[0].origin.origin_protocol_policy, 'http-only') |
| 53 |
| 54 def test_get_distribution_config(self): |
| 55 body = """ |
| 56 <DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-0
1/"> |
| 57 <CustomOrigin> |
| 58 <DNSName>example.com</DNSName> |
| 59 <HTTPPort>80</HTTPPort> |
| 60 <HTTPSPort>443</HTTPSPort> |
| 61 <OriginProtocolPolicy>http-only</OriginProtocolPolicy> |
| 62 </CustomOrigin> |
| 63 <CallerReference>1234567890123</CallerReference> |
| 64 <CNAME>static.example.com</CNAME> |
| 65 <Enabled>true</Enabled> |
| 66 </DistributionConfig> |
| 67 """ |
| 68 |
| 69 self.set_http_response(status_code=200, body=body, header={"Etag": "AABB
CC"}) |
| 70 response = self.service_connection.get_distribution_config('EEEEEEEEEEEE
E') |
| 71 |
| 72 self.assertTrue(isinstance(response, DistributionConfig)) |
| 73 self.assertTrue(isinstance(response.origin, CustomOrigin)) |
| 74 self.assertEqual(response.origin.dns_name, "example.com") |
| 75 self.assertEqual(response.origin.http_port, 80) |
| 76 self.assertEqual(response.origin.https_port, 443) |
| 77 self.assertEqual(response.origin.origin_protocol_policy, "http-only") |
| 78 self.assertEqual(response.cnames, ["static.example.com"]) |
| 79 self.assertTrue(response.enabled) |
| 80 self.assertEqual(response.etag, "AABBCC") |
| 81 |
| 82 def test_set_distribution_config(self): |
| 83 get_body = """ |
| 84 <DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-0
1/"> |
| 85 <CustomOrigin> |
| 86 <DNSName>example.com</DNSName> |
| 87 <HTTPPort>80</HTTPPort> |
| 88 <HTTPSPort>443</HTTPSPort> |
| 89 <OriginProtocolPolicy>http-only</OriginProtocolPolicy> |
| 90 </CustomOrigin> |
| 91 <CallerReference>1234567890123</CallerReference> |
| 92 <CNAME>static.example.com</CNAME> |
| 93 <Enabled>true</Enabled> |
| 94 </DistributionConfig> |
| 95 """ |
| 96 |
| 97 put_body = """ |
| 98 <Distribution xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"> |
| 99 <Id>EEEEEE</Id> |
| 100 <Status>InProgress</Status> |
| 101 <LastModifiedTime>2014-02-04T10:47:53.493Z</LastModifiedTime> |
| 102 <InProgressInvalidationBatches>0</InProgressInvalidationBatches> |
| 103 <DomainName>d2000000000000.cloudfront.net</DomainName> |
| 104 <DistributionConfig> |
| 105 <CustomOrigin> |
| 106 <DNSName>example.com</DNSName> |
| 107 <HTTPPort>80</HTTPPort> |
| 108 <HTTPSPort>443</HTTPSPort> |
| 109 <OriginProtocolPolicy>match-viewer</OriginProtocolPolicy> |
| 110 </CustomOrigin> |
| 111 <CallerReference>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</CallerRef
erence> |
| 112 <Comment>this is a comment</Comment> |
| 113 <Enabled>false</Enabled> |
| 114 </DistributionConfig> |
| 115 </Distribution> |
| 116 """ |
| 117 |
| 118 self.set_http_response(status_code=200, body=get_body, header={"Etag": "
AA"}) |
| 119 conf = self.service_connection.get_distribution_config('EEEEEEE') |
| 120 |
| 121 self.set_http_response(status_code=200, body=put_body, header={"Etag": "
AABBCCD"}) |
| 122 conf.comment = 'this is a comment' |
| 123 response = self.service_connection.set_distribution_config('EEEEEEE', co
nf.etag, conf) |
| 124 |
| 125 self.assertEqual(response, "AABBCCD") |
| 126 |
| 127 def test_get_distribution_info(self): |
| 128 body = """ |
| 129 <Distribution xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"> |
| 130 <Id>EEEEEEEEEEEEE</Id> |
| 131 <Status>InProgress</Status> |
| 132 <LastModifiedTime>2014-02-03T11:03:41.087Z</LastModifiedTime> |
| 133 <InProgressInvalidationBatches>0</InProgressInvalidationBatches> |
| 134 <DomainName>abcdef12345678.cloudfront.net</DomainName> |
| 135 <DistributionConfig> |
| 136 <CustomOrigin> |
| 137 <DNSName>example.com</DNSName> |
| 138 <HTTPPort>80</HTTPPort> |
| 139 <HTTPSPort>443</HTTPSPort> |
| 140 <OriginProtocolPolicy>http-only</OriginProtocolPolicy> |
| 141 </CustomOrigin> |
| 142 <CallerReference>1111111111111</CallerReference> |
| 143 <CNAME>static.example.com</CNAME> |
| 144 <Enabled>true</Enabled> |
| 145 </DistributionConfig> |
| 146 </Distribution> |
| 147 """ |
| 148 |
| 149 self.set_http_response(status_code=200, body=body) |
| 150 response = self.service_connection.get_distribution_info('EEEEEEEEEEEEE'
) |
| 151 |
| 152 self.assertTrue(isinstance(response, Distribution)) |
| 153 self.assertTrue(isinstance(response.config, DistributionConfig)) |
| 154 self.assertTrue(isinstance(response.config.origin, CustomOrigin)) |
| 155 self.assertEqual(response.config.origin.dns_name, "example.com") |
| 156 self.assertEqual(response.config.origin.http_port, 80) |
| 157 self.assertEqual(response.config.origin.https_port, 443) |
| 158 self.assertEqual(response.config.origin.origin_protocol_policy, "http-on
ly") |
| 159 self.assertEqual(response.config.cnames, ["static.example.com"]) |
| 160 self.assertTrue(response.config.enabled) |
| 161 self.assertEqual(response.id, "EEEEEEEEEEEEE") |
| 162 self.assertEqual(response.status, "InProgress") |
| 163 self.assertEqual(response.domain_name, "abcdef12345678.cloudfront.net") |
| 164 self.assertEqual(response.in_progress_invalidation_batches, 0) |
| 165 |
| 166 def test_create_distribution(self): |
| 167 body = """ |
| 168 <Distribution xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"> |
| 169 <Id>EEEEEEEEEEEEEE</Id> |
| 170 <Status>InProgress</Status> |
| 171 <LastModifiedTime>2014-02-04T10:34:07.873Z</LastModifiedTime> |
| 172 <InProgressInvalidationBatches>0</InProgressInvalidationBatches> |
| 173 <DomainName>d2000000000000.cloudfront.net</DomainName> |
| 174 <DistributionConfig> |
| 175 <CustomOrigin> |
| 176 <DNSName>example.com</DNSName> |
| 177 <HTTPPort>80</HTTPPort> |
| 178 <HTTPSPort>443</HTTPSPort> |
| 179 <OriginProtocolPolicy>match-viewer</OriginProtocolPolicy> |
| 180 </CustomOrigin> |
| 181 <CallerReference>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</CallerRef
erence> |
| 182 <Comment>example.com distribution</Comment> |
| 183 <Enabled>false</Enabled> |
| 184 </DistributionConfig> |
| 185 </Distribution> |
| 186 """ |
| 187 |
| 188 self.set_http_response(status_code=201, body=body) |
| 189 origin = CustomOrigin("example.com", origin_protocol_policy="match_viewe
r") |
| 190 response = self.service_connection.create_distribution(origin, enabled=F
alse, comment="example.com distribution") |
| 191 |
| 192 self.assertTrue(isinstance(response, Distribution)) |
| 193 self.assertTrue(isinstance(response.config, DistributionConfig)) |
| 194 self.assertTrue(isinstance(response.config.origin, CustomOrigin)) |
| 195 self.assertEqual(response.config.origin.dns_name, "example.com") |
| 196 self.assertEqual(response.config.origin.http_port, 80) |
| 197 self.assertEqual(response.config.origin.https_port, 443) |
| 198 self.assertEqual(response.config.origin.origin_protocol_policy, "match-v
iewer") |
| 199 self.assertEqual(response.config.cnames, []) |
| 200 self.assertTrue(not response.config.enabled) |
| 201 self.assertEqual(response.id, "EEEEEEEEEEEEEE") |
| 202 self.assertEqual(response.status, "InProgress") |
| 203 self.assertEqual(response.domain_name, "d2000000000000.cloudfront.net") |
| 204 self.assertEqual(response.in_progress_invalidation_batches, 0) |
| OLD | NEW |