Example #1
0
 def test_dont_send_msg_if_sms_field_set(self):
     # set the sms field
     self.bulk_msg.sms = SMSFactory()
     self.bulk_msg.save()
     send_message_by_id(self.bulk_msg.pk)
     # no message sent
     self.assertEqual(len(self.outbound), 0)
Example #2
0
 def target(pk):
     # wait until all threads have started before attempting to send
     trigger.wait()
     send_message_by_id(pk)
     # workaround https://code.djangoproject.com/ticket/22420
     for conn in django_db_connections.all():
         conn.close()
Example #3
0
 def test_endpoint_gets_saved_to_sms_object(self):
     self.bulk_msg.from_shortcode = settings.REPORTS_SHORT_CODE
     self.bulk_msg.save()
     # send message
     send_message_by_id(self.bulk_msg.pk)
     sms = BulkMessage.objects.get(id=self.bulk_msg.id).sms
     self.assertEqual(sms.from_number, settings.REPORTS_SHORT_CODE)
Example #4
0
 def test_dont_send_msg_if_sms_field_set(self):
     # set the sms field
     self.bulk_msg.sms = SMSFactory()
     self.bulk_msg.save()
     send_message_by_id(self.bulk_msg.pk)
     # no message sent
     self.assertEqual(len(self.outbound), 0)
Example #5
0
 def test_endpoint_gets_saved_to_sms_object(self):
     self.bulk_msg.from_shortcode = settings.REPORTS_SHORT_CODE
     self.bulk_msg.save()
     # send message
     send_message_by_id(self.bulk_msg.pk)
     sms = BulkMessage.objects.get(id=self.bulk_msg.id).sms
     self.assertEqual(sms.from_number, settings.REPORTS_SHORT_CODE)
Example #6
0
 def test_endpoint_is_passed_to_backend(self, mock_send_to_backend):
     # mock sending the message to check what params we send to the backend
     send_message_by_id(self.bulk_msg.pk)
     self.assertTrue(mock_send_to_backend.called)
     call_args, call_kwargs = mock_send_to_backend.call_args
     # by default, we should send endpoint=REGISTRATION_SHORT_CODE
     self.assertEqual(call_kwargs['context'], {'endpoint': settings.REGISTRATION_SHORT_CODE})
Example #7
0
 def target(pk):
     # wait until all threads have started before attempting to send
     trigger.wait()
     send_message_by_id(pk)
     # workaround https://code.djangoproject.com/ticket/22420
     for conn in django_db_connections.all():
         conn.close()
Example #8
0
 def test_endpoint_is_passed_to_backend(self, mock_send_to_backend):
     # mock sending the message to check what params we send to the backend
     send_message_by_id(self.bulk_msg.pk)
     self.assertTrue(mock_send_to_backend.called)
     call_args, call_kwargs = mock_send_to_backend.call_args
     # by default, we should send endpoint=REGISTRATION_SHORT_CODE
     self.assertEqual(call_kwargs['context'],
                      {'endpoint': settings.REGISTRATION_SHORT_CODE})
Example #9
0
 def test_endpoint_passed_to_backend_is_customizable(self):
     self.bulk_msg.from_shortcode = settings.REPORTS_SHORT_CODE
     self.bulk_msg.save()
     # send message
     with patch.object(LowLevelTestRouter, 'send_to_backend') as mock_send_to_backend:
         send_message_by_id(self.bulk_msg.pk)
     self.assertTrue(mock_send_to_backend.called)
     call_args, call_kwargs = mock_send_to_backend.call_args
     self.assertEqual(call_kwargs['context'], {'endpoint': settings.REPORTS_SHORT_CODE})
Example #10
0
 def test_endpoint_passed_to_backend_is_customizable(self):
     self.bulk_msg.from_shortcode = settings.REPORTS_SHORT_CODE
     self.bulk_msg.save()
     # send message
     with patch.object(LowLevelTestRouter,
                       'send_to_backend') as mock_send_to_backend:
         send_message_by_id(self.bulk_msg.pk)
     self.assertTrue(mock_send_to_backend.called)
     call_args, call_kwargs = mock_send_to_backend.call_args
     self.assertEqual(call_kwargs['context'],
                      {'endpoint': settings.REPORTS_SHORT_CODE})
Example #11
0
 def test_send_one_bulk_message(self):
     # send message
     send_message_by_id(self.bulk_msg.pk)
     # -> sms is no longer 'None'
     sms = BulkMessage.objects.get(id=self.bulk_msg.id).sms
     self.assertTrue(sms)
     # -> from_number is REGISTRATION_SHORT_CODE (default)
     self.assertEqual(sms.from_number, settings.REGISTRATION_SHORT_CODE)
     # -> to_number is the phone number from the BulkMessage
     self.assertEqual(sms.to_number, self.bulk_msg.phone_number)
     # -> message is the message from the BulkMessage
     self.assertEqual(sms.message, self.bulk_msg.message)
     self.assertEqual(len(self.outbound), 1)
Example #12
0
 def test_send_one_bulk_message(self):
     # send message
     send_message_by_id(self.bulk_msg.pk)
     # -> sms is no longer 'None'
     sms = BulkMessage.objects.get(id=self.bulk_msg.id).sms
     self.assertTrue(sms)
     # -> from_number is REGISTRATION_SHORT_CODE (default)
     self.assertEqual(sms.from_number, settings.REGISTRATION_SHORT_CODE)
     # -> to_number is the phone number from the BulkMessage
     self.assertEqual(sms.to_number, self.bulk_msg.phone_number)
     # -> message is the message from the BulkMessage
     self.assertEqual(sms.message, self.bulk_msg.message)
     self.assertEqual(len(self.outbound), 1)
Example #13
0
 def test_send_to_existing_connection(self, send_to_backend):
     """
     Ensure bulk messages to phone numbers with existing connections use that
     connection. This helps ensure (but does not guarantee) that messages to
     Thuraya phones won't be sent over Madar or Libyana.
     """
     # use a backend that's available in the test environment but not
     # in BULKSMS_BACKENDS
     conn = ConnectionFactory(identity=self.bulk_msg.phone_number,
                              backend__name=settings.HTTPTESTER_BACKEND)
     old_count = Connection.objects.all().count()
     # send message
     send_message_by_id(self.bulk_msg.pk)
     # make sure send_to_backend was called with the correct backend name and
     # identity
     self.assertEqual(send_to_backend.call_count, 1)
     self.assertEqual(send_to_backend.call_args[1]['backend_name'], conn.backend.name)
     self.assertEqual(send_to_backend.call_args[1]['identities'], [conn.identity])
     # make sure no new connection object was created:
     new_count = Connection.objects.all().count()
     self.assertEqual(old_count, new_count)
Example #14
0
 def test_send_to_existing_connection(self, send_to_backend):
     """
     Ensure bulk messages to phone numbers with existing connections use that
     connection. This helps ensure (but does not guarantee) that messages to
     Thuraya phones won't be sent over Madar or Libyana.
     """
     # use a backend that's available in the test environment but not
     # in BULKSMS_BACKENDS
     conn = ConnectionFactory(identity=self.bulk_msg.phone_number,
                              backend__name=settings.HTTPTESTER_BACKEND)
     old_count = Connection.objects.all().count()
     # send message
     send_message_by_id(self.bulk_msg.pk)
     # make sure send_to_backend was called with the correct backend name and
     # identity
     self.assertEqual(send_to_backend.call_count, 1)
     self.assertEqual(send_to_backend.call_args[1]['backend_name'],
                      conn.backend.name)
     self.assertEqual(send_to_backend.call_args[1]['identities'],
                      [conn.identity])
     # make sure no new connection object was created:
     new_count = Connection.objects.all().count()
     self.assertEqual(old_count, new_count)
Example #15
0
 def test_send_to_invalid_id(self):
     """
     Ensure sending to an invalid ID returns gracefully
     """
     self.assertEqual(send_message_by_id(9999999), 0)
Example #16
0
 def test_dont_send_msg_if_batch_inactive(self):
     self.batch.status = Batch.PENDING
     self.batch.save()
     send_message_by_id(self.bulk_msg.pk)
     # no message sent
     self.assertEqual(len(self.outbound), 0)
Example #17
0
 def test_dont_send_msg_if_batch_inactive(self):
     self.batch.status = Batch.PENDING
     self.batch.save()
     send_message_by_id(self.bulk_msg.pk)
     # no message sent
     self.assertEqual(len(self.outbound), 0)
Example #18
0
 def test_send_to_invalid_id(self):
     """
     Ensure sending to an invalid ID returns gracefully
     """
     self.assertEqual(send_message_by_id(9999999), 0)