1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Show parent device/VM when creating new components

This commit is contained in:
jeremystretch
2021-12-28 15:07:14 -05:00
parent 21356b487a
commit 3982f13569
5 changed files with 53 additions and 10 deletions

View File

@@ -1,8 +1,9 @@
from django.test import TestCase
from dcim.choices import DeviceFaceChoices, DeviceStatusChoices, InterfaceTypeChoices
from dcim.choices import DeviceFaceChoices, DeviceStatusChoices
from dcim.forms import *
from dcim.models import *
from utilities.testing import create_test_device
from virtualization.models import Cluster, ClusterGroup, ClusterType
@@ -118,15 +119,20 @@ class DeviceTestCase(TestCase):
class LabelTestCase(TestCase):
@classmethod
def setUpTestData(cls):
cls.device = create_test_device('Device 1')
def test_interface_label_count_valid(self):
"""
Test that generating an equal number of names and labels passes form validation.
"""
interface_data = {
'device': self.device.pk,
'name_pattern': 'eth[0-9]',
'label_pattern': 'Interface[0-9]',
}
form = ComponentCreateForm(interface_data)
form = DeviceComponentCreateForm(interface_data)
self.assertTrue(form.is_valid())
@@ -135,10 +141,11 @@ class LabelTestCase(TestCase):
Check that attempting to generate a differing number of names and labels results in a validation error.
"""
bad_interface_data = {
'device': self.device.pk,
'name_pattern': 'eth[0-9]',
'label_pattern': 'Interface[0-1]',
}
form = ComponentCreateForm(bad_interface_data)
form = DeviceComponentCreateForm(bad_interface_data)
self.assertFalse(form.is_valid())
self.assertIn('label_pattern', form.errors)