Commit b0a28dde77f88aa5c3ec7f8ed44141fb3ef49750

Authored by Andrew Buss
Exists in master

Merge branch 'master' of git.ucsd.edu:110swag/flashy-backend

Showing 1 changed file Inline Diff

flashcards/tests/test_api.py View file @ b0a28dd
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):
email = "test@flashy.cards" 8 8 email = "test@flashy.cards"
User.objects.create_user(email, email=email, password="1234") 9 9 User.objects.create_user(email, email=email, password="1234")
10 10
def test_login(self): 11 11 def test_login(self):
url = '/api/login' 12 12 url = '/api/login'
data = {'email': 'test@flashy.cards', 'password': '1234'} 13 13 data = {'email': 'test@flashy.cards', 'password': '1234'}
response = self.client.post(url, data, format='json') 14 14 response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, HTTP_200_OK) 15 15 self.assertEqual(response.status_code, HTTP_200_OK)
16 16
data = {'email': 'test@flashy.cards', 'password': '54321'} 17 17 data = {'email': 'test@flashy.cards', 'password': '54321'}
response = self.client.post(url, data, format='json') 18 18 response = self.client.post(url, data, format='json')
self.assertContains(response, 'Invalid email or password', status_code=400) 19 19 self.assertContains(response, 'Invalid email or password', status_code=400)
20 20
data = {'email': 'none@flashy.cards', 'password': '54321'} 21 21 data = {'email': 'none@flashy.cards', 'password': '54321'}
response = self.client.post(url, data, format='json') 22 22 response = self.client.post(url, data, format='json')
self.assertContains(response, 'Invalid email or password', status_code=400) 23 23 self.assertContains(response, 'Invalid email or password', status_code=400)
24 24
data = {'password': '54321'} 25 25 data = {'password': '54321'}
response = self.client.post(url, data, format='json') 26 26 response = self.client.post(url, data, format='json')
self.assertContains(response, 'Email is required', status_code=400) 27 27 self.assertContains(response, 'Email is required', status_code=400)
28 28
29 29
class RegistrationTest(APITestCase): 30 30 class RegistrationTest(APITestCase):
def test_create_account(self): 31 31 def test_create_account(self):
url = '/api/users/me' 32 32 url = '/api/users/me'
data = {'email': 'none@none.com', 'password': '1234'} 33 33 data = {'email': 'none@none.com', 'password': '1234'}
response = self.client.post(url, data, format='json') 34 34 response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, HTTP_201_CREATED) 35 35 self.assertEqual(response.status_code, HTTP_201_CREATED)
36 36
37
data = {'email': 'none@none.com', 'password': '1234'} 38 37 data = {'email': 'none@none.com', 'password': '1234'}
response = self.client.post('/api/login', data, format='json') 39 38 response = self.client.post('/api/login', data, format='json')
self.assertEqual(response.status_code, HTTP_200_OK) 40 39 self.assertEqual(response.status_code, HTTP_200_OK)
41 40
41
42 data = {'email': 'none@none.com'}