Implemented OptInPhoneNumber + Tests
This commit is contained in:
parent
1281ac86d5
commit
f7f80293c7
@ -173,6 +173,7 @@ class SNSBackend(BaseBackend):
|
||||
self.platform_endpoints = {}
|
||||
self.region_name = region_name
|
||||
self.sms_attributes = {}
|
||||
self.opt_out_numbers = ['+447420500600', '+447420505401', '+447632960543', '+447632960028', '+447700900149', '+447700900550', '+447700900545', '+447700900907']
|
||||
|
||||
def reset(self):
|
||||
region_name = self.region_name
|
||||
|
@ -521,7 +521,19 @@ class SNSResponse(BaseResponse):
|
||||
|
||||
def list_phone_numbers_opted_out(self):
|
||||
template = self.response_template(LIST_OPTOUT_TEMPLATE)
|
||||
return template.render(opt_outs=['+447420500600', '+447420505401'])
|
||||
return template.render(opt_outs=self.backend.opt_out_numbers)
|
||||
|
||||
def opt_in_phone_number(self):
|
||||
number = self._get_param('phoneNumber')
|
||||
|
||||
try:
|
||||
self.backend.opt_out_numbers.remove(number)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
template = self.response_template(OPT_IN_NUMBER_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
|
||||
|
||||
CREATE_TOPIC_TEMPLATE = """<CreateTopicResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
|
||||
@ -876,3 +888,11 @@ LIST_OPTOUT_TEMPLATE = """<ListPhoneNumbersOptedOutResponse xmlns="http://sns.am
|
||||
<RequestId>985e196d-a237-51b6-b33a-4b5601276b38</RequestId>
|
||||
</ResponseMetadata>
|
||||
</ListPhoneNumbersOptedOutResponse>"""
|
||||
|
||||
OPT_IN_NUMBER_TEMPLATE = """<OptInPhoneNumberResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
|
||||
<OptInPhoneNumberResult/>
|
||||
<ResponseMetadata>
|
||||
<RequestId>4c61842c-0796-50ef-95ac-d610c0bc8cf8</RequestId>
|
||||
</ResponseMetadata>
|
||||
</OptInPhoneNumberResponse>
|
||||
"""
|
||||
|
@ -67,5 +67,18 @@ def test_list_opted_out():
|
||||
response = conn.list_phone_numbers_opted_out()
|
||||
|
||||
response.should.contain('phoneNumbers')
|
||||
response['phoneNumbers'].should.contain('+447420500600')
|
||||
response['phoneNumbers'].should.contain('+447420505401')
|
||||
len(response['phoneNumbers']).should.be.greater_than(0)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_opt_in():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
response = conn.list_phone_numbers_opted_out()
|
||||
current_len = len(response['phoneNumbers'])
|
||||
assert current_len > 0
|
||||
|
||||
conn.opt_in_phone_number(phoneNumber=response['phoneNumbers'][0])
|
||||
|
||||
response = conn.list_phone_numbers_opted_out()
|
||||
len(response['phoneNumbers']).should.be.greater_than(0)
|
||||
len(response['phoneNumbers']).should.be.lower_than(current_len)
|
||||
|
Loading…
Reference in New Issue
Block a user