mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
Simplify tests
This commit is contained in:
parent
e7481f3bcc
commit
113de69af7
@ -1,5 +1,7 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from dcim.models import *
|
from dcim.models import *
|
||||||
|
from utilities.testing.utils import create_test_device
|
||||||
|
|
||||||
|
|
||||||
class CountersTest(TestCase):
|
class CountersTest(TestCase):
|
||||||
@ -9,53 +11,42 @@ class CountersTest(TestCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
|
||||||
site = Site.objects.create(name='Test Site 1', slug='test-site-1')
|
# Create devices
|
||||||
manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
|
device1 = create_test_device('Device 1')
|
||||||
devicetype = DeviceType.objects.create(
|
device2 = create_test_device('Device 2')
|
||||||
manufacturer=manufacturer, model='Test Device Type 1', slug='test-device-type-1'
|
|
||||||
)
|
# Create interfaces
|
||||||
devicerole = DeviceRole.objects.create(
|
Interface.objects.create(device=device1, name='Interface 1')
|
||||||
name='Test Device Role 1', slug='test-device-role-1', color='ff0000'
|
Interface.objects.create(device=device1, name='Interface 2')
|
||||||
)
|
Interface.objects.create(device=device2, name='Interface 3')
|
||||||
device1 = Device.objects.create(
|
Interface.objects.create(device=device2, name='Interface 4')
|
||||||
device_type=devicetype, device_role=devicerole, name='TestDevice1', site=site
|
|
||||||
)
|
|
||||||
device2 = Device.objects.create(
|
|
||||||
device_type=devicetype, device_role=devicerole, name='TestDevice2', site=site
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_interface_count_addition(self):
|
def test_interface_count_addition(self):
|
||||||
"""
|
"""
|
||||||
When a tracked object (Interface) is added the tracking counter should be updated.
|
When a tracked object (Interface) is added the tracking counter should be updated.
|
||||||
"""
|
"""
|
||||||
device1 = Device.objects.get(name='TestDevice1')
|
device1, device2 = Device.objects.all()
|
||||||
device2 = Device.objects.get(name='TestDevice2')
|
self.assertEqual(device1._interface_count, 2)
|
||||||
self.assertEqual(device1._interface_count, 0)
|
self.assertEqual(device2._interface_count, 2)
|
||||||
self.assertEqual(device2._interface_count, 0)
|
|
||||||
|
|
||||||
interface1 = Interface.objects.create(device=device1, name='eth0')
|
Interface.objects.create(device=device1, name='Interface 5')
|
||||||
interface2 = Interface.objects.create(device=device2, name='eth0')
|
Interface.objects.create(device=device2, name='Interface 6')
|
||||||
interface3 = Interface.objects.create(device=device2, name='eth1')
|
|
||||||
device1.refresh_from_db()
|
device1.refresh_from_db()
|
||||||
device2.refresh_from_db()
|
device2.refresh_from_db()
|
||||||
self.assertEqual(device1._interface_count, 1)
|
self.assertEqual(device1._interface_count, 3)
|
||||||
self.assertEqual(device2._interface_count, 2)
|
self.assertEqual(device2._interface_count, 3)
|
||||||
|
|
||||||
def test_interface_count_deletion(self):
|
def test_interface_count_deletion(self):
|
||||||
"""
|
"""
|
||||||
When a tracked object (Interface) is deleted the tracking counter should be updated.
|
When a tracked object (Interface) is deleted the tracking counter should be updated.
|
||||||
"""
|
"""
|
||||||
device1 = Device.objects.get(name='TestDevice1')
|
device1, device2 = Device.objects.all()
|
||||||
device2 = Device.objects.get(name='TestDevice2')
|
self.assertEqual(device1._interface_count, 2)
|
||||||
self.assertEqual(device1._interface_count, 0)
|
self.assertEqual(device2._interface_count, 2)
|
||||||
self.assertEqual(device2._interface_count, 0)
|
|
||||||
|
|
||||||
interface1 = Interface.objects.create(device=device1, name='eth0')
|
Interface.objects.get(name='Interface 1').delete()
|
||||||
interface2 = Interface.objects.create(device=device2, name='eth0')
|
Interface.objects.get(name='Interface 3').delete()
|
||||||
interface3 = Interface.objects.create(device=device2, name='eth1')
|
|
||||||
interface2.delete()
|
|
||||||
interface3.delete()
|
|
||||||
device1.refresh_from_db()
|
device1.refresh_from_db()
|
||||||
device2.refresh_from_db()
|
device2.refresh_from_db()
|
||||||
self.assertEqual(device1._interface_count, 1)
|
self.assertEqual(device1._interface_count, 1)
|
||||||
self.assertEqual(device2._interface_count, 0)
|
self.assertEqual(device2._interface_count, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user