-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathtest_users.py
More file actions
34 lines (22 loc) · 1009 Bytes
/
test_users.py
File metadata and controls
34 lines (22 loc) · 1009 Bytes
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
from __future__ import unicode_literals
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):
url = '/v2/users/'
user = User.objects.get(username='autotest')
token = Token.objects.get(user=user)
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):
url = '/v2/users/'
user = User.objects.get(username='autotest2')
token = Token.objects.get(user=user)
response = self.client.get(url,
HTTP_AUTHORIZATION='token {}'.format(token))
self.assertEqual(response.status_code, 403)