diff --git a/flashcards/tests/test_api.py b/flashcards/tests/test_api.py index aeb7ab8..b73410c 100644 --- a/flashcards/tests/test_api.py +++ b/flashcards/tests/test_api.py @@ -5,7 +5,8 @@ from rest_framework.test import APITestCase class LoginTests(APITestCase): def setUp(self): - User.objects.create(email="test@flashy.cards", password='1234') + email = "test@flashy.cards" + User.objects.create_user(email, email=email, password="1234") def test_login(self): url = '/api/login' @@ -13,6 +14,18 @@ class LoginTests(APITestCase): response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, HTTP_200_OK) + data = {'email': 'test@flashy.cards', 'password': '54321'} + response = self.client.post(url, data, format='json') + self.assertContains(response, 'Invalid email or password', status_code=400) + + data = {'email': 'none@flashy.cards', 'password': '54321'} + response = self.client.post(url, data, format='json') + self.assertContains(response, 'Invalid email or password', status_code=400) + + data = {'password': '54321'} + response = self.client.post(url, data, format='json') + self.assertContains(response, 'Email is required', status_code=400) + class RegistrationTest(APITestCase): def test_create_account(self): diff --git a/flashcards/tests/test_models.py b/flashcards/tests/test_models.py index aca606b..35a8ae5 100644 --- a/flashcards/tests/test_models.py +++ b/flashcards/tests/test_models.py @@ -19,3 +19,5 @@ class UserTests(TestCase): self.assertIn(section, user.sections.all()) user.sections.add(section) self.assertEqual(user.sections.count(), 1) + +