class TestVertexBackendRequestContent(TestCase): def setUp(self): self.vertex_backend = VertexBackend() self.vertex_backend.set_extra_fields( username=TEST_USERNAME, password=TEST_PASSWORD, senderid=TEST_SENDER_ID, ) self.queued_sms = QueuedSMS(phone_number=TEST_PHONE_NUMBER, ) def test_params(self): self.queued_sms.text = TEST_TEXT_MESSAGE params = self.vertex_backend.populate_params(self.queued_sms) self.assertEqual(params['username'], TEST_USERNAME) self.assertEqual(params['pass'], TEST_PASSWORD) self.assertEqual(params['senderid'], TEST_SENDER_ID) self.assertEqual(params['response'], 'Y') self.assertEqual(params['dest_mobileno'], strip_plus(TEST_PHONE_NUMBER)) self.assertEqual(params['msgtype'], TEXT_MSG_TYPE) self.assertEqual(params['message'], TEST_TEXT_MESSAGE) self.queued_sms.text = TEST_UNICODE_MESSAGE params = self.vertex_backend.populate_params(self.queued_sms) self.assertEqual(params['message'], TEST_UNICODE_MESSAGE.encode('utf-8')) self.assertEqual(params['msgtype'], UNICODE_MSG_TYPE) def test_phone_number_is_valid(self): self.assertFalse(VertexBackend().phone_number_is_valid('+91')) self.assertFalse(VertexBackend().phone_number_is_valid('+123456789')) self.assertTrue(VertexBackend().phone_number_is_valid('+910123456789'))
def setUp(self): self.vertex_backend = VertexBackend() self.vertex_backend.set_extra_fields( username=TEST_USERNAME, password=TEST_PASSWORD, senderid=TEST_SENDER_ID, ) self.queued_sms = QueuedSMS(phone_number=TEST_PHONE_NUMBER, )
class TestVertexBackendResponseHandling(TestCase): def setUp(self): self.vertex_backend = VertexBackend() self.queued_sms = QueuedSMS() def test_handle_success(self): self.vertex_backend.handle_response(self.queued_sms, 200, TEST_SUCCESSFUL_RESPONSE) self.assertEqual(self.queued_sms.backend_message_id, TEST_SUCCESSFUL_RESPONSE) self.assertFalse(self.queued_sms.error) def test_handle_failure(self): self.assertFalse(self.queued_sms.error) self.vertex_backend.handle_response(self.queued_sms, 200, TEST_INCORRECT_NUMBER_RESPONSE) self.assertEqual(self.queued_sms.system_error_message, SMS.ERROR_INVALID_DESTINATION_NUMBER) self.assertTrue(self.queued_sms.error) with mock.patch( 'corehq.messaging.smsbackends.vertex.models.notify_exception' ) as exception_notifier: self.queued_sms.error = False self.vertex_backend.handle_response(self.queued_sms, 200, TEST_NON_CODE_MESSAGES) self.assertEqual(self.queued_sms.system_error_message, SMS.ERROR_TOO_MANY_UNSUCCESSFUL_ATTEMPTS) self.assertTrue(self.queued_sms.error) exception_notifier.assert_called_once_with( None, "Error with the Vertex SMS Backend: " + TEST_NON_CODE_MESSAGES) with mock.patch( 'corehq.messaging.smsbackends.vertex.models.notify_exception' ) as exception_notifier: self.queued_sms.error = False self.vertex_backend.handle_response(self.queued_sms, 200, TEST_FAILURE_RESPONSE) self.assertEqual(self.queued_sms.system_error_message, SMS.ERROR_TOO_MANY_UNSUCCESSFUL_ATTEMPTS) self.assertTrue(self.queued_sms.error) exception_notifier.assert_called_once_with( None, "Error with the Vertex SMS Backend: " + TEST_FAILURE_RESPONSE) with self.assertRaisesMessage( VertexBackendException, "Unrecognized response from Vertex gateway with {response_status_code} " "status code, response {response_text}".format( response_status_code=200, response_text=RANDOM_ERROR_MESSAGE)): self.vertex_backend.handle_response(self.queued_sms, 200, RANDOM_ERROR_MESSAGE)
class TestVertexBackendResponseHandling(TestCase): def setUp(self): self.vertex_backend = VertexBackend() self.queued_sms = QueuedSMS() def test_handle_success(self): self.vertex_backend.handle_response(self.queued_sms, 200, TEST_SUCCESSFUL_RESPONSE) self.assertEqual(self.queued_sms.backend_message_id, TEST_SUCCESSFUL_RESPONSE) self.assertFalse(self.queued_sms.error) def test_handle_failure(self): self.assertFalse(self.queued_sms.error) self.vertex_backend.handle_response(self.queued_sms, 200, TEST_INCORRECT_NUMBER_RESPONSE) self.assertEqual(self.queued_sms.system_error_message, SMS.ERROR_INVALID_DESTINATION_NUMBER) self.assertTrue(self.queued_sms.error) with mock.patch('corehq.messaging.smsbackends.vertex.models.notify_exception') as exception_notifier: self.queued_sms.error = False self.vertex_backend.handle_response(self.queued_sms, 200, TEST_NON_CODE_MESSAGES) self.assertEqual(self.queued_sms.system_error_message, SMS.ERROR_TOO_MANY_UNSUCCESSFUL_ATTEMPTS) self.assertTrue(self.queued_sms.error) exception_notifier.assert_called_once_with( None, "Error with the Vertex SMS Backend: " + TEST_NON_CODE_MESSAGES ) with mock.patch('corehq.messaging.smsbackends.vertex.models.notify_exception') as exception_notifier: self.queued_sms.error = False self.vertex_backend.handle_response(self.queued_sms, 200, TEST_FAILURE_RESPONSE) self.assertEqual(self.queued_sms.system_error_message, SMS.ERROR_TOO_MANY_UNSUCCESSFUL_ATTEMPTS) self.assertTrue(self.queued_sms.error) exception_notifier.assert_called_once_with( None, "Error with the Vertex SMS Backend: " + TEST_FAILURE_RESPONSE ) with self.assertRaisesMessage( VertexBackendException, "Unrecognized response from Vertex gateway with {response_status_code} " "status code, response {response_text}".format( response_status_code=200, response_text=RANDOM_ERROR_MESSAGE) ): self.vertex_backend.handle_response(self.queued_sms, 200, RANDOM_ERROR_MESSAGE)
def setUp(self): self.vertex_backend = VertexBackend() self.vertex_backend.set_extra_fields( username=TEST_USERNAME, password=TEST_PASSWORD, senderid=TEST_SENDER_ID, ) self.queued_sms = QueuedSMS( phone_number=TEST_PHONE_NUMBER, )
class TestVertexBackendRequestContent(TestCase): def setUp(self): self.vertex_backend = VertexBackend() self.vertex_backend.set_extra_fields( username=TEST_USERNAME, password=TEST_PASSWORD, senderid=TEST_SENDER_ID, ) self.queued_sms = QueuedSMS( phone_number=TEST_PHONE_NUMBER, ) def test_params(self): self.queued_sms.text = TEST_TEXT_MESSAGE params = self.vertex_backend.populate_params(self.queued_sms) self.assertEqual(params['username'], TEST_USERNAME) self.assertEqual(params['pass'], TEST_PASSWORD) self.assertEqual(params['senderid'], TEST_SENDER_ID) self.assertEqual(params['response'], 'Y') self.assertEqual(params['dest_mobileno'], strip_plus(TEST_PHONE_NUMBER)) self.assertEqual(params['msgtype'], TEXT_MSG_TYPE) self.assertEqual(params['message'], TEST_TEXT_MESSAGE) self.queued_sms.text = TEST_UNICODE_MESSAGE params = self.vertex_backend.populate_params(self.queued_sms) if six.PY3: self.assertEqual(params['message'], TEST_UNICODE_MESSAGE) self.assertEqual(params['msgtype'], TEXT_MSG_TYPE) else: self.assertEqual(params['message'].decode('utf-8'), TEST_UNICODE_MESSAGE) self.assertEqual(params['msgtype'], UNICODE_MSG_TYPE) def test_phone_number_is_valid(self): self.assertFalse(VertexBackend().phone_number_is_valid('+91')) self.assertFalse(VertexBackend().phone_number_is_valid('+123456789')) self.assertTrue(VertexBackend().phone_number_is_valid('+910123456789'))
def setUp(self): self.vertex_backend = VertexBackend() self.queued_sms = QueuedSMS()
def test_phone_number_is_valid(self): self.assertFalse(VertexBackend().phone_number_is_valid('+91')) self.assertFalse(VertexBackend().phone_number_is_valid('+123456789')) self.assertTrue(VertexBackend().phone_number_is_valid('+910123456789'))
def setUp(self): self.vertex_backend = VertexBackend() self.queued_sms = QueuedSMS()