From 60cf35d28b293d59dd66115207093fab0de93261 Mon Sep 17 00:00:00 2001 From: Andrew Buss <abuss@ucsd.edu> Date: Fri, 1 May 2015 12:32:22 -0700 Subject: [PATCH] fixed up login tests --- flashcards/tests/test_api.py | 15 ++++++++++++++- flashcards/tests/test_models.py | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) 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) + + -- 1.9.1