Add sns.untag_resource
This commit is contained in:
parent
726775678c
commit
26ef792690
@ -5866,7 +5866,7 @@
|
||||
- [ ] update_job
|
||||
|
||||
## sns
|
||||
55% implemented
|
||||
58% implemented
|
||||
- [ ] add_permission
|
||||
- [ ] check_if_phone_number_is_opted_out
|
||||
- [ ] confirm_subscription
|
||||
@ -5899,7 +5899,7 @@
|
||||
- [X] subscribe
|
||||
- [x] tag_resource
|
||||
- [X] unsubscribe
|
||||
- [ ] untag_resource
|
||||
- [x] untag_resource
|
||||
|
||||
## sqs
|
||||
65% implemented
|
||||
|
@ -521,6 +521,13 @@ class SNSBackend(BaseBackend):
|
||||
|
||||
self.topics[resource_arn]._tags = updated_tags
|
||||
|
||||
def untag_resource(self, resource_arn, tag_keys):
|
||||
if resource_arn not in self.topics:
|
||||
raise ResourceNotFoundError
|
||||
|
||||
for key in tag_keys:
|
||||
self.topics[resource_arn]._tags.pop(key, None)
|
||||
|
||||
|
||||
sns_backends = {}
|
||||
for region in Session().get_available_regions('sns'):
|
||||
|
@ -712,6 +712,14 @@ class SNSResponse(BaseResponse):
|
||||
|
||||
return self.response_template(TAG_RESOURCE_TEMPLATE).render()
|
||||
|
||||
def untag_resource(self):
|
||||
arn = self._get_param('ResourceArn')
|
||||
tag_keys = self._get_multi_param('TagKeys.member')
|
||||
|
||||
self.backend.untag_resource(arn, tag_keys)
|
||||
|
||||
return self.response_template(UNTAG_RESOURCE_TEMPLATE).render()
|
||||
|
||||
|
||||
CREATE_TOPIC_TEMPLATE = """<CreateTopicResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
|
||||
<CreateTopicResult>
|
||||
@ -1116,3 +1124,10 @@ TAG_RESOURCE_TEMPLATE = """<TagResourceResponse xmlns="http://sns.amazonaws.com/
|
||||
<RequestId>fd4ab1da-692f-50a7-95ad-e7c665877d98</RequestId>
|
||||
</ResponseMetadata>
|
||||
</TagResourceResponse>"""
|
||||
|
||||
UNTAG_RESOURCE_TEMPLATE = """<UntagResourceResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
|
||||
<UntagResourceResult/>
|
||||
<ResponseMetadata>
|
||||
<RequestId>14eb7b1a-4cbd-5a56-80db-2d06412df769</RequestId>
|
||||
</ResponseMetadata>
|
||||
</UntagResourceResponse>"""
|
||||
|
@ -297,6 +297,52 @@ def test_tag_topic():
|
||||
])
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_untag_topic():
|
||||
conn = boto3.client('sns', region_name = 'us-east-1')
|
||||
response = conn.create_topic(
|
||||
Name = 'some-topic-with-tags',
|
||||
Tags = [
|
||||
{
|
||||
'Key': 'tag_key_1',
|
||||
'Value': 'tag_value_1'
|
||||
},
|
||||
{
|
||||
'Key': 'tag_key_2',
|
||||
'Value': 'tag_value_2'
|
||||
}
|
||||
]
|
||||
)
|
||||
topic_arn = response['TopicArn']
|
||||
|
||||
conn.untag_resource(
|
||||
ResourceArn = topic_arn,
|
||||
TagKeys = [
|
||||
'tag_key_1'
|
||||
]
|
||||
)
|
||||
conn.list_tags_for_resource(ResourceArn = topic_arn)['Tags'].should.equal([
|
||||
{
|
||||
'Key': 'tag_key_2',
|
||||
'Value': 'tag_value_2'
|
||||
}
|
||||
])
|
||||
|
||||
# removing a non existing tag should not raise any error
|
||||
conn.untag_resource(
|
||||
ResourceArn = topic_arn,
|
||||
TagKeys = [
|
||||
'not-existing-tag'
|
||||
]
|
||||
)
|
||||
conn.list_tags_for_resource(ResourceArn = topic_arn)['Tags'].should.equal([
|
||||
{
|
||||
'Key': 'tag_key_2',
|
||||
'Value': 'tag_value_2'
|
||||
}
|
||||
])
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_list_tags_for_resource_error():
|
||||
conn = boto3.client('sns', region_name = 'us-east-1')
|
||||
@ -361,3 +407,27 @@ def test_tag_resource_errors():
|
||||
'Value': 'tag_value_X'
|
||||
}
|
||||
])
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_untag_resource_error():
|
||||
conn = boto3.client('sns', region_name = 'us-east-1')
|
||||
conn.create_topic(
|
||||
Name = 'some-topic-with-tags',
|
||||
Tags = [
|
||||
{
|
||||
'Key': 'tag_key_1',
|
||||
'Value': 'tag_value_X'
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
conn.untag_resource.when.called_with(
|
||||
ResourceArn = 'not-existing-topic',
|
||||
TagKeys = [
|
||||
'tag_key_1'
|
||||
]
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'Resource does not exist'
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user