|
1 | 1 | from django.core.exceptions import ValidationError |
2 | | -from django.test import TestCase |
| 2 | +from django.test import tag, TestCase |
3 | 3 |
|
4 | 4 | from circuits.models import * |
5 | 5 | from core.models import ObjectType |
|
12 | 12 | from virtualization.models import Cluster, ClusterType |
13 | 13 |
|
14 | 14 |
|
| 15 | +class MACAddressTestCase(TestCase): |
| 16 | + @classmethod |
| 17 | + def setUpTestData(cls): |
| 18 | + site = Site.objects.create(name='Test Site 1', slug='test-site-1') |
| 19 | + manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1') |
| 20 | + device_type = DeviceType.objects.create( |
| 21 | + manufacturer=manufacturer, model='Test Device Type 1', slug='test-device-type-1' |
| 22 | + ) |
| 23 | + device_role = DeviceRole.objects.create(name='Test Role 1', slug='test-role-1') |
| 24 | + device = Device.objects.create( |
| 25 | + name='Device 1', device_type=device_type, role=device_role, site=site, |
| 26 | + ) |
| 27 | + cls.interface = Interface.objects.create( |
| 28 | + device=device, |
| 29 | + name='Interface 1', |
| 30 | + type=InterfaceTypeChoices.TYPE_1GE_FIXED, |
| 31 | + mgmt_only=True |
| 32 | + ) |
| 33 | + |
| 34 | + cls.mac_a = MACAddress.objects.create(mac_address='1234567890ab', assigned_object=cls.interface) |
| 35 | + cls.mac_b = MACAddress.objects.create(mac_address='1234567890ba', assigned_object=cls.interface) |
| 36 | + |
| 37 | + cls.interface.primary_mac_address = cls.mac_a |
| 38 | + cls.interface.save() |
| 39 | + |
| 40 | + @tag('regression') |
| 41 | + def test_clean_will_not_allow_removal_of_assigned_object_if_primary(self): |
| 42 | + self.mac_a.assigned_object = None |
| 43 | + with self.assertRaisesMessage(ValidationError, 'Cannot unassign MAC Address while'): |
| 44 | + self.mac_a.clean() |
| 45 | + |
| 46 | + @tag('regression') |
| 47 | + def test_clean_will_allow_removal_of_assigned_object_if_not_primary(self): |
| 48 | + self.mac_b.assigned_object = None |
| 49 | + self.mac_b.clean() |
| 50 | + |
| 51 | + |
15 | 52 | class LocationTestCase(TestCase): |
16 | 53 |
|
17 | 54 | def test_change_location_site(self): |
|
0 commit comments