mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Add REST API test for custom fields
This commit is contained in:
parent
a05fe69043
commit
98f2d2501b
@ -11,7 +11,7 @@ from rq import Worker
|
|||||||
|
|
||||||
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Rack, RackGroup, RackRole, Site
|
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Rack, RackGroup, RackRole, Site
|
||||||
from extras.api.views import ReportViewSet, ScriptViewSet
|
from extras.api.views import ReportViewSet, ScriptViewSet
|
||||||
from extras.models import ConfigContext, ExportTemplate, ImageAttachment, Tag
|
from extras.models import ConfigContext, CustomField, ExportTemplate, ImageAttachment, Tag
|
||||||
from extras.reports import Report
|
from extras.reports import Report
|
||||||
from extras.scripts import BooleanVar, IntegerVar, Script, StringVar
|
from extras.scripts import BooleanVar, IntegerVar, Script, StringVar
|
||||||
from utilities.testing import APITestCase, APIViewTestCases
|
from utilities.testing import APITestCase, APIViewTestCases
|
||||||
@ -30,6 +30,53 @@ class AppTest(APITestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomFieldTest(APIViewTestCases.APIViewTestCase):
|
||||||
|
model = CustomField
|
||||||
|
brief_fields = ['id', 'name', 'url']
|
||||||
|
create_data = [
|
||||||
|
{
|
||||||
|
'content_types': ['dcim.site'],
|
||||||
|
'name': 'cf4',
|
||||||
|
'type': 'date',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'content_types': ['dcim.site'],
|
||||||
|
'name': 'cf5',
|
||||||
|
'type': 'url',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'content_types': ['dcim.site'],
|
||||||
|
'name': 'cf6',
|
||||||
|
'type': 'select',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
bulk_update_data = {
|
||||||
|
'description': 'New description',
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
site_ct = ContentType.objects.get_for_model(Site)
|
||||||
|
|
||||||
|
custom_fields = (
|
||||||
|
CustomField(
|
||||||
|
name='cf1',
|
||||||
|
type='text'
|
||||||
|
),
|
||||||
|
CustomField(
|
||||||
|
name='cf2',
|
||||||
|
type='integer'
|
||||||
|
),
|
||||||
|
CustomField(
|
||||||
|
name='cf3',
|
||||||
|
type='boolean'
|
||||||
|
),
|
||||||
|
)
|
||||||
|
CustomField.objects.bulk_create(custom_fields)
|
||||||
|
for cf in custom_fields:
|
||||||
|
cf.content_types.add(site_ct)
|
||||||
|
|
||||||
|
|
||||||
class ExportTemplateTest(APIViewTestCases.APIViewTestCase):
|
class ExportTemplateTest(APIViewTestCases.APIViewTestCase):
|
||||||
model = ExportTemplate
|
model = ExportTemplate
|
||||||
brief_fields = ['id', 'name', 'url']
|
brief_fields = ['id', 'name', 'url']
|
||||||
|
Loading…
Reference in New Issue
Block a user