mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Clean up tests
This commit is contained in:
@@ -521,22 +521,39 @@ class CableTestCase(TestCase):
|
||||
self.assertIsNone(interface2.cable)
|
||||
self.assertIsNone(interface2._link_peer)
|
||||
|
||||
def test_cable_validates_same_parent_object(self):
|
||||
"""
|
||||
The clean method should ensure that all terminations at either end of a Cable belong to the same parent object.
|
||||
"""
|
||||
cable = Cable(a_terminations=[self.interface1], b_terminations=[self.power_port1])
|
||||
with self.assertRaises(ValidationError):
|
||||
cable.clean()
|
||||
|
||||
def test_cable_validates_same_type(self):
|
||||
"""
|
||||
The clean method should ensure that all terminations at either end of a Cable are of the same type.
|
||||
"""
|
||||
cable = Cable(a_terminations=[self.front_port1, self.rear_port1], b_terminations=[self.interface1])
|
||||
with self.assertRaises(ValidationError):
|
||||
cable.clean()
|
||||
|
||||
def test_cable_validates_compatible_types(self):
|
||||
"""
|
||||
The clean method should have a check to ensure only compatible port types can be connected by a cable
|
||||
"""
|
||||
# An interface cannot be connected to a power port
|
||||
cable = Cable(a_terminations=[self.interface1], b_terminations=[self.power_port1])
|
||||
cable = Cable(a_terminations=[self.interface1, self.interface2], b_terminations=[self.interface3])
|
||||
with self.assertRaises(ValidationError):
|
||||
cable.clean()
|
||||
|
||||
def test_cable_front_port_cannot_connect_to_corresponding_rear_port(self):
|
||||
"""
|
||||
A cable cannot connect a front port to its corresponding rear port
|
||||
"""
|
||||
cable = Cable(a_terminations=[self.front_port1], b_terminations=[self.rear_port1])
|
||||
with self.assertRaises(ValidationError):
|
||||
cable.clean()
|
||||
# TODO: Remove this?
|
||||
# def test_cable_front_port_cannot_connect_to_corresponding_rear_port(self):
|
||||
# """
|
||||
# A cable cannot connect a front port to its corresponding rear port
|
||||
# """
|
||||
# cable = Cable(a_terminations=[self.front_port1], b_terminations=[self.rear_port1])
|
||||
# with self.assertRaises(ValidationError):
|
||||
# cable.clean()
|
||||
|
||||
def test_cable_cannot_terminate_to_a_provider_network_circuittermination(self):
|
||||
"""
|
||||
@@ -546,34 +563,35 @@ class CableTestCase(TestCase):
|
||||
with self.assertRaises(ValidationError):
|
||||
cable.clean()
|
||||
|
||||
def test_rearport_connections(self):
|
||||
"""
|
||||
Test various combinations of RearPort connections.
|
||||
"""
|
||||
# Connecting a single-position RearPort to a multi-position RearPort is ok
|
||||
Cable(a_terminations=[self.rear_port1], b_terminations=[self.rear_port2]).full_clean()
|
||||
|
||||
# Connecting a single-position RearPort to an Interface is ok
|
||||
Cable(a_terminations=[self.rear_port1], b_terminations=[self.interface3]).full_clean()
|
||||
|
||||
# Connecting a single-position RearPort to a CircuitTermination is ok
|
||||
Cable(a_terminations=[self.rear_port1], b_terminations=[self.circuittermination1]).full_clean()
|
||||
|
||||
# Connecting a multi-position RearPort to another RearPort with the same number of positions is ok
|
||||
Cable(a_terminations=[self.rear_port3], b_terminations=[self.rear_port4]).full_clean()
|
||||
|
||||
# Connecting a multi-position RearPort to an Interface is ok
|
||||
Cable(a_terminations=[self.rear_port2], b_terminations=[self.interface3]).full_clean()
|
||||
|
||||
# Connecting a multi-position RearPort to a CircuitTermination is ok
|
||||
Cable(a_terminations=[self.rear_port2], b_terminations=[self.circuittermination1]).full_clean()
|
||||
|
||||
# Connecting a two-position RearPort to a three-position RearPort is NOT ok
|
||||
with self.assertRaises(
|
||||
ValidationError,
|
||||
msg='Connecting a 2-position RearPort to a 3-position RearPort should fail'
|
||||
):
|
||||
Cable(a_terminations=[self.rear_port2], b_terminations=[self.rear_port3]).full_clean()
|
||||
# TODO: Remove this?
|
||||
# def test_rearport_connections(self):
|
||||
# """
|
||||
# Test various combinations of RearPort connections.
|
||||
# """
|
||||
# # Connecting a single-position RearPort to a multi-position RearPort is ok
|
||||
# Cable(a_terminations=[self.rear_port1], b_terminations=[self.rear_port2]).full_clean()
|
||||
#
|
||||
# # Connecting a single-position RearPort to an Interface is ok
|
||||
# Cable(a_terminations=[self.rear_port1], b_terminations=[self.interface3]).full_clean()
|
||||
#
|
||||
# # Connecting a single-position RearPort to a CircuitTermination is ok
|
||||
# Cable(a_terminations=[self.rear_port1], b_terminations=[self.circuittermination1]).full_clean()
|
||||
#
|
||||
# # Connecting a multi-position RearPort to another RearPort with the same number of positions is ok
|
||||
# Cable(a_terminations=[self.rear_port3], b_terminations=[self.rear_port4]).full_clean()
|
||||
#
|
||||
# # Connecting a multi-position RearPort to an Interface is ok
|
||||
# Cable(a_terminations=[self.rear_port2], b_terminations=[self.interface3]).full_clean()
|
||||
#
|
||||
# # Connecting a multi-position RearPort to a CircuitTermination is ok
|
||||
# Cable(a_terminations=[self.rear_port2], b_terminations=[self.circuittermination1]).full_clean()
|
||||
#
|
||||
# # Connecting a two-position RearPort to a three-position RearPort is NOT ok
|
||||
# with self.assertRaises(
|
||||
# ValidationError,
|
||||
# msg='Connecting a 2-position RearPort to a 3-position RearPort should fail'
|
||||
# ):
|
||||
# Cable(a_terminations=[self.rear_port2], b_terminations=[self.rear_port3]).full_clean()
|
||||
|
||||
def test_cable_cannot_terminate_to_a_virtual_interface(self):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user