コード例 #1
0
    def test_remove_tag_empty_value(self):
        self.set_http_response(status_code=200)
        taggedEC2Object = TaggedEC2Object(self.service_connection)
        taggedEC2Object.id = "i-abcd1234"
        taggedEC2Object.tags["key1"] = "value1"
        taggedEC2Object.tags["key2"] = "value2"

        taggedEC2Object.remove_tag("key1", "")

        self.assert_request_parameters(
            {
                'ResourceId.1': 'i-abcd1234',
                'Action': 'DeleteTags',
                'Tag.1.Key': 'key1',
                'Tag.1.Value': ''
            },
            ignore_params_values=[
                'AWSAccessKeyId', 'SignatureMethod', 'SignatureVersion',
                'Timestamp', 'Version'
            ])

        self.assertEqual(taggedEC2Object.tags, {
            "key1": "value1",
            "key2": "value2"
        })
コード例 #2
0
    def test_add_tags(self):
        self.set_http_response(status_code=200)
        taggedEC2Object = TaggedEC2Object(self.service_connection)
        taggedEC2Object.id = "i-abcd1234"
        taggedEC2Object.tags["already_present_key"] = "already_present_value"

        taggedEC2Object.add_tags({"key1": "value1", "key2": "value2"})

        self.assert_request_parameters(
            {
                'ResourceId.1': 'i-abcd1234',
                'Action': 'CreateTags',
                'Tag.1.Key': 'key1',
                'Tag.1.Value': 'value1',
                'Tag.2.Key': 'key2',
                'Tag.2.Value': 'value2'
            },
            ignore_params_values=[
                'AWSAccessKeyId', 'SignatureMethod', 'SignatureVersion',
                'Timestamp', 'Version'
            ])

        self.assertEqual(
            taggedEC2Object.tags, {
                "already_present_key": "already_present_value",
                "key1": "value1",
                "key2": "value2"
            })
コード例 #3
0
 def test_tag_resource_raises_error(self):
     """ Tests that when add_tags fails
         tag_resource raises the right error.
     """
     ctx = self.get_mock_ctx('test_tag_resource_raises_error')
     current_ctx.set(ctx=ctx)
     resource = AwsBaseNode('root', [], resource_states=[])
     ctx.node.properties['name'] = 'root'
     test_resource = TaggedEC2Object()
     tags = []
     with mock.patch(
             'boto.ec2.ec2object.TaggedEC2Object.add_tags') \
             as mock_add_tags:
         mock_add_tags.side_effect = EC2ResponseError(
                 mock.Mock(return_value={'status': 404}),
                 'error')
         ex = self.assertRaises(
                 NonRecoverableError,
                 resource._tag_resource,
                 test_resource,
                 tags)
         self.assertIn(
                 'unable to tag resource name', ex.message)