mirror of
https://github.com/inventree/InvenTree.git
synced 2025-09-15 15:11:34 +00:00
test user create api
This commit is contained in:
@@ -40,7 +40,8 @@ class UserAPITests(InvenTreeAPITestCase):
|
|||||||
|
|
||||||
def test_user_api(self):
|
def test_user_api(self):
|
||||||
"""Tests for User API endpoints."""
|
"""Tests for User API endpoints."""
|
||||||
response = self.get(reverse('api-user-list'), expected_code=200)
|
url = reverse('api-user-list')
|
||||||
|
response = self.get(url, expected_code=200)
|
||||||
|
|
||||||
# Check the correct number of results was returned
|
# Check the correct number of results was returned
|
||||||
self.assertEqual(len(response.data), User.objects.count())
|
self.assertEqual(len(response.data), User.objects.count())
|
||||||
@@ -58,6 +59,32 @@ class UserAPITests(InvenTreeAPITestCase):
|
|||||||
self.assertIn('pk', response.data)
|
self.assertIn('pk', response.data)
|
||||||
self.assertIn('username', response.data)
|
self.assertIn('username', response.data)
|
||||||
|
|
||||||
|
# Test create user
|
||||||
|
response = self.post(url, expected_code=403)
|
||||||
|
self.assertIn(
|
||||||
|
'You do not have permission to perform this action.', str(response.data)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
|
||||||
|
response = self.post(
|
||||||
|
url,
|
||||||
|
data={
|
||||||
|
'username': 'test',
|
||||||
|
'first_name': 'Test',
|
||||||
|
'last_name': 'User',
|
||||||
|
'email': 'aa@example.org',
|
||||||
|
},
|
||||||
|
expected_code=201,
|
||||||
|
)
|
||||||
|
self.assertEqual(response.data['username'], 'test')
|
||||||
|
self.assertEqual(response.data['first_name'], 'Test')
|
||||||
|
self.assertEqual(response.data['last_name'], 'User')
|
||||||
|
self.assertEqual(response.data['is_staff'], False)
|
||||||
|
self.assertEqual(response.data['is_superuser'], False)
|
||||||
|
self.assertEqual(response.data['is_active'], True)
|
||||||
|
|
||||||
def test_group_api(self):
|
def test_group_api(self):
|
||||||
"""Tests for the Group API endpoints."""
|
"""Tests for the Group API endpoints."""
|
||||||
response = self.get(reverse('api-group-list'), expected_code=200)
|
response = self.get(reverse('api-group-list'), expected_code=200)
|
||||||
|
Reference in New Issue
Block a user