forked from inventree/InvenTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
55 lines (38 loc) · 1.46 KB
/
test_api.py
File metadata and controls
55 lines (38 loc) · 1.46 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
"""API tests for various user / auth API endpoints"""
from django.contrib.auth.models import Group, User
from django.urls import reverse
from InvenTree.unit_test import InvenTreeAPITestCase
class UserAPITests(InvenTreeAPITestCase):
"""Tests for user API endpoints"""
def test_user_api(self):
"""Tests for User API endpoints"""
response = self.get(
reverse('api-user-list'),
expected_code=200
)
# Check the correct number of results was returned
self.assertEqual(len(response.data), User.objects.count())
for key in ['username', 'pk', 'email']:
self.assertIn(key, response.data[0])
# Check detail URL
pk = response.data[0]['pk']
response = self.get(
reverse('api-user-detail', kwargs={'pk': pk}),
expected_code=200
)
self.assertIn('pk', response.data)
self.assertIn('username', response.data)
def test_group_api(self):
"""Tests for the Group API endpoints"""
response = self.get(
reverse('api-group-list'),
expected_code=200,
)
self.assertIn('name', response.data[0])
self.assertEqual(len(response.data), Group.objects.count())
# Check detail URL
response = self.get(
reverse('api-group-detail', kwargs={'pk': response.data[0]['pk']}),
expected_code=200,
)
self.assertIn('name', response.data)