File: test_s3_control.py

package info (click to toggle)
python-botocore 1.12.103%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 41,552 kB
  • sloc: python: 43,119; xml: 15,052; makefile: 131
file content (66 lines) | stat: -rw-r--r-- 2,815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from tests import unittest, mock, BaseSessionTest, create_session

from botocore.config import Config
from botocore.awsrequest import AWSResponse


class S3ControlOperationTest(BaseSessionTest):
    def setUp(self):
        super(S3ControlOperationTest, self).setUp()
        self.region = 'us-west-2'
        self.client = self.session.create_client(
            's3control', self.region)
        self.session_send_patch = mock.patch(
            'botocore.endpoint.Endpoint._send')
        self.http_session_send_mock = self.session_send_patch.start()
        self.http_response = mock.Mock(spec=AWSResponse)
        self.http_response.status_code = 200
        self.http_response.headers = {}
        self.http_response.content = ''
        self.http_session_send_mock.return_value = self.http_response

    def tearDown(self):
        super(BaseSessionTest, self).tearDown()
        self.session_send_patch.stop()

    def test_does_add_account_id_to_host(self):
        self.client.get_public_access_block(AccountId='123')
        self.assertEqual(self.http_session_send_mock.call_count, 1)
        request = self.http_session_send_mock.call_args_list[0][0][0]

        self.assertTrue(request.url.startswith(
            'https://123.s3-control.us-west-2.amazonaws.com'))

    def test_does_remove_account_id_from_headers(self):
        self.client.get_public_access_block(AccountId='123')
        self.assertEqual(self.http_session_send_mock.call_count, 1)
        request = self.http_session_send_mock.call_args_list[0][0][0]

        self.assertIn('x-amz-account-id', request.headers)

    def test_does_support_dualstack_endpoint(self):
        # Re-create the client with the use_dualstack_endpoint configuration
        # option set to True.
        self.client = self.session.create_client(
            's3control', self.region, config=Config(
                s3={'use_dualstack_endpoint': True}
            )
        )
        self.client.get_public_access_block(AccountId='123')

        self.assertEqual(self.http_session_send_mock.call_count, 1)
        request = self.http_session_send_mock.call_args_list[0][0][0]
        self.assertTrue(request.url.startswith(
            'https://123.s3-control.dualstack.us-west-2.amazonaws.com'))