def test_create(self):
        _ctx = self.get_mock_ctx(
            'test_create',
            test_properties=NODE_PROPERTIES,
            test_runtime_properties=RUNTIME_PROPERTIES,
            type_hierarchy=QUEUE_TH
        )

        current_ctx.set(_ctx)

        self.fake_client.create_queue = MagicMock(return_value={
            'QueueUrl': 'fake_QueueUrl'
        })

        queue.create(ctx=_ctx, resource_config=None, iface=None)

        self.fake_boto.assert_called_with('sqs', **CLIENT_CONFIG)

        self.fake_client.get_queue_attributes.assert_called_with(
            AttributeNames=['QueueArn'], QueueUrl='fake_QueueUrl'
        )

        self.assertEqual(
            _ctx.instance.runtime_properties,
            {
                'aws_resource_arn': 'None',
                'aws_resource_id': 'fake_QueueUrl',
                'resource_config': {}
            }
        )
    def test_create(self):
        _ctx = self.get_mock_ctx(
            'test_create',
            test_properties=NODE_PROPERTIES,
            test_runtime_properties=RUNTIME_PROPERTIES,
            type_hierarchy=QUEUE_TH
        )

        current_ctx.set(_ctx)

        self.fake_client.create_queue = MagicMock(return_value={
            'QueueUrl': 'fake_QueueUrl'
        })

        queue.create(ctx=_ctx, resource_config=None, iface=None)

        self.fake_boto.assert_called_with('sqs', **CLIENT_CONFIG)

        self.fake_client.get_queue_attributes.assert_called_with(
            AttributeNames=['QueueArn'], QueueUrl='fake_QueueUrl'
        )

        self.assertEqual(
            _ctx.instance.runtime_properties,
            {
                'aws_resource_arn': 'None',
                'aws_resource_id': 'fake_QueueUrl',
                'resource_config': {}
            }
        )
    def test_create_with_arn(self):
        node_properties = {
            'use_external_resource': False,
            'resource_config': {
                'kwargs': {
                    'QueueName': 'test-queue',
                    'Attributes': {
                        'Policy': POLICY_STRING,
                        'MessageRetentionPeriod': '86400',
                        'VisibilityTimeout': '180'
                    }
                }
            },
            'client_config': CLIENT_CONFIG
        }

        _ctx = self.get_mock_ctx(
            'test_create',
            test_properties=node_properties,
            test_runtime_properties=RUNTIME_PROPERTIES,
            type_hierarchy=QUEUE_TH
        )

        current_ctx.set(_ctx)

        self.fake_client.create_queue = MagicMock(return_value={
            'QueueUrl': 'fake_QueueUrl'
        })

        self.fake_client.get_queue_attributes = MagicMock(return_value={
            'Attributes': {
                'QueueArn': 'fake_QueueArn'
            }
        })
        queue.create(ctx=_ctx, resource_config=None, iface=None)

        self.fake_boto.assert_called_with('sqs', **CLIENT_CONFIG)

        self.fake_client.create_queue.assert_called_with(
            Attributes={
                'Policy': POLICY_STRING,
                'MessageRetentionPeriod': '86400',
                'VisibilityTimeout': '180'
            },
            QueueName='test-queue'
        )

        self.fake_client.get_queue_attributes.assert_called_with(
            AttributeNames=['QueueArn'], QueueUrl='fake_QueueUrl'
        )

        self.assertEqual(
            _ctx.instance.runtime_properties,
            RUNTIME_PROPERTIES_AFTER_CREATE
        )
    def test_create_with_arn(self):
        node_properties = {
            'use_external_resource': False,
            'resource_config': {
                'kwargs': {
                    'QueueName': 'test-queue',
                    'Attributes': {
                        'Policy': POLICY_STRING,
                        'MessageRetentionPeriod': '86400',
                        'VisibilityTimeout': '180'
                    }
                }
            },
            'client_config': CLIENT_CONFIG
        }

        _ctx = self.get_mock_ctx(
            'test_create',
            test_properties=node_properties,
            test_runtime_properties=RUNTIME_PROPERTIES,
            type_hierarchy=QUEUE_TH
        )

        current_ctx.set(_ctx)

        self.fake_client.create_queue = MagicMock(return_value={
            'QueueUrl': 'fake_QueueUrl'
        })

        self.fake_client.get_queue_attributes = MagicMock(return_value={
            'Attributes': {
                'QueueArn': 'fake_QueueArn'
            }
        })
        queue.create(ctx=_ctx, resource_config=None, iface=None)

        self.fake_boto.assert_called_with('sqs', **CLIENT_CONFIG)

        self.fake_client.create_queue.assert_called_with(
            Attributes={
                'Policy': POLICY_STRING,
                'MessageRetentionPeriod': '86400',
                'VisibilityTimeout': '180'
            },
            QueueName='test-queue'
        )

        self.fake_client.get_queue_attributes.assert_called_with(
            AttributeNames=['QueueArn'], QueueUrl='fake_QueueUrl'
        )

        self.assertEqual(
            _ctx.instance.runtime_properties,
            RUNTIME_PROPERTIES_AFTER_CREATE
        )
    def test_create_raises_UnknownServiceError(self):
        _ctx = self.get_mock_ctx('test_create',
                                 test_properties=NODE_PROPERTIES,
                                 test_runtime_properties=RUNTIME_PROPERTIES,
                                 type_hierarchy=QUEUE_TH)

        current_ctx.set(_ctx)

        with self.assertRaises(UnknownServiceError) as error:
            queue.create(ctx=_ctx, resource_config=None, iface=None)

        self.assertEqual(
            str(error.exception),
            "Unknown service: 'sqs'. Valid service names are: ['rds']")

        self.fake_boto.assert_called_with('sqs', **CLIENT_CONFIG)
    def test_create_raises_UnknownServiceError(self):
        _ctx = self.get_mock_ctx(
            'test_create',
            test_properties=NODE_PROPERTIES,
            test_runtime_properties=RUNTIME_PROPERTIES,
            type_hierarchy=QUEUE_TH
        )

        current_ctx.set(_ctx)

        with self.assertRaises(UnknownServiceError) as error:
            queue.create(ctx=_ctx, resource_config=None, iface=None)

        self.assertEqual(
            str(error.exception),
            "Unknown service: 'sqs'. Valid service names are: ['rds']"
        )

        self.fake_boto.assert_called_with('sqs', **CLIENT_CONFIG)