mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Test forms and views with labels
This commit is contained in:
@ -116,3 +116,71 @@ class DeviceTestCase(TestCase):
|
||||
|
||||
# Check that the initial value for the cluster group is set automatically when assigning the cluster
|
||||
self.assertEqual(test.initial['cluster_group'], cluster.group.pk)
|
||||
|
||||
|
||||
class LabelTestCase(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
site = Site.objects.create(name='Site 2', slug='site-2')
|
||||
manufacturer = Manufacturer.objects.create(name='Manufacturer 2', slug='manufacturer-2')
|
||||
cls.device_type = DeviceType.objects.create(
|
||||
manufacturer=manufacturer, model='Device Type 2', slug='device-type-2', u_height=1
|
||||
)
|
||||
device_role = DeviceRole.objects.create(
|
||||
name='Device Role 2', slug='device-role-2', color='ffff00'
|
||||
)
|
||||
cls.device = Device.objects.create(
|
||||
name='Device 2', device_type=cls.device_type, device_role=device_role, site=site
|
||||
)
|
||||
|
||||
def test_interface_label_count_valid(self):
|
||||
good_interface_data = {
|
||||
'device': self.device.pk,
|
||||
'name_pattern': 'eth[0-9]',
|
||||
# Test that a label CAN be applied to each generated interfaces
|
||||
'label_pattern': 'Interface[0-9]',
|
||||
'type': InterfaceTypeChoices.TYPE_100ME_FIXED,
|
||||
}
|
||||
form = InterfaceCreateForm(good_interface_data)
|
||||
|
||||
print(form.errors)
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
def test_interface_label_count_mismatch(self):
|
||||
bad_interface_data = {
|
||||
'device': self.device.pk,
|
||||
'name_pattern': 'eth[0-9]',
|
||||
# Test that a label CANNOT be applied to each generated interfaces
|
||||
'label_pattern': 'Interface[0-1]',
|
||||
'type': InterfaceTypeChoices.TYPE_100ME_FIXED,
|
||||
}
|
||||
form = InterfaceCreateForm(bad_interface_data)
|
||||
|
||||
self.assertFalse(form.is_valid())
|
||||
self.assertIn('label_pattern', form.errors)
|
||||
|
||||
def test_console_port_template_label_count_valid(self):
|
||||
bad_console_port_template_data = {
|
||||
'device_type': self.device_type,
|
||||
'name_pattern': 'Console Port Template[4-6]',
|
||||
# Test that a label CANNOT be applied to each generated console port templates
|
||||
'label_pattern': 'Serial[4-6]',
|
||||
'type': ConsolePortTypeChoices.TYPE_RJ45,
|
||||
}
|
||||
form = ConsolePortTemplateCreateForm(bad_console_port_template_data)
|
||||
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
def test_console_port_template_label_count_mismatch(self):
|
||||
bad_console_port_template_data = {
|
||||
'device_type': self.device_type,
|
||||
'name_pattern': 'Console Port Template[4-6]',
|
||||
# Test that a label CANNOT be applied to each generated console port templates
|
||||
'label_pattern': 'Serial[0-1]',
|
||||
'type': ConsolePortTypeChoices.TYPE_RJ45,
|
||||
}
|
||||
form = ConsolePortTemplateCreateForm(bad_console_port_template_data)
|
||||
|
||||
self.assertFalse(form.is_valid())
|
||||
self.assertIn('label_pattern', form.errors)
|
||||
|
@ -699,6 +699,8 @@ class InterfaceTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas
|
||||
cls.bulk_create_data = {
|
||||
'device_type': devicetypes[1].pk,
|
||||
'name_pattern': 'Interface Template [4-6]',
|
||||
# Test that a label can be applied to each generated interface templates
|
||||
'label_pattern': 'Interface Template Label [3-5]',
|
||||
'type': InterfaceTypeChoices.TYPE_1GE_GBIC,
|
||||
'mgmt_only': True,
|
||||
}
|
||||
@ -995,6 +997,8 @@ class ConsolePortTestCase(ViewTestCases.DeviceComponentViewTestCase):
|
||||
cls.bulk_create_data = {
|
||||
'device': device.pk,
|
||||
'name_pattern': 'Console Port [4-6]',
|
||||
# Test that a label can be applied to each generated console ports
|
||||
'label_pattern': 'Serial[3-5]',
|
||||
'type': ConsolePortTypeChoices.TYPE_RJ45,
|
||||
'description': 'A console port',
|
||||
'tags': 'Alpha,Bravo,Charlie',
|
||||
|
Reference in New Issue
Block a user