forked from jazzband/djangorestframework-simplejwt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_models.py
107 lines (72 loc) · 3.06 KB
/
test_models.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from django.test import TestCase
from rest_framework_simplejwt.models import TokenUser
from rest_framework_simplejwt.settings import api_settings
AuthToken = api_settings.AUTH_TOKEN_CLASSES[0]
class TestTokenUser(TestCase):
def setUp(self):
self.token = AuthToken()
self.token[api_settings.USER_ID_CLAIM] = 42
self.token['username'] = 'deep-thought'
self.token['some_other_stuff'] = 'arstarst'
self.user = TokenUser(self.token)
def test_username(self):
self.assertEqual(self.user.username, 'deep-thought')
def test_is_active(self):
self.assertTrue(self.user.is_active)
def test_str(self):
self.assertEqual(str(self.user), 'TokenUser 42')
def test_id(self):
self.assertEqual(self.user.id, 42)
def test_pk(self):
self.assertEqual(self.user.pk, 42)
def test_is_staff(self):
payload = {api_settings.USER_ID_CLAIM: 42}
user = TokenUser(payload)
self.assertFalse(user.is_staff)
payload['is_staff'] = True
user = TokenUser(payload)
self.assertTrue(user.is_staff)
def test_is_superuser(self):
payload = {api_settings.USER_ID_CLAIM: 42}
user = TokenUser(payload)
self.assertFalse(user.is_superuser)
payload['is_superuser'] = True
user = TokenUser(payload)
self.assertTrue(user.is_superuser)
def test_eq(self):
user1 = TokenUser({api_settings.USER_ID_CLAIM: 1})
user2 = TokenUser({api_settings.USER_ID_CLAIM: 2})
user3 = TokenUser({api_settings.USER_ID_CLAIM: 1})
self.assertNotEqual(user1, user2)
self.assertEqual(user1, user3)
def test_hash(self):
self.assertEqual(hash(self.user), hash(self.user.id))
def test_not_implemented(self):
with self.assertRaises(NotImplementedError):
self.user.save()
with self.assertRaises(NotImplementedError):
self.user.delete()
with self.assertRaises(NotImplementedError):
self.user.set_password('arst')
with self.assertRaises(NotImplementedError):
self.user.check_password('arst')
def test_groups(self):
self.assertFalse(self.user.groups.exists())
def test_user_permissions(self):
self.assertFalse(self.user.user_permissions.exists())
def test_get_group_permissions(self):
self.assertEqual(len(self.user.get_group_permissions()), 0)
def test_get_all_permissions(self):
self.assertEqual(len(self.user.get_all_permissions()), 0)
def test_has_perm(self):
self.assertFalse(self.user.has_perm('test_perm'))
def test_has_perms(self):
self.assertFalse(self.user.has_perms(['test_perm']))
def test_has_module_perms(self):
self.assertFalse(self.user.has_module_perms('test_module'))
def test_is_anonymous(self):
self.assertFalse(self.user.is_anonymous)
def test_is_authenticated(self):
self.assertTrue(self.user.is_authenticated)
def test_get_username(self):
self.assertEqual(self.user.get_username(), 'deep-thought')