-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_authentication.py
More file actions
63 lines (56 loc) · 1.76 KB
/
test_authentication.py
File metadata and controls
63 lines (56 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import django.test
import django.urls
import rest_framework.status
import rest_framework.test
import user.models
class AuthenticationTests(rest_framework.test.APITestCase):
def setUp(self):
self.client = rest_framework.test.APIClient()
super().setUp()
def tearDown(self):
user.models.User.objects.all().delete()
super().tearDown()
def test_valid_registration(self):
data = {
'name': 'Steve',
'surname': 'Jobs',
'email': 'minecraft.digger@gmail.com',
'password': 'SuperStrongPassword2000!',
'other': {'age': 23, 'country': 'gb'},
}
response = self.client.post(
django.urls.reverse('api-user:sign-up'),
data,
format='json',
)
self.assertEqual(
response.status_code,
rest_framework.status.HTTP_200_OK,
)
self.assertIn('access', response.data)
self.assertTrue(
user.models.User.objects.filter(
email='minecraft.digger@gmail.com',
).exists(),
)
def test_signin_success(self):
user.models.User.objects.create_user(
email='minecraft.digger@gmail.com',
name='Steve',
surname='Jobs',
password='SuperStrongPassword2000!',
other={'age': 23, 'country': 'gb'},
)
data = {
'email': 'minecraft.digger@gmail.com',
'password': 'SuperStrongPassword2000!',
}
response = self.client.post(
django.urls.reverse('api-user:sign-in'),
data,
format='json',
)
self.assertEqual(
response.status_code,
rest_framework.status.HTTP_200_OK,
)