Implemented Add/RemovePermission + Tests
This commit is contained in:
parent
f7f80293c7
commit
ef8a97f6c3
@ -174,6 +174,7 @@ class SNSBackend(BaseBackend):
|
||||
self.region_name = region_name
|
||||
self.sms_attributes = {}
|
||||
self.opt_out_numbers = ['+447420500600', '+447420505401', '+447632960543', '+447632960028', '+447700900149', '+447700900550', '+447700900545', '+447700900907']
|
||||
self.permissions = {}
|
||||
|
||||
def reset(self):
|
||||
region_name = self.region_name
|
||||
|
@ -534,6 +534,30 @@ class SNSResponse(BaseResponse):
|
||||
template = self.response_template(OPT_IN_NUMBER_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
def add_permission(self):
|
||||
arn = self._get_param('TopicArn')
|
||||
label = self._get_param('Label')
|
||||
accounts = self._get_multi_param('AWSAccountId.member.')
|
||||
action = self._get_multi_param('ActionName.member.')
|
||||
|
||||
key = (arn, label)
|
||||
self.backend.permissions[key] = {'accounts': accounts, 'action': action}
|
||||
|
||||
template = self.response_template(ADD_PERMISSION)
|
||||
return template.render()
|
||||
|
||||
def remove_permission(self):
|
||||
arn = self._get_param('TopicArn')
|
||||
label = self._get_param('Label')
|
||||
|
||||
try:
|
||||
key = (arn, label)
|
||||
del self.backend.permissions[key]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
template = self.response_template(DEL_PERMISSION)
|
||||
return template.render()
|
||||
|
||||
|
||||
CREATE_TOPIC_TEMPLATE = """<CreateTopicResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
|
||||
@ -894,5 +918,16 @@ OPT_IN_NUMBER_TEMPLATE = """<OptInPhoneNumberResponse xmlns="http://sns.amazonaw
|
||||
<ResponseMetadata>
|
||||
<RequestId>4c61842c-0796-50ef-95ac-d610c0bc8cf8</RequestId>
|
||||
</ResponseMetadata>
|
||||
</OptInPhoneNumberResponse>
|
||||
"""
|
||||
</OptInPhoneNumberResponse>"""
|
||||
|
||||
ADD_PERMISSION = """<AddPermissionResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
|
||||
<ResponseMetadata>
|
||||
<RequestId>c046e713-c5ff-5888-a7bc-b52f0e4f1299</RequestId>
|
||||
</ResponseMetadata>
|
||||
</AddPermissionResponse>"""
|
||||
|
||||
DEL_PERMISSION = """<RemovePermissionResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
|
||||
<ResponseMetadata>
|
||||
<RequestId>e767cc9f-314b-5e1b-b283-9ea3fd4e38a3</RequestId>
|
||||
</ResponseMetadata>
|
||||
</RemovePermissionResponse>"""
|
||||
|
@ -82,3 +82,19 @@ def test_opt_in():
|
||||
response = conn.list_phone_numbers_opted_out()
|
||||
len(response['phoneNumbers']).should.be.greater_than(0)
|
||||
len(response['phoneNumbers']).should.be.lower_than(current_len)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_add_remove_permissions():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
|
||||
conn.add_permission(
|
||||
TopicArn='arn:aws:sns:us-east-1:000000000000:terry_test',
|
||||
Label='Test1234',
|
||||
AWSAccountId=['999999999999'],
|
||||
ActionName=['AddPermission']
|
||||
)
|
||||
conn.remove_permission(
|
||||
TopicArn='arn:aws:sns:us-east-1:000000000000:terry_test',
|
||||
Label='Test1234'
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user