2
0
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:
Matthias Mair
2025-02-06 00:42:55 +01:00
parent 60f0d8c133
commit ccc40e64a9

View File

@@ -40,7 +40,8 @@ class UserAPITests(InvenTreeAPITestCase):
def test_user_api(self):
"""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
self.assertEqual(len(response.data), User.objects.count())
@@ -58,6 +59,32 @@ class UserAPITests(InvenTreeAPITestCase):
self.assertIn('pk', 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):
"""Tests for the Group API endpoints."""
response = self.get(reverse('api-group-list'), expected_code=200)