mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Add tests & cleanup
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
class UserPreference:
|
||||
|
||||
"""
|
||||
Represents a configurable user preference.
|
||||
"""
|
||||
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x):
|
||||
self.label = label
|
||||
self.choices = choices
|
||||
|
@ -1,8 +1,6 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
from users.models import UserConfig
|
||||
|
||||
|
||||
class UserConfigTest(TestCase):
|
||||
|
||||
|
39
netbox/users/tests/test_preferences.py
Normal file
39
netbox/users/tests/test_preferences.py
Normal file
@ -0,0 +1,39 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import override_settings, TestCase
|
||||
|
||||
from users.preferences import UserPreference
|
||||
|
||||
|
||||
DEFAULT_USER_PREFERENCES = {
|
||||
'pagination': {
|
||||
'per_page': 250,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class UserPreferencesTest(TestCase):
|
||||
|
||||
def test_userpreference(self):
|
||||
CHOICES = (
|
||||
('foo', 'Foo'),
|
||||
('bar', 'Bar'),
|
||||
)
|
||||
kwargs = {
|
||||
'label': 'Test Preference',
|
||||
'choices': CHOICES,
|
||||
'default': CHOICES[0][0],
|
||||
'description': 'Description',
|
||||
}
|
||||
userpref = UserPreference(**kwargs)
|
||||
|
||||
self.assertEqual(userpref.label, kwargs['label'])
|
||||
self.assertEqual(userpref.choices, kwargs['choices'])
|
||||
self.assertEqual(userpref.default, kwargs['default'])
|
||||
self.assertEqual(userpref.description, kwargs['description'])
|
||||
|
||||
@override_settings(DEFAULT_USER_PREFERENCES=DEFAULT_USER_PREFERENCES)
|
||||
def test_default_preferences(self):
|
||||
user = User.objects.create(username='User 1')
|
||||
userconfig = user.config
|
||||
|
||||
self.assertEqual(userconfig.data, DEFAULT_USER_PREFERENCES)
|
Reference in New Issue
Block a user