Skip to content

Commit

Permalink
Added partition to client meta object
Browse files Browse the repository at this point in the history
Made the partion name available in the client meta object
Added unit tests for partition in client metadata
Added functional tests for partition in client metadata
  • Loading branch information
Posnet committed Oct 6, 2016
1 parent 34fa1ea commit 0296ded
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
4 changes: 3 additions & 1 deletion botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get_client_args(self, service_model, region_name, is_secure,
protocol = final_args['protocol']
config_kwargs = final_args['config_kwargs']
s3_config = final_args['s3_config']
partition = endpoint_config['metadata'].get('partition', None)

event_emitter = copy.copy(self._event_emitter)
signer = RequestSigner(
Expand Down Expand Up @@ -83,7 +84,8 @@ def get_client_args(self, service_model, region_name, is_secure,
'request_signer': signer,
'service_model': service_model,
'loader': self._loader,
'client_config': new_config
'client_config': new_config,
'partition': partition
}

def compute_client_args(self, service_model, client_config,
Expand Down
11 changes: 8 additions & 3 deletions botocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class BaseClient(object):

def __init__(self, serializer, endpoint, response_parser,
event_emitter, request_signer, service_model, loader,
client_config):
client_config, partition):
self._serializer = serializer
self._endpoint = endpoint
self._response_parser = response_parser
Expand All @@ -397,7 +397,7 @@ def __init__(self, serializer, endpoint, response_parser,
self._client_config = client_config
self.meta = ClientMeta(event_emitter, self._client_config,
endpoint.host, service_model,
self._PY_TO_OP_NAME)
self._PY_TO_OP_NAME, partition)
self._register_handlers()

def _register_handlers(self):
Expand Down Expand Up @@ -660,12 +660,13 @@ class ClientMeta(object):
"""

def __init__(self, events, client_config, endpoint_url, service_model,
method_to_api_mapping):
method_to_api_mapping, partition):
self.events = events
self._client_config = client_config
self._endpoint_url = endpoint_url
self._service_model = service_model
self._method_to_api_mapping = method_to_api_mapping
self._partition = partition

@property
def service_model(self):
Expand All @@ -686,3 +687,7 @@ def config(self):
@property
def method_to_api_mapping(self):
return self._method_to_api_mapping

@property
def partition(self):
return self._partition
44 changes: 44 additions & 0 deletions tests/functional/test_client_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2015 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

import botocore.session

class TestClientMeta(unittest.TestCase):
def setUp(self):
self.session = botocore.session.get_session()

def test_region_name_on_meta(self):
client = self.session.create_client('s3', 'us-west-2')
self.assertEqual(client.meta.region_name, 'us-west-2')

def test_endpoint_url_on_meta(self):
client = self.session.create_client('s3', 'us-west-2',
endpoint_url='https://foo')
self.assertEqual(client.meta.endpoint_url, 'https://foo')

def test_client_has_standard_partition_on_meta(self):
client = self.session.create_client('s3', 'us-west-2')
self.assertEqual(client.meta.partition, 'aws')

def test_client_has_china_partition_on_meta(self):
client = self.session.create_client('s3', 'cn-north-1')
self.assertEqual(client.meta.partition, 'aws-cn')

def test_client_has_gov_partition_on_meta(self):
client = self.session.create_client('s3', 'us-gov-west-1')
self.assertEqual(client.meta.partition, 'aws-us-gov')

def test_client_has_no_partition_on_meta_if_custom_region(self):
client = self.session.create_client('s3', 'myregion')
self.assertEqual(client.meta.partition, None)
3 changes: 2 additions & 1 deletion tests/unit/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def test_max_pool_from_client_config_forwarded_to_endpoint_creator(self):
bridge.resolve.return_value = {
'region_name': 'us-west-2', 'signature_version': 'v4',
'endpoint_url': 'https://ec2/',
'signing_name': 'ec2', 'signing_region': 'us-west-2'}
'signing_name': 'ec2', 'signing_region': 'us-west-2',
'metadata': {}}
with mock.patch('botocore.args.EndpointCreator') as m:
args_create.get_client_args(
service_model, 'us-west-2', True, 'https://ec2/', True,
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,26 @@ def test_client_has_endpoint_url_on_meta(self):
self.assertEqual(service_client.meta.endpoint_url,
'https://foo.bar')

def test_client_has_standard_partition_on_meta(self):
creator = self.create_client_creator()
service_client = creator.create_client(
'myservice', 'us-west-2', credentials=self.credentials)
self.assertEqual(service_client.meta.partition,
'aws')

def test_client_has_non_standard_partition_on_meta(self):
creator = self.create_client_creator()
self.resolver.construct_endpoint.return_value = {
'partition': 'aws-cn',
'hostname': 'foo',
'endpointName': 'cn-north-1',
'signatureVersions': ['v4'],
}
service_client = creator.create_client(
'myservice', 'cn-north-1', credentials=self.credentials)
self.assertEqual(service_client.meta.partition,
'aws-cn')

def test_api_version_is_passed_to_loader_if_provided(self):
creator = self.create_client_creator()
self.endpoint.host = 'https://foo.bar'
Expand Down

0 comments on commit 0296ded

Please sign in to comment.