def test_no_email(self, requests_mock): requests_mock.return_value = FakeResponse(200, "ok") no_email_request = self.request.post(reverse("subscribe")) no_email_response = ajax_subscribe(no_email_request) self.assertEqual(no_email_response.status_code, 200) self.assertContains(no_email_response, "Failed") self.assertFalse(requests_mock.called)
def test_valid_email(self, requests_mock): requests_mock.return_value = FakeResponse(200, "ok") valid_email = "*****@*****.**" valid_email_request = self.request.post(reverse("subscribe"), {"email": valid_email}) valid_email_response = ajax_subscribe(valid_email_request) self.assertEqual(valid_email_response.status_code, 200) self.assertContains(valid_email_response, "OK") self.assertTrue(requests_mock.called)
def test_email_fail(self, requests_mock): requests_mock.return_value = MagicMock(status_code=200, json={'error': "wrong_code"}) response = ajax_subscribe(self.request) self.assertContains(response, 'Failed')
def test_email_ok(self, requests_mock): requests_mock.return_value = FakeResponse(200, "ok") response = ajax_subscribe(self.request) self.assertContains(response, 'OK')
def test_email_fail(self, requests_mock): requests_mock.return_value = MagicMock(status_code=200, json={ 'error': "wrong_code" }) response = ajax_subscribe(self.request) self.assertContains(response, 'Failed')