-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathtest_users.py
More file actions
30 lines (21 loc) · 1.01 KB
/
test_users.py
File metadata and controls
30 lines (21 loc) · 1.01 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
from django.contrib.auth.models import User
from django.test import TestCase
from rest_framework.authtoken.models import Token
class TestUsers(TestCase):
""" Tests users endpoint"""
fixtures = ['tests.json']
def test_super_user_can_list(self):
user = User.objects.get(username='autotest')
token = Token.objects.get(user=user)
for url in ['/v2/users', '/v2/users/']:
response = self.client.get(url,
HTTP_AUTHORIZATION='token {}'.format(token))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['results']), 3)
def test_non_super_user_cannot_list(self):
user = User.objects.get(username='autotest2')
token = Token.objects.get(user=user)
for url in ['/v2/users', '/v2/users/']:
response = self.client.get(url,
HTTP_AUTHORIZATION='token {}'.format(token))
self.assertEqual(response.status_code, 403)