|
@@ -1,6 +1,8 @@
|
|
|
from django.test import TestCase
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
-from dcim.choices import DeviceFaceChoices, DeviceStatusChoices, InterfaceTypeChoices, InterfaceModeChoices
|
|
|
|
|
|
|
+from dcim.choices import (
|
|
|
|
|
+ DeviceFaceChoices, DeviceStatusChoices, InterfaceTypeChoices, InterfaceModeChoices, PowerOutletStatusChoices
|
|
|
|
|
+)
|
|
|
from dcim.forms import *
|
|
from dcim.forms import *
|
|
|
from dcim.models import *
|
|
from dcim.models import *
|
|
|
from ipam.models import VLAN
|
|
from ipam.models import VLAN
|
|
@@ -12,6 +14,56 @@ def get_id(model, slug):
|
|
|
return model.objects.get(slug=slug).id
|
|
return model.objects.get(slug=slug).id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+class PowerOutletFormTestCase(TestCase):
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def setUpTestData(cls):
|
|
|
|
|
+ cls.site = site = Site.objects.create(name='Site 1', slug='site-1')
|
|
|
|
|
+ cls.manufacturer = manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1')
|
|
|
|
|
+ cls.role = role = DeviceRole.objects.create(
|
|
|
|
|
+ name='Device Role 1', slug='device-role-1', color='ff0000'
|
|
|
|
|
+ )
|
|
|
|
|
+ cls.device_type = device_type = DeviceType.objects.create(
|
|
|
|
|
+ manufacturer=manufacturer, model='Device Type 1', slug='device-type-1', u_height=1
|
|
|
|
|
+ )
|
|
|
|
|
+ cls.rack = rack = Rack.objects.create(name='Rack 1', site=site)
|
|
|
|
|
+ cls.device = Device.objects.create(
|
|
|
|
|
+ name='Device 1', device_type=device_type, role=role, site=site, rack=rack, position=1
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ def test_status_is_required(self):
|
|
|
|
|
+ form = PowerOutletForm(data={
|
|
|
|
|
+ 'device': self.device,
|
|
|
|
|
+ 'module': None,
|
|
|
|
|
+ 'name': 'New Enabled Outlet',
|
|
|
|
|
+ })
|
|
|
|
|
+ self.assertFalse(form.is_valid())
|
|
|
|
|
+ self.assertIn('status', form.errors)
|
|
|
|
|
+
|
|
|
|
|
+ def test_status_must_be_defined_choice(self):
|
|
|
|
|
+ form = PowerOutletForm(data={
|
|
|
|
|
+ 'device': self.device,
|
|
|
|
|
+ 'module': None,
|
|
|
|
|
+ 'name': 'New Enabled Outlet',
|
|
|
|
|
+ 'status': 'this isn\'t a defined choice',
|
|
|
|
|
+ })
|
|
|
|
|
+ self.assertFalse(form.is_valid())
|
|
|
|
|
+ self.assertIn('status', form.errors)
|
|
|
|
|
+ self.assertTrue(form.errors['status'][-1].startswith('Select a valid choice.'))
|
|
|
|
|
+
|
|
|
|
|
+ def test_status_recognizes_choices(self):
|
|
|
|
|
+ for index, choice in enumerate(PowerOutletStatusChoices.CHOICES):
|
|
|
|
|
+ form = PowerOutletForm(data={
|
|
|
|
|
+ 'device': self.device,
|
|
|
|
|
+ 'module': None,
|
|
|
|
|
+ 'name': f'New Enabled Outlet {index + 1}',
|
|
|
|
|
+ 'status': choice[0],
|
|
|
|
|
+ })
|
|
|
|
|
+ self.assertEqual({}, form.errors)
|
|
|
|
|
+ self.assertTrue(form.is_valid())
|
|
|
|
|
+ instance = form.save()
|
|
|
|
|
+ self.assertEqual(instance.status, choice[0])
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
class DeviceTestCase(TestCase):
|
|
class DeviceTestCase(TestCase):
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|