本文整理汇总了Python中boto3.exceptions.ResourceNotExistsError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ResourceNotExistsError方法的具体用法?Python exceptions.ResourceNotExistsError怎么用?Python exceptions.ResourceNotExistsError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto3.exceptions
的用法示例。
在下文中一共展示了exceptions.ResourceNotExistsError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_attributes_fails_with_no_existing_table_create_table_default_false
# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import ResourceNotExistsError [as 别名]
def test_get_attributes_fails_with_no_existing_table_create_table_default_false(self):
self.dynamodb_resource.Table.side_effect = ResourceNotExistsError(
"test", "test", "test")
self.dynamodb_resource.create_table.return_value = "test"
test_dynamodb_adapter = DynamoDbAdapter(
table_name="test_table", partition_keygen=self.partition_keygen,
dynamodb_resource=self.dynamodb_resource)
with self.assertRaises(PersistenceException) as exc:
test_dynamodb_adapter.get_attributes(
request_envelope=self.request_envelope)
assert "DynamoDb table test_table doesn't exist" in str(
exc.exception), (
"Get attributes didn't raise Persistence Exception when no "
"existing table and create table set as false")
self.dynamodb_resource.create_table.assert_not_called(), (
"Create table called on dynamodb resource when create_table "
"flag is set as False")
示例2: test_save_attributes_fails_with_no_existing_table
# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import ResourceNotExistsError [as 别名]
def test_save_attributes_fails_with_no_existing_table(self):
self.dynamodb_resource.Table.side_effect = ResourceNotExistsError(
"test", "test", "test")
self.dynamodb_resource.create_table.return_value = "test"
test_dynamodb_adapter = DynamoDbAdapter(
table_name="test_table", partition_keygen=self.partition_keygen,
dynamodb_resource=self.dynamodb_resource)
with self.assertRaises(PersistenceException) as exc:
test_dynamodb_adapter.save_attributes(
request_envelope=self.request_envelope, attributes=self.attributes)
assert "DynamoDb table test_table doesn't exist" in str(
exc.exception), (
"Save attributes didn't raise Persistence Exception when no "
"existing table and create table set as false")
self.dynamodb_resource.create_table.assert_not_called(), (
"Create table called on dynamodb resource when create_table flag "
"is set as False")
示例3: test_delete_attributes_fails_with_no_existing_table
# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import ResourceNotExistsError [as 别名]
def test_delete_attributes_fails_with_no_existing_table(self):
self.dynamodb_resource.Table.side_effect = ResourceNotExistsError(
"test", "test", "test")
self.dynamodb_resource.create_table.return_value = "test"
test_dynamodb_adapter = DynamoDbAdapter(
table_name="test_table", partition_keygen=self.partition_keygen,
dynamodb_resource=self.dynamodb_resource)
with self.assertRaises(PersistenceException) as exc:
test_dynamodb_adapter.delete_attributes(
request_envelope=self.request_envelope)
assert "DynamoDb table test_table doesn't exist" in str(
exc.exception), (
"Delete attributes didn't raise Persistence Exception when no "
"existing table and create table set as false")
self.dynamodb_resource.create_table.assert_not_called(), (
"Create table called on dynamodb resource when create_table flag "
"is set as False")
示例4: test_get_attributes_resource_not_exist_fails
# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import ResourceNotExistsError [as 别名]
def test_get_attributes_resource_not_exist_fails(self):
self.object_keygen.return_value = "test_object_key"
self.s3_client.get_object.side_effect = ResourceNotExistsError("resource does not exist",
self.bucket_key, self.bucket_name)
test_s3_adapter = S3Adapter(bucket_name=self.bucket_name, path_prefix=self.bucket_key,
s3_client=self.s3_client, object_keygen=self.object_keygen)
with self.assertRaises(PersistenceException) as exc:
test_s3_adapter.get_attributes(request_envelope=self.request_envelope)
示例5: test_save_attributes_fails_with_no_existing_bucket
# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import ResourceNotExistsError [as 别名]
def test_save_attributes_fails_with_no_existing_bucket(self):
self.object_keygen.return_value = "test_object_key"
test_s3_adapter = S3Adapter(bucket_name=self.bucket_name, path_prefix=self.bucket_key,
s3_client=self.s3_client, object_keygen=self.object_keygen)
self.s3_client.put_object.side_effect = ResourceNotExistsError("resource does not exist",
self.bucket_key, self.bucket_name)
with self.assertRaises(PersistenceException) as exc:
test_s3_adapter.save_attributes(request_envelope=self.request_envelope, attributes=_MOCK_DATA)
示例6: resource
# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import ResourceNotExistsError [as 别名]
def resource(self, service_name, region_name=None, api_version=None,
use_ssl=True, verify=None, endpoint_url=None,
aws_access_key_id=None, aws_secret_access_key=None,
aws_session_token=None, config=None):
try:
resource_model = self._loader.load_service_model(
service_name, 'resources-1', api_version)
except UnknownServiceError:
available = self.get_available_resources()
has_low_level_client = (
service_name in self.get_available_services())
raise ResourceNotExistsError(service_name, available,
has_low_level_client)
except DataNotFoundError:
# This is because we've provided an invalid API version.
available_api_versions = self._loader.list_api_versions(
service_name, 'resources-1')
raise UnknownAPIVersionError(
service_name, api_version, ', '.join(available_api_versions))
if api_version is None:
# Even though botocore's load_service_model() can handle
# using the latest api_version if not provided, we need
# to track this api_version in boto3 in order to ensure
# we're pairing a resource model with a client model
# of the same API version. It's possible for the latest
# API version of a resource model in boto3 to not be
# the same API version as a service model in botocore.
# So we need to look up the api_version if one is not
# provided to ensure we load the same API version of the
# client.
#
# Note: This is relying on the fact that
# loader.load_service_model(..., api_version=None)
# and loader.determine_latest_version(..., 'resources-1')
# both load the same api version of the file.
api_version = self._loader.determine_latest_version(
service_name, 'resources-1')
# Creating a new resource instance requires the low-level client
# and service model, the resource version and resource JSON data.
# We pass these to the factory and get back a class, which is
# instantiated on top of the low-level client.
if config is not None:
if config.user_agent_extra is None:
config = copy.deepcopy(config)
config.user_agent_extra = 'Resource'
else:
config = AioConfig(user_agent_extra='Resource')
# client = blah part has been moved into a dodgy context class
return ResourceCreaterContext(self, service_name, region_name, api_version,
use_ssl, verify, endpoint_url, aws_access_key_id,
aws_secret_access_key, aws_session_token, config,
resource_model)