mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
12794 change User ref to get_user_model (#12905)
* 12794 change User ref to get_user_model * 12794 call get_user_model once in tests * 12794 call get_user_model once in tests * 12794 use settings.AUTH_USER_MODEL for FK reference
This commit is contained in:
@ -2,7 +2,7 @@ import inspect
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.urls import reverse
|
||||
from django.test import override_settings
|
||||
@ -26,6 +26,9 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
#
|
||||
# REST/GraphQL API Tests
|
||||
#
|
||||
|
@ -1,6 +1,6 @@
|
||||
import json
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
@ -27,7 +27,7 @@ class TestCase(_TestCase):
|
||||
def setUp(self):
|
||||
|
||||
# Create the test user and assign permissions
|
||||
self.user = User.objects.create_user(username='testuser')
|
||||
self.user = get_user_model().objects.create_user(username='testuser')
|
||||
self.add_permissions(*self.user_permissions)
|
||||
|
||||
# Initialize the test client
|
||||
|
@ -2,7 +2,8 @@ import logging
|
||||
import re
|
||||
from contextlib import contextmanager
|
||||
|
||||
from django.contrib.auth.models import Permission, User
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.utils.text import slugify
|
||||
|
||||
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
|
||||
@ -63,7 +64,7 @@ def create_test_user(username='testuser', permissions=None):
|
||||
"""
|
||||
Create a User with the given permissions.
|
||||
"""
|
||||
user = User.objects.create_user(username=username)
|
||||
user = get_user_model().objects.create_user(username=username)
|
||||
if permissions is None:
|
||||
permissions = ()
|
||||
for perm_name in permissions:
|
||||
|
Reference in New Issue
Block a user