def test_normal_post_error(self, sms_mock): """Should not send sms and should return the form with error message.""" req = self.rf.post('/', {'number': '8675309'}) resp = views.sms_send(req) self.assertEqual(resp.status_code, 200) self.assertContains(resp, u'Sorry. This number isn\'t valid.') self.assertFalse(sms_mock.called)
def test_normal_basket_error(self, sms_mock): """Should not send sms and should return the form with error message.""" sms_mock.side_effect = views.basket.BasketException req = self.rf.post('/', {'number': '5558675309'}) resp = views.sms_send(req) sms_mock.assert_called_with('15558675309', 'SMS_Android', False) self.assertEqual(resp.status_code, 200) self.assertContains(resp, u'An error occurred in our system. Please try again later.')
def test_ajax_post_success(self, sms_mock): """Should send sms and return a JSON response.""" req = self.rf.post('/', {'number': '5558675309'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') resp = views.sms_send(req) sms_mock.assert_called_with('15558675309', 'SMS_Android', False) self.assertEqual(resp.status_code, 200) resp_data = json.loads(resp.content) self.assertEqual(resp_data, {'success': True})
def test_normal_basket_error(self, sms_mock): """Should not send sms and should return the form with error message.""" sms_mock.side_effect = views.basket.BasketException req = self.rf.post('/', {'number': '5558675309'}) resp = views.sms_send(req) sms_mock.assert_called_with('15558675309', 'SMS_Android', False) self.assertEqual(resp.status_code, 200) self.assertContains( resp, u'An error occurred in our system. Please try again later.')
def test_ajax_post_error(self, sms_mock): """Should not send sms and should return a JSON response.""" req = self.rf.post('/', {'number': '8675309'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') resp = views.sms_send(req) self.assertFalse(sms_mock.called) self.assertEqual(resp.status_code, 200) resp_data = json.loads(resp.content) self.assertFalse(resp_data['success']) self.assertIn(u'Sorry. This number isn\'t valid.', resp_data['error'])
def test_ajax_basket_error(self, sms_mock): """Should not send sms and should return a JSON response.""" sms_mock.side_effect = views.basket.BasketException req = self.rf.post('/', {'number': '5558675309'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') resp = views.sms_send(req) sms_mock.assert_called_with('15558675309', 'SMS_Android', False) self.assertEqual(resp.status_code, 200) resp_data = json.loads(resp.content) self.assertEqual(resp_data, { 'success': False, 'error': u'An error occurred in our system. Please try again later.', })
def test_ajax_basket_error(self, sms_mock): """Should not send sms and should return a JSON response.""" sms_mock.side_effect = views.basket.BasketException req = self.rf.post('/', {'number': '5558675309'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') resp = views.sms_send(req) sms_mock.assert_called_with('15558675309', 'SMS_Android', False) self.assertEqual(resp.status_code, 200) resp_data = json.loads(resp.content) self.assertEqual( resp_data, { 'success': False, 'error': u'An error occurred in our system. Please try again later.', })
def test_normal_post_success(self, sms_mock): """Should send sms and return a redirect.""" req = self.rf.post('/', {'number': '5558675309'}) resp = views.sms_send(req) sms_mock.assert_called_with('15558675309', 'SMS_Android', False) self.assertEqual(resp.status_code, 302)