mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Convert extras view tests to StandardTestCases
This commit is contained in:
parent
c9d0dcecf3
commit
ab7b921641
@ -7,44 +7,47 @@ from django.urls import reverse
|
|||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from extras.choices import ObjectChangeActionChoices
|
from extras.choices import ObjectChangeActionChoices
|
||||||
from extras.models import ConfigContext, ObjectChange, Tag
|
from extras.models import ConfigContext, ObjectChange, Tag
|
||||||
from utilities.testing import TestCase
|
from utilities.testing import StandardTestCases, TestCase
|
||||||
|
|
||||||
|
|
||||||
class TagTestCase(TestCase):
|
class TagTestCase(StandardTestCases.Views):
|
||||||
user_permissions = (
|
model = Tag
|
||||||
'extras.view_tag',
|
|
||||||
)
|
# Disable inapplicable tests
|
||||||
|
test_create_object = None
|
||||||
|
test_import_objects = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
|
||||||
Tag.objects.bulk_create([
|
Tag.objects.bulk_create((
|
||||||
Tag(name='Tag 1', slug='tag-1'),
|
Tag(name='Tag 1', slug='tag-1'),
|
||||||
Tag(name='Tag 2', slug='tag-2'),
|
Tag(name='Tag 2', slug='tag-2'),
|
||||||
Tag(name='Tag 3', slug='tag-3'),
|
Tag(name='Tag 3', slug='tag-3'),
|
||||||
])
|
))
|
||||||
|
|
||||||
def test_tag_list(self):
|
cls.form_data = {
|
||||||
|
'name': 'Tag X',
|
||||||
url = reverse('extras:tag_list')
|
'slug': 'tag-x',
|
||||||
params = {
|
'color': 'c0c0c0',
|
||||||
"q": "tag",
|
'comments': 'Some comments',
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)))
|
|
||||||
self.assertHttpStatus(response, 200)
|
|
||||||
|
|
||||||
|
class ConfigContextTestCase(StandardTestCases.Views):
|
||||||
|
model = ConfigContext
|
||||||
|
|
||||||
class ConfigContextTestCase(TestCase):
|
# Disable inapplicable tests
|
||||||
user_permissions = (
|
test_import_objects = None
|
||||||
'extras.view_configcontext',
|
|
||||||
)
|
# TODO: Resolve model discrepancies when creating/editing ConfigContexts
|
||||||
|
test_create_object = None
|
||||||
|
test_edit_object = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
|
||||||
site = Site(name='Site 1', slug='site-1')
|
site = Site.objects.create(name='Site 1', slug='site-1')
|
||||||
site.save()
|
|
||||||
|
|
||||||
# Create three ConfigContexts
|
# Create three ConfigContexts
|
||||||
for i in range(1, 4):
|
for i in range(1, 4):
|
||||||
@ -55,22 +58,21 @@ class ConfigContextTestCase(TestCase):
|
|||||||
configcontext.save()
|
configcontext.save()
|
||||||
configcontext.sites.add(site)
|
configcontext.sites.add(site)
|
||||||
|
|
||||||
def test_configcontext_list(self):
|
cls.form_data = {
|
||||||
|
'name': 'Config Context X',
|
||||||
url = reverse('extras:configcontext_list')
|
'weight': 200,
|
||||||
params = {
|
'description': 'A new config context',
|
||||||
"q": "foo",
|
'is_active': True,
|
||||||
|
'regions': [],
|
||||||
|
'sites': [site.pk],
|
||||||
|
'roles': [],
|
||||||
|
'platforms': [],
|
||||||
|
'tenant_groups': [],
|
||||||
|
'tenants': [],
|
||||||
|
'tags': [],
|
||||||
|
'data': '{"foo": 123}',
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)))
|
|
||||||
self.assertHttpStatus(response, 200)
|
|
||||||
|
|
||||||
def test_configcontext(self):
|
|
||||||
|
|
||||||
configcontext = ConfigContext.objects.first()
|
|
||||||
response = self.client.get(configcontext.get_absolute_url())
|
|
||||||
self.assertHttpStatus(response, 200)
|
|
||||||
|
|
||||||
|
|
||||||
class ObjectChangeTestCase(TestCase):
|
class ObjectChangeTestCase(TestCase):
|
||||||
user_permissions = (
|
user_permissions = (
|
||||||
|
Loading…
Reference in New Issue
Block a user