Commit 60cf35d28b293d59dd66115207093fab0de93261
1 parent
c266643909
Exists in
master
fixed up login tests
Showing 1 changed file with 16 additions and 1 deletions Inline Diff
flashcards/tests/test_api.py
View file @
60cf35d
from flashcards.models import User | 1 | 1 | from flashcards.models import User | |
from rest_framework.status import HTTP_201_CREATED, HTTP_200_OK | 2 | 2 | from rest_framework.status import HTTP_201_CREATED, HTTP_200_OK | |
from rest_framework.test import APITestCase | 3 | 3 | from rest_framework.test import APITestCase | |
4 | 4 | |||
5 | 5 | |||
class LoginTests(APITestCase): | 6 | 6 | class LoginTests(APITestCase): | |
def setUp(self): | 7 | 7 | def setUp(self): | |
User.objects.create(email="test@flashy.cards", password='1234') | 8 | 8 | email = "test@flashy.cards" | |
9 | User.objects.create_user(email, email=email, password="1234") | |||
9 | 10 | |||
def test_login(self): | 10 | 11 | def test_login(self): | |
url = '/api/login' | 11 | 12 | url = '/api/login' | |
data = {'email': 'test@flashy.cards', 'password': '1234'} | 12 | 13 | data = {'email': 'test@flashy.cards', 'password': '1234'} | |
response = self.client.post(url, data, format='json') | 13 | 14 | response = self.client.post(url, data, format='json') | |
self.assertEqual(response.status_code, HTTP_200_OK) | 14 | 15 | self.assertEqual(response.status_code, HTTP_200_OK) | |
16 | ||||
17 | data = {'email': 'test@flashy.cards', 'password': '54321'} | |||
18 | response = self.client.post(url, data, format='json') | |||
19 | self.assertContains(response, 'Invalid email or password', status_code=400) | |||
20 | ||||
21 | data = {'email': 'none@flashy.cards', 'password': '54321'} | |||
22 | response = self.client.post(url, data, format='json') | |||
23 | self.assertContains(response, 'Invalid email or password', status_code=400) | |||
24 | ||||
25 | data = {'password': '54321'} | |||
26 | response = self.client.post(url, data, format='json') | |||
27 | self.assertContains(response, 'Email is required', status_code=400) | |||
15 | 28 | |||
16 | 29 | |||
class RegistrationTest(APITestCase): | 17 | 30 | class RegistrationTest(APITestCase): | |
def test_create_account(self): | 18 | 31 | def test_create_account(self): | |
url = '/api/users/me' | 19 | 32 | url = '/api/users/me' | |
data = {'email': 'none@none.com', 'password': '1234'} | 20 | 33 | data = {'email': 'none@none.com', 'password': '1234'} | |
response = self.client.post(url, data, format='json') | 21 | 34 | response = self.client.post(url, data, format='json') | |
self.assertEqual(response.status_code, HTTP_201_CREATED) | 22 | 35 | self.assertEqual(response.status_code, HTTP_201_CREATED) | |
23 | 36 |