mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-24 02:11:50 +01:00
Initial work on REST API endpoint for tokens
This commit is contained in:
@@ -2,7 +2,7 @@ from django.contrib.auth.models import Group, User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.urls import reverse
|
||||
|
||||
from users.models import ObjectPermission
|
||||
from users.models import ObjectPermission, Token
|
||||
from utilities.testing import APIViewTestCases, APITestCase
|
||||
from utilities.utils import deepmerge
|
||||
|
||||
@@ -75,6 +75,38 @@ class GroupTest(APIViewTestCases.APIViewTestCase):
|
||||
Group.objects.bulk_create(users)
|
||||
|
||||
|
||||
class TokenTest(APIViewTestCases.APIViewTestCase):
|
||||
model = Token
|
||||
brief_fields = ['display', 'id', 'key', 'url', 'write_enabled']
|
||||
bulk_update_data = {
|
||||
'description': 'New description',
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
tokens = (
|
||||
# We already start with one Token, created by the test class
|
||||
Token(user=self.user),
|
||||
Token(user=self.user),
|
||||
)
|
||||
# Use save() instead of bulk_create() to ensure keys get automatically generated
|
||||
for token in tokens:
|
||||
token.save()
|
||||
|
||||
self.create_data = [
|
||||
{
|
||||
'user': self.user.pk,
|
||||
},
|
||||
{
|
||||
'user': self.user.pk,
|
||||
},
|
||||
{
|
||||
'user': self.user.pk,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class ObjectPermissionTest(APIViewTestCases.APIViewTestCase):
|
||||
model = ObjectPermission
|
||||
brief_fields = ['actions', 'display', 'enabled', 'groups', 'id', 'name', 'object_types', 'url', 'users']
|
||||
|
||||
Reference in New Issue
Block a user