Commit 4af65c21daa9090ef7e7ff572e34b368718a408c
1 parent
1b23b2c217
Exists in
master
Expanded tests somewhat
Showing 2 changed files with 26 additions and 4 deletions Side-by-side Diff
flashcards/tests/test_api.py
View file @
4af65c2
1 | +from django.core import mail | |
1 | 2 | from flashcards.models import User |
2 | -from rest_framework.status import HTTP_201_CREATED, HTTP_200_OK, HTTP_403_FORBIDDEN, HTTP_401_UNAUTHORIZED | |
3 | +from rest_framework.status import HTTP_201_CREATED, HTTP_200_OK, HTTP_401_UNAUTHORIZED | |
3 | 4 | from rest_framework.test import APITestCase |
4 | 5 | |
5 | 6 | |
6 | 7 | |
7 | 8 | |
... | ... | @@ -26,13 +27,21 @@ |
26 | 27 | response = self.client.post(url, data, format='json') |
27 | 28 | self.assertContains(response, 'email', status_code=400) |
28 | 29 | |
30 | + data = {'email': 'none@flashy.cards'} | |
31 | + response = self.client.post(url, data, format='json') | |
32 | + self.assertContains(response, 'password', status_code=400) | |
29 | 33 | |
34 | + | |
30 | 35 | class RegistrationTest(APITestCase): |
31 | 36 | def test_create_account(self): |
32 | 37 | url = '/api/users/me' |
33 | 38 | data = {'email': 'none@none.com', 'password': '1234'} |
34 | 39 | response = self.client.post(url, data, format='json') |
35 | 40 | self.assertEqual(response.status_code, HTTP_201_CREATED) |
41 | + | |
42 | + user = User.objects.get(email="none@none.com") | |
43 | + self.assertEqual(len(mail.outbox), 1) | |
44 | + self.assertIn(user.confirmation_key, mail.outbox[0].body) | |
36 | 45 | |
37 | 46 | data = {'email': 'none@none.com', 'password': '1234'} |
38 | 47 | response = self.client.post('/api/login', data, format='json') |
flashcards/tests/test_models.py
View file @
4af65c2
1 | 1 | from django.test import TestCase |
2 | 2 | from flashcards.models import User, Section |
3 | +from simple_email_confirmation import EmailAddress | |
3 | 4 | |
4 | 5 | |
6 | +class RegistrationTests(TestCase): | |
7 | + def setUp(self): | |
8 | + User.objects.create_user(email="none@none.com", password="1234") | |
9 | + | |
10 | + def test_email_confirmation(self): | |
11 | + user = User.objects.get(email="none@none.com") | |
12 | + self.assertFalse(user.is_confirmed) | |
13 | + user.confirm_email(user.confirmation_key) | |
14 | + self.assertTrue(user.is_confirmed) | |
15 | + | |
16 | + | |
5 | 17 | class UserTests(TestCase): |
6 | 18 | def setUp(self): |
7 | - User.objects.create(email="none@none.com", password="1234") | |
19 | + User.objects.create_user(email="none@none.com", password="1234") | |
8 | 20 | Section.objects.create(department='dept', |
9 | 21 | course_num='101a', |
10 | 22 | course_title='how 2 test', |
... | ... | @@ -19,4 +31,6 @@ |
19 | 31 | self.assertIn(section, user.sections.all()) |
20 | 32 | user.sections.add(section) |
21 | 33 | self.assertEqual(user.sections.count(), 1) |
34 | + user.sections.remove(section) | |
35 | + self.assertEqual(user.sections.count(), 0) |