本文整理汇总了Python中tests.create_session函数的典型用法代码示例。如果您正苦于以下问题:Python create_session函数的具体用法?Python create_session怎么用?Python create_session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_session函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _verify_expected_endpoint_url
def _verify_expected_endpoint_url(region, bucket, key, s3_config,
is_secure=True,
customer_provided_endpoint=None,
expected_url=None):
http_response = mock.Mock()
http_response.status_code = 200
http_response.headers = {}
http_response.content = b''
environ = {}
with mock.patch('os.environ', environ):
environ['AWS_ACCESS_KEY_ID'] = 'access_key'
environ['AWS_SECRET_ACCESS_KEY'] = 'secret_key'
environ['AWS_CONFIG_FILE'] = 'no-exist-foo'
session = create_session()
session.config_filename = 'no-exist-foo'
config = None
if s3_config is not None:
config = Config(s3=s3_config)
s3 = session.create_client('s3', region_name=region, use_ssl=is_secure,
config=config,
endpoint_url=customer_provided_endpoint)
with mock.patch('botocore.endpoint.Session.send') as mock_send:
mock_send.return_value = http_response
s3.put_object(Bucket=bucket,
Key=key, Body=b'bar')
request_sent = mock_send.call_args[0][0]
assert_equal(request_sent.url, expected_url)
开发者ID:kyleknap,项目名称:botocore,代码行数:27,代码来源:test_s3.py
示例2: test_can_specify_multiple_versions_from_config
def test_can_specify_multiple_versions_from_config(self, client_creator):
config_api_version = '2012-01-01'
second_config_api_version = '2013-01-01'
with temporary_file('w') as f:
del self.environ['FOO_PROFILE']
self.environ['FOO_CONFIG_FILE'] = f.name
self.session = create_session(session_vars=self.env_vars)
f.write('[default]\n')
f.write('foo_api_versions =\n'
' myservice = %s\n'
' myservice2 = %s\n' % (
config_api_version, second_config_api_version)
)
f.flush()
self.session.create_client('myservice', 'us-west-2')
call_kwargs = client_creator.return_value.\
create_client.call_args[1]
self.assertEqual(call_kwargs['api_version'], config_api_version)
self.session.create_client('myservice2', 'us-west-2')
call_kwargs = client_creator.return_value.\
create_client.call_args[1]
self.assertEqual(
call_kwargs['api_version'], second_config_api_version)
开发者ID:pplu,项目名称:botocore,代码行数:25,代码来源:test_session.py
示例3: _get_patched_session
def _get_patched_session():
with mock.patch('os.environ') as environ:
environ['AWS_ACCESS_KEY_ID'] = 'access_key'
environ['AWS_SECRET_ACCESS_KEY'] = 'secret_key'
environ['AWS_CONFIG_FILE'] = 'no-exist-foo'
session = create_session()
return session
开发者ID:pplu,项目名称:botocore,代码行数:7,代码来源:test_regions.py
示例4: test_profile_does_not_exist_with_default_profile
def test_profile_does_not_exist_with_default_profile(self):
session = create_session(session_vars=self.env_vars)
config = session.get_scoped_config()
# We should have loaded this properly, and we'll check
# that foo_access_key which is defined in the config
# file should be present in the loaded config dict.
self.assertIn('aws_access_key_id', config)
开发者ID:vchan,项目名称:botocore,代码行数:7,代码来源:test_session.py
示例5: test_emit_first_non_none
def test_emit_first_non_none(self):
session = create_session(session_vars=self.env_vars)
session.register('foo', lambda **kwargs: None)
session.register('foo', lambda **kwargs: 'first')
session.register('foo', lambda **kwargs: 'second')
response = session.emit_first_non_none_response('foo')
self.assertEqual(response, 'first')
开发者ID:vchan,项目名称:botocore,代码行数:7,代码来源:test_session.py
示例6: setUp
def setUp(self):
super(EnvVarTest, self).setUp()
self.environ['AWS_CONFIG_FILE'] = path('aws_config_nocreds')
self.environ['BOTO_CONFIG'] = ''
self.environ['AWS_ACCESS_KEY_ID'] = 'foo'
self.environ['AWS_SECRET_ACCESS_KEY'] = 'bar'
self.session = create_session(session_vars=TESTENVVARS)
开发者ID:j3tm0t0,项目名称:botocore,代码行数:7,代码来源:test_credentials.py
示例7: test_xml_parsing
def test_xml_parsing():
for dp in ['responses', 'errors']:
data_path = os.path.join(os.path.dirname(__file__), 'xml')
data_path = os.path.join(data_path, dp)
session = create_session()
xml_files = glob.glob('%s/*.xml' % data_path)
service_names = set()
for fn in xml_files:
service_names.add(os.path.split(fn)[1].split('-')[0])
for service_name in service_names:
service = session.get_service(service_name)
service_xml_files = glob.glob('%s/%s-*.xml' % (data_path,
service_name))
for xmlfile in service_xml_files:
dirname, filename = os.path.split(xmlfile)
basename = os.path.splitext(filename)[0]
jsonfile = os.path.join(dirname, basename + '.json')
sn, opname = basename.split('-', 1)
opname = opname.split('#')[0]
operation = service.get_operation(opname)
r = XmlResponse(session, operation)
fp = open(xmlfile)
xml = fp.read()
fp.close()
r.parse(xml, 'utf-8')
save_jsonfile(jsonfile, r)
fp = open(jsonfile)
data = json.load(fp)
fp.close()
yield check_dicts, xmlfile, r.get_value(), data
开发者ID:Lumida,项目名称:botocore,代码行数:30,代码来源:test_response_parsing.py
示例8: test_multiple_env_vars_uses_second_var
def test_multiple_env_vars_uses_second_var(self):
env_vars = {
'profile': (None, ['BAR_DEFAULT_PROFILE', 'BAR_PROFILE'], None),
}
session = create_session(session_vars=env_vars)
self.environ.pop('BAR_DEFAULT_PROFILE', None)
self.environ['BAR_PROFILE'] = 'second'
self.assertEqual(session.get_config_variable('profile'), 'second')
开发者ID:vchan,项目名称:botocore,代码行数:8,代码来源:test_session.py
示例9: test_supports_multiple_env_vars_for_single_logical_name
def test_supports_multiple_env_vars_for_single_logical_name(self):
env_vars = {
'profile': (None, ['BAR_DEFAULT_PROFILE', 'BAR_PROFILE'], None),
}
session = create_session(session_vars=env_vars)
self.environ['BAR_DEFAULT_PROFILE'] = 'first'
self.environ['BAR_PROFILE'] = 'second'
self.assertEqual(session.get_config_variable('profile'), 'first')
开发者ID:vchan,项目名称:botocore,代码行数:8,代码来源:test_session.py
示例10: test_emitter_can_be_passed_in
def test_emitter_can_be_passed_in(self):
events = HierarchicalEmitter()
session = create_session(event_hooks=events)
calls = []
handler = lambda **kwargs: calls.append(kwargs)
events.register('foo', handler)
session.emit('foo')
self.assertEqual(len(calls), 1)
开发者ID:boto,项目名称:botocore,代码行数:9,代码来源:test_session.py
示例11: test_default_profile_is_obeyed
def test_default_profile_is_obeyed(self):
self.environ['BOTO_DEFAULT_PROFILE'] = 'personal'
session = create_session()
credentials = session.get_credentials()
self.assertEqual(credentials.access_key, 'fie')
self.assertEqual(credentials.secret_key, 'baz')
self.assertEqual(credentials.token, 'fiebaz')
self.assertEqual(credentials.method, 'config')
self.assertEqual(len(session.available_profiles), 2)
self.assertIn('default', session.available_profiles)
self.assertIn('personal', session.available_profiles)
开发者ID:j3tm0t0,项目名称:botocore,代码行数:11,代码来源:test_credentials.py
示例12: test_type_conversions_occur_when_specified
def test_type_conversions_occur_when_specified(self):
# Specify that we can retrieve the var from the
# FOO_TIMEOUT env var, with a conversion function
# of int().
self.env_vars['metadata_service_timeout'] = (
None, 'FOO_TIMEOUT', None, int)
# Environment variables are always strings.
self.environ['FOO_TIMEOUT'] = '10'
session = create_session(session_vars=self.env_vars)
# But we should type convert this to a string.
self.assertEqual(
session.get_config_variable('metadata_service_timeout'), 10)
开发者ID:brint,项目名称:botocore,代码行数:12,代码来源:test_session.py
示例13: setUp
def setUp(self):
self.environ = {}
self.environ_patch = mock.patch('os.environ', self.environ)
self.environ_patch.start()
self.environ['FOO_PROFILE'] = 'foo'
self.environ['FOO_REGION'] = 'us-west-11'
data_path = os.path.join(os.path.dirname(__file__), 'data')
self.environ['FOO_DATA_PATH'] = data_path
config_path = os.path.join(os.path.dirname(__file__), 'cfg',
'foo_config')
self.environ['FOO_CONFIG_FILE'] = config_path
self.session = create_session()
config_chain_builder = ConfigChainFactory(
session=self.session,
environ=self.environ,
)
config_store = self.session.get_component('config_store')
config_updates = {
'profile': config_chain_builder.create_config_chain(
instance_name='profile',
env_var_names='FOO_PROFILE',
),
'region': config_chain_builder.create_config_chain(
instance_name='region',
env_var_names='FOO_REGION',
config_property_name='foo_region',
),
'data_path': config_chain_builder.create_config_chain(
instance_name='data_path',
env_var_names='FOO_DATA_PATH',
config_property_name='data_path',
),
'config_file': config_chain_builder.create_config_chain(
instance_name='config_file',
env_var_names='FOO_CONFIG_FILE',
),
'credentials_file': config_chain_builder.create_config_chain(
instance_name='credentials_file',
default='/tmp/nowhere',
),
'ca_bundle': config_chain_builder.create_config_chain(
instance_name='ca_bundle',
env_var_names='FOO_AWS_CA_BUNDLE',
config_property_name='foo_ca_bundle',
),
'api_versions': config_chain_builder.create_config_chain(
instance_name='api_versions',
config_property_name='foo_api_versions',
default={},
),
}
for name, provider in config_updates.items():
config_store.set_config_provider(name, provider)
开发者ID:boto,项目名称:botocore,代码行数:53,代码来源:test_session.py
示例14: test_config_loader_delegation
def test_config_loader_delegation(self):
session = create_session(profile='credfile-profile')
with temporary_file('w') as f:
f.write('[credfile-profile]\naws_access_key_id=a\n')
f.write('aws_secret_access_key=b\n')
f.flush()
session.set_config_variable('credentials_file', f.name)
# Now trying to retrieve the scoped config should pull in
# values from the shared credentials file.
self.assertEqual(session.get_scoped_config(),
{'aws_access_key_id': 'a',
'aws_secret_access_key': 'b'})
开发者ID:boto,项目名称:botocore,代码行数:12,代码来源:test_session.py
示例15: test_default_profile_specified_raises_exception
def test_default_profile_specified_raises_exception(self):
# If you explicity set the default profile and you don't
# have that in your config file, an exception is raised.
config_path = os.path.join(os.path.dirname(__file__), 'cfg',
'boto_config_empty')
self.environ['FOO_CONFIG_FILE'] = config_path
self.environ['FOO_PROFILE'] = 'default'
session = create_session(session_vars=self.env_vars)
# In this case, even though we specified default, because
# the boto_config_empty config file does not have a default
# profile, we should be raising an exception.
with self.assertRaises(botocore.exceptions.ProfileNotFound):
session.get_scoped_config()
开发者ID:vchan,项目名称:botocore,代码行数:13,代码来源:test_session.py
示例16: test_create_client_with_ca_bundle_from_config
def test_create_client_with_ca_bundle_from_config(self, client_creator):
with temporary_file('w') as f:
del self.environ['FOO_PROFILE']
self.environ['FOO_CONFIG_FILE'] = f.name
self.session = create_session(session_vars=self.env_vars)
f.write('[default]\n')
f.write('foo_ca_bundle=config-certs.pem\n')
f.flush()
self.session.create_client('ec2', 'us-west-2')
call_kwargs = client_creator.return_value.\
create_client.call_args[1]
self.assertEqual(call_kwargs['verify'], 'config-certs.pem')
开发者ID:grepory,项目名称:botocore,代码行数:13,代码来源:test_session.py
示例17: test_profile
def test_profile(self):
self.assertEqual(self.session.get_variable('profile'), 'foo')
self.assertEqual(self.session.get_variable('region'), 'moon-west-1')
self.session.get_variable('profile') == 'default'
saved_region = self.environ['FOO_REGION']
del self.environ['FOO_REGION']
saved_profile = self.environ['FOO_PROFILE']
del self.environ['FOO_PROFILE']
session = create_session(session_vars=self.env_vars)
self.assertEqual(session.get_variable('profile'), None)
self.assertEqual(session.get_variable('region'), 'us-west-1')
self.environ['FOO_REGION'] = saved_region
self.environ['FOO_PROFILE'] = saved_profile
开发者ID:j3tm0t0,项目名称:botocore,代码行数:13,代码来源:test_session.py
示例18: setUp
def setUp(self):
super(TestResetStreamOnRetry, self).setUp()
self.total_calls = 0
self.auth = Mock()
self.session = create_session(include_builtin_handlers=False)
self.service = Mock()
self.service.endpoint_prefix = 's3'
self.service.session = self.session
self.endpoint = RestEndpoint(
self.service, 'us-east-1', 'https://s3.amazonaws.com/',
auth=self.auth)
self.http_session = Mock()
self.endpoint.http_session = self.http_session
self.get_response_patch = patch('botocore.response.get_response')
self.get_response = self.get_response_patch.start()
self.retried_on_exception = None
开发者ID:ctingwai,项目名称:botocore,代码行数:16,代码来源:test_endpoint.py
示例19: setUp
def setUp(self):
self.env_vars = {'profile': (None, 'FOO_PROFILE', None),
'region': ('foo_region', 'FOO_REGION', None),
'data_path': ('data_path', 'FOO_DATA_PATH', None),
'config_file': (None, 'FOO_CONFIG_FILE', None)}
self.environ = {}
self.environ_patch = mock.patch('os.environ', self.environ)
self.environ_patch.start()
self.environ['FOO_PROFILE'] = 'foo'
self.environ['FOO_REGION'] = 'moon-west-1'
data_path = os.path.join(os.path.dirname(__file__), 'data')
self.environ['FOO_DATA_PATH'] = data_path
config_path = os.path.join(os.path.dirname(__file__), 'cfg',
'foo_config')
self.environ['FOO_CONFIG_FILE'] = config_path
self.session = create_session(session_vars=self.env_vars)
开发者ID:ctingwai,项目名称:botocore,代码行数:16,代码来源:test_session.py
示例20: test_param_api_version_overrides_config_value
def test_param_api_version_overrides_config_value(self, client_creator):
config_api_version = '2012-01-01'
override_api_version = '2014-01-01'
with temporary_file('w') as f:
del self.environ['FOO_PROFILE']
self.environ['FOO_CONFIG_FILE'] = f.name
self.session = create_session(session_vars=self.env_vars)
f.write('[default]\n')
f.write('foo_api_versions =\n'
' myservice = %s\n' % config_api_version)
f.flush()
self.session.create_client(
'myservice', 'us-west-2', api_version=override_api_version)
call_kwargs = client_creator.return_value.\
create_client.call_args[1]
self.assertEqual(call_kwargs['api_version'], override_api_version)
开发者ID:pplu,项目名称:botocore,代码行数:17,代码来源:test_session.py
注:本文中的tests.create_session函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论