Skip to content

Commit

Permalink
updates to existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonemo committed May 26, 2023
1 parent 87dfca1 commit a04c941
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 11 additions & 1 deletion tests/unit/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@
from botocore.configprovider import ConfigValueStore
from botocore.hooks import HierarchicalEmitter
from botocore.model import ServiceModel
from botocore.useragent import UserAgentString
from tests import mock, unittest


class TestCreateClientArgs(unittest.TestCase):
def setUp(self):
self.event_emitter = mock.Mock(HierarchicalEmitter)
self.config_store = ConfigValueStore()
user_agent_creator = UserAgentString(None, None, None, None, None)
self.args_create = args.ClientArgsCreator(
self.event_emitter, None, None, None, None, self.config_store
event_emitter=self.event_emitter,
user_agent=None,
response_parser_factory=None,
loader=None,
exceptions_factory=None,
config_store=self.config_store,
user_agent_creator=user_agent_creator,
)
self.service_name = 'ec2'
self.region = 'us-west-2'
Expand Down Expand Up @@ -518,13 +526,15 @@ class TestEndpointResolverBuiltins(unittest.TestCase):
def setUp(self):
event_emitter = mock.Mock(HierarchicalEmitter)
self.config_store = ConfigValueStore()
user_agent_creator = UserAgentString(None, None, None, None, None)
self.args_create = args.ClientArgsCreator(
event_emitter=event_emitter,
user_agent=None,
response_parser_factory=None,
loader=None,
exceptions_factory=None,
config_store=self.config_store,
user_agent_creator=user_agent_creator,
)
self.bridge = ClientEndpointBridge(
endpoint_resolver=mock.Mock(),
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
UnknownSignatureVersionError,
)
from botocore.stub import Stubber
from botocore.useragent import UserAgentString
from tests import mock, unittest


Expand Down Expand Up @@ -169,6 +170,7 @@ def create_client_creator(
endpoint_prefix=None,
exceptions_factory=None,
config_store=None,
user_agent_creator=None,
):
if event_emitter is None:
event_emitter = hooks.HierarchicalEmitter()
Expand All @@ -187,6 +189,14 @@ def create_client_creator(
exceptions_factory = ClientExceptionsFactory()
if config_store is None:
config_store = self.config_store
if user_agent_creator is None:
user_agent_creator = (
UserAgentString.from_environment().set_session_config(
session_user_agent_name='MyUserAgent',
session_user_agent_version='1.2.3-rc5',
session_user_agent_extra=None,
)
)
creator = client.ClientCreator(
self.loader,
self.resolver,
Expand All @@ -197,6 +207,7 @@ def create_client_creator(
response_parser_factory,
exceptions_factory,
config_store,
user_agent_creator,
)
return creator

Expand Down Expand Up @@ -647,7 +658,7 @@ def test_client_user_agent_in_request(self):
k.lower(): v
for k, v in self.endpoint.make_request.call_args[0][1].items()
}
self.assertEqual(params['headers']['User-Agent'], 'user-agent')
self.assertIn('MyUserAgent/1.2.3', params['headers']['User-Agent'])

def test_client_custom_user_agent_in_request(self):
creator = self.create_client_creator()
Expand All @@ -673,7 +684,7 @@ def test_client_custom_user_agent_extra_in_request(self):
)
service_client.test_operation(Foo='one')
headers = self.endpoint.make_request.call_args[0][1]['headers']
self.assertEqual(headers['User-Agent'], 'user-agent extrastuff')
self.assertTrue(headers['User-Agent'].endswith('extrastuff'))

def test_client_registers_request_created_handler(self):
event_emitter = self.create_mock_emitter()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_useragent.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_user_agent_string_with_missing_information():
crt_version=None,
).with_client_config(Config())
actual = uas.to_string()
assert actual == 'Botocore/1.29.134 ua/2.0 os/other lang/python'
assert actual == f'Botocore/{botocore_version} ua/2.0 os/other lang/python'


def test_from_environment(monkeypatch):
Expand Down

0 comments on commit a04c941

Please sign in to comment.