-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
40 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
import datetime | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.models import Group | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.test import TestCase | ||
from django.utils.timezone import make_aware | ||
|
||
from users import filtersets | ||
from users.models import ObjectPermission, Token | ||
from users.models import ObjectPermission, Token, NetBoxUser | ||
from utilities.testing import BaseFilterSetTests | ||
|
||
User = get_user_model() | ||
|
||
|
||
class UserTestCase(TestCase, BaseFilterSetTests): | ||
queryset = User.objects.all() | ||
queryset = NetBoxUser.objects.all() | ||
filterset = filtersets.UserFilterSet | ||
|
||
@classmethod | ||
|
@@ -28,40 +25,40 @@ def setUpTestData(cls): | |
Group.objects.bulk_create(groups) | ||
|
||
users = ( | ||
User( | ||
NetBoxUser( | ||
username='User1', | ||
first_name='Hank', | ||
last_name='Hill', | ||
email='[email protected]', | ||
is_staff=True, | ||
is_superuser=True | ||
), | ||
User( | ||
NetBoxUser( | ||
username='User2', | ||
first_name='Dale', | ||
last_name='Gribble', | ||
email='[email protected]' | ||
), | ||
User( | ||
NetBoxUser( | ||
username='User3', | ||
first_name='Bill', | ||
last_name='Dauterive', | ||
email='[email protected]' | ||
), | ||
User( | ||
NetBoxUser( | ||
username='User4', | ||
first_name='Jeff', | ||
last_name='Boomhauer', | ||
email='[email protected]' | ||
), | ||
User( | ||
NetBoxUser( | ||
username='User5', | ||
first_name='Debbie', | ||
last_name='Grund', | ||
is_active=False | ||
) | ||
) | ||
User.objects.bulk_create(users) | ||
NetBoxUser.objects.bulk_create(users) | ||
|
||
users[0].groups.set([groups[0]]) | ||
users[1].groups.set([groups[1]]) | ||
|
@@ -145,11 +142,11 @@ def setUpTestData(cls): | |
Group.objects.bulk_create(groups) | ||
|
||
users = ( | ||
User(username='User1'), | ||
User(username='User2'), | ||
User(username='User3'), | ||
NetBoxUser(username='User1'), | ||
NetBoxUser(username='User2'), | ||
NetBoxUser(username='User3'), | ||
) | ||
User.objects.bulk_create(users) | ||
NetBoxUser.objects.bulk_create(users) | ||
|
||
object_types = ( | ||
ContentType.objects.get(app_label='dcim', model='site'), | ||
|
@@ -192,7 +189,7 @@ def test_group(self): | |
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) | ||
|
||
def test_user(self): | ||
users = User.objects.filter(username__in=['User1', 'User2']) | ||
users = NetBoxUser.objects.filter(username__in=['User1', 'User2']) | ||
params = {'user_id': [users[0].pk, users[1].pk]} | ||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) | ||
params = {'user': [users[0].username, users[1].username]} | ||
|
@@ -232,11 +229,11 @@ class TokenTestCase(TestCase, BaseFilterSetTests): | |
def setUpTestData(cls): | ||
|
||
users = ( | ||
User(username='User1'), | ||
User(username='User2'), | ||
User(username='User3'), | ||
NetBoxUser(username='User1'), | ||
NetBoxUser(username='User2'), | ||
NetBoxUser(username='User3'), | ||
) | ||
User.objects.bulk_create(users) | ||
NetBoxUser.objects.bulk_create(users) | ||
|
||
future_date = make_aware(datetime.datetime(3000, 1, 1)) | ||
past_date = make_aware(datetime.datetime(2000, 1, 1)) | ||
|
@@ -252,7 +249,7 @@ def test_q(self): | |
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) | ||
|
||
def test_user(self): | ||
users = User.objects.order_by('id')[:2] | ||
users = NetBoxUser.objects.order_by('id')[:2] | ||
params = {'user_id': [users[0].pk, users[1].pk]} | ||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) | ||
params = {'user': [users[0].username, users[1].username]} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters