Ejemplo n.º 1
0
 def test_sms_receipts(self):
     """
     Receipts received from opera should update the status
     """
     [sms] = mock_sent_messages(self.user, count=1,
                                 transport_name="Opera",
                                 transport_msg_id="001efc31")
     self.assertEquals(sms.transport_status, '')
     
     raw_xml_post = """
     <?xml version="1.0"?>
     <!DOCTYPE receipts>
     <receipts>
       <receipt>
         <msgid>26567958</msgid>
         <reference>001efc31</reference>
         <msisdn>+27123456789</msisdn>
         <status>D</status>
         <timestamp>20080831T15:59:24</timestamp>
         <billed>NO</billed>
       </receipt>
     </receipts>
     """
     
     resp = self.client.post(reverse('api:opera:sms-receipt'), 
                             raw_xml_post.strip(), content_type='text/xml')
     sms = SentSMS.objects.get(pk=sms.pk) # reload
     self.assertEquals(sms.transport_status, 'D')
     self.assertEquals(resp.status_code, 201)
Ejemplo n.º 2
0
 def test_multiple_statuses(self):
     smss = mock_sent_messages(self.user, count=10)
     sms_ids = map(lambda sms: int(sms.pk), smss)
     sms_ids.sort()
     resp = self.client.get(reverse('api:e-scape:sms-status-list'), {
         'id': sms_ids
     })
     from django.utils import simplejson
     json_smss = simplejson.loads(resp.content)
     json_sms_ids = map(lambda sms: int(sms['id']), json_smss)
     json_sms_ids.sort()
     self.assertEquals(sms_ids, json_sms_ids)
     self.assertEquals(resp.status_code, 200)
Ejemplo n.º 3
0
 def test_sms_receipts(self):
     """
     Receipts received from clickatell should update the status
     """
     [sms] = mock_sent_messages(self.user, count=1, 
                                 transport_name = 'Clickatell',
                                 transport_msg_id='a' * 32)
     self.assertEquals(sms.transport_status, '')
     resp = self.client.post(reverse('api:clickatell:sms-receipt'), {
         'apiMsgId': 'a' * 32,
         'cliMsgId': sms.pk,
         'status': 8, # OK
         'to': '27123456789',
         'from': '27123456789',
         'timestamp': int(time()),
         'charge': 0.3
     })
     self.assertEquals(resp.status_code, 201)
     sms = SentSMS.objects.get(pk=sms.pk) # reload
     self.assertEquals(sms.transport_status, '8')
Ejemplo n.º 4
0
 def test_sms_status_list_since(self):
     """
     Sorry this test needs some explanation. In the SentSMS model I'm using
     Django's `auto_now` and `auto_now_add` options to automatically 
     timestamp the `created_at` and `updated_at` values. Downside of this
     is that you now no longer can set these values from the code. The 
     fixture has a `SentSMS` entry from 2009. I'm using that date to make
     sure the `since` parameter gives us back that entry as well instead
     of only the most recent 50 ones (which I create manually in this test).
     """
     january_2009 = datetime(2009,01,01,0,0,0)
     new_smss = mock_sent_messages(self.user, count=50)
     resp = self.client.get(reverse('api:e-scape:sms-status-list'), {
         'since': january_2009
     })
     from django.utils import simplejson
     data = simplejson.loads(resp.content)
     self.assertEquals(len(data), 51) # respects the `since` parameter
                                     # overriding the `limit` parameter.
                                     # On top of the 50 newly created
                                     # entries it should also return the 
                                     # 51st entry which is one from 2009
                                     # in the fixtures file.
     self.assertEquals(resp.status_code, 200)