| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 from mock import patch | 2 from mock import patch |
| 3 import xml.dom.minidom |
| 3 | 4 |
| 4 from tests.unit import unittest | 5 from tests.unit import unittest |
| 5 from tests.unit import AWSMockServiceTestCase | 6 from tests.unit import AWSMockServiceTestCase |
| 6 | 7 |
| 8 from boto.exception import BotoClientError |
| 7 from boto.s3.connection import S3Connection | 9 from boto.s3.connection import S3Connection |
| 8 from boto.s3.bucket import Bucket | 10 from boto.s3.bucket import Bucket |
| 9 from boto.s3.deletemarker import DeleteMarker | 11 from boto.s3.deletemarker import DeleteMarker |
| 10 from boto.s3.key import Key | 12 from boto.s3.key import Key |
| 11 from boto.s3.multipart import MultiPartUpload | 13 from boto.s3.multipart import MultiPartUpload |
| 12 from boto.s3.prefix import Prefix | 14 from boto.s3.prefix import Prefix |
| 13 | 15 |
| 14 | 16 |
| 15 class TestS3Bucket(AWSMockServiceTestCase): | 17 class TestS3Bucket(AWSMockServiceTestCase): |
| 16 connection_class = S3Connection | 18 connection_class = S3Connection |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 'bar=%E2%98%83&max-keys=0&foo=true&some-other=thing' | 107 'bar=%E2%98%83&max-keys=0&foo=true&some-other=thing' |
| 106 ) | 108 ) |
| 107 | 109 |
| 108 # Multiple params with initial. | 110 # Multiple params with initial. |
| 109 qa = bukket._get_all_query_args(multiple_params, 'initial=1') | 111 qa = bukket._get_all_query_args(multiple_params, 'initial=1') |
| 110 self.assertEqual( | 112 self.assertEqual( |
| 111 qa, | 113 qa, |
| 112 'initial=1&bar=%E2%98%83&max-keys=0&foo=true&some-other=thing' | 114 'initial=1&bar=%E2%98%83&max-keys=0&foo=true&some-other=thing' |
| 113 ) | 115 ) |
| 114 | 116 |
| 115 @patch.object(Bucket, 'get_all_keys') | 117 @patch.object(S3Connection, 'head_bucket') |
| 116 def test_bucket_copy_key_no_validate(self, mock_get_all_keys): | 118 def test_bucket_copy_key_no_validate(self, mock_head_bucket): |
| 117 self.set_http_response(status_code=200) | 119 self.set_http_response(status_code=200) |
| 118 bucket = self.service_connection.create_bucket('mybucket') | 120 bucket = self.service_connection.create_bucket('mybucket') |
| 119 | 121 |
| 120 self.assertFalse(mock_get_all_keys.called) | 122 self.assertFalse(mock_head_bucket.called) |
| 121 self.service_connection.get_bucket('mybucket', validate=True) | 123 self.service_connection.get_bucket('mybucket', validate=True) |
| 122 self.assertTrue(mock_get_all_keys.called) | 124 self.assertTrue(mock_head_bucket.called) |
| 123 | 125 |
| 124 mock_get_all_keys.reset_mock() | 126 mock_head_bucket.reset_mock() |
| 125 self.assertFalse(mock_get_all_keys.called) | 127 self.assertFalse(mock_head_bucket.called) |
| 126 try: | 128 try: |
| 127 bucket.copy_key('newkey', 'srcbucket', 'srckey', preserve_acl=True) | 129 bucket.copy_key('newkey', 'srcbucket', 'srckey', preserve_acl=True) |
| 128 except: | 130 except: |
| 129 # Will throw because of empty response. | 131 # Will throw because of empty response. |
| 130 pass | 132 pass |
| 131 self.assertFalse(mock_get_all_keys.called) | 133 self.assertFalse(mock_head_bucket.called) |
| 132 | 134 |
| 133 @patch.object(Bucket, '_get_all') | 135 @patch.object(Bucket, '_get_all') |
| 134 def test_bucket_encoding(self, mock_get_all): | 136 def test_bucket_encoding(self, mock_get_all): |
| 135 self.set_http_response(status_code=200) | 137 self.set_http_response(status_code=200) |
| 136 bucket = self.service_connection.get_bucket('mybucket') | 138 bucket = self.service_connection.get_bucket('mybucket') |
| 137 | 139 |
| 138 # First, without the encoding. | 140 # First, without the encoding. |
| 139 mock_get_all.reset_mock() | 141 mock_get_all.reset_mock() |
| 140 bucket.get_all_keys() | 142 bucket.get_all_keys() |
| 141 mock_get_all.assert_called_with( | 143 mock_get_all.assert_called_with( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 169 | 171 |
| 170 mock_get_all.reset_mock() | 172 mock_get_all.reset_mock() |
| 171 bucket.get_all_multipart_uploads(encoding_type='url') | 173 bucket.get_all_multipart_uploads(encoding_type='url') |
| 172 mock_get_all.assert_called_with( | 174 mock_get_all.assert_called_with( |
| 173 [ | 175 [ |
| 174 ('Upload', MultiPartUpload), | 176 ('Upload', MultiPartUpload), |
| 175 ('CommonPrefixes', Prefix) | 177 ('CommonPrefixes', Prefix) |
| 176 ], 'uploads', None, | 178 ], 'uploads', None, |
| 177 encoding_type='url' | 179 encoding_type='url' |
| 178 ) | 180 ) |
| 181 |
| 182 @patch.object(Bucket, 'get_all_keys') |
| 183 @patch.object(Bucket, '_get_key_internal') |
| 184 def test_bucket_get_key_no_validate(self, mock_gki, mock_gak): |
| 185 self.set_http_response(status_code=200) |
| 186 bucket = self.service_connection.get_bucket('mybucket') |
| 187 key = bucket.get_key('mykey', validate=False) |
| 188 |
| 189 self.assertEqual(len(mock_gki.mock_calls), 0) |
| 190 self.assertTrue(isinstance(key, Key)) |
| 191 self.assertEqual(key.name, 'mykey') |
| 192 |
| 193 with self.assertRaises(BotoClientError): |
| 194 bucket.get_key( |
| 195 'mykey', |
| 196 version_id='something', |
| 197 validate=False |
| 198 ) |
| 199 |
| 200 def acl_policy(self): |
| 201 return """<?xml version="1.0" encoding="UTF-8"?> |
| 202 <AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> |
| 203 <Owner> |
| 204 <ID>owner_id</ID> |
| 205 <DisplayName>owner_display_name</DisplayName> |
| 206 </Owner> |
| 207 <AccessControlList> |
| 208 <Grant> |
| 209 <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 210 xsi:type="CanonicalUser"> |
| 211 <ID>grantee_id</ID> |
| 212 <DisplayName>grantee_display_name</DisplayName> |
| 213 </Grantee> |
| 214 <Permission>FULL_CONTROL</Permission> |
| 215 </Grant> |
| 216 </AccessControlList> |
| 217 </AccessControlPolicy>""" |
| 218 |
| 219 def test_bucket_acl_policy_namespace(self): |
| 220 self.set_http_response(status_code=200) |
| 221 bucket = self.service_connection.get_bucket('mybucket') |
| 222 |
| 223 self.set_http_response(status_code=200, body=self.acl_policy()) |
| 224 policy = bucket.get_acl() |
| 225 |
| 226 xml_policy = policy.to_xml() |
| 227 document = xml.dom.minidom.parseString(xml_policy) |
| 228 namespace = document.documentElement.namespaceURI |
| 229 self.assertEqual(namespace, 'http://s3.amazonaws.com/doc/2006-03-01/') |
| OLD | NEW |