Python boto3.exceptions.ResourceNotExistsError() Examples

The following are 6 code examples of boto3.exceptions.ResourceNotExistsError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module boto3.exceptions , or try the search function .
Example #1
Source File: test_adapter.py    From alexa-skills-kit-sdk-for-python with Apache License 2.0 6 votes vote down vote up
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") 
Example #2
Source File: test_adapter.py    From alexa-skills-kit-sdk-for-python with Apache License 2.0 6 votes vote down vote up
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") 
Example #3
Source File: test_adapter.py    From alexa-skills-kit-sdk-for-python with Apache License 2.0 6 votes vote down vote up
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") 
Example #4
Source File: test_adapter.py    From alexa-skills-kit-sdk-for-python with Apache License 2.0 5 votes vote down vote up
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) 
Example #5
Source File: test_adapter.py    From alexa-skills-kit-sdk-for-python with Apache License 2.0 5 votes vote down vote up
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) 
Example #6
Source File: session.py    From aioboto3 with Apache License 2.0 4 votes vote down vote up
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)