def test_get_peer(self): cra = RelationshipAssociation(relationship=self.m2m_1, source=self.racks[0], destination=self.vlans[0]) cra.save() self.assertEqual(cra.get_peer(self.racks[0]), self.vlans[0]) self.assertEqual(cra.get_peer(self.vlans[0]), self.racks[0]) self.assertEqual(cra.get_peer(self.vlans[1]), None)
def test_get_peer(self): """Validate that the get_peer() method works correctly.""" cra = RelationshipAssociation(relationship=self.m2m_1, source=self.racks[0], destination=self.vlans[0]) cra.save() self.assertEqual(cra.get_peer(self.racks[0]), self.vlans[0]) self.assertEqual(cra.get_peer(self.vlans[0]), self.racks[0]) self.assertEqual(cra.get_peer(self.vlans[1]), None)
def test_clean_check_quantity_o2o(self): """Validate that one-to-one relationships can't have more than one relationship association per side. """ cra = RelationshipAssociation(relationship=self.o2o_1, source=self.racks[0], destination=self.sites[0]) cra.clean() cra.save() cra = RelationshipAssociation(relationship=self.o2o_1, source=self.racks[1], destination=self.sites[1]) cra.clean() cra.save() with self.assertRaises(ValidationError): cra = RelationshipAssociation(relationship=self.o2o_1, source=self.racks[0], destination=self.sites[2]) cra.clean() with self.assertRaises(ValidationError): cra = RelationshipAssociation(relationship=self.o2o_1, source=self.racks[2], destination=self.sites[0]) cra.clean()
def test_clean_check_quantity_o2m(self): """Validate that one-to-many relationships can't have more than one relationship association per source.""" cra = RelationshipAssociation(relationship=self.o2m_1, source=self.sites[0], destination=self.vlans[0]) cra.clean() cra.save() cra = RelationshipAssociation(relationship=self.o2m_1, source=self.sites[0], destination=self.vlans[1]) cra.clean() cra.save() cra = RelationshipAssociation(relationship=self.o2m_1, source=self.sites[1], destination=self.vlans[2]) cra.clean() cra.save() with self.assertRaises(ValidationError) as handler: cra = RelationshipAssociation(relationship=self.o2m_1, source=self.sites[2], destination=self.vlans[0]) cra.clean() expected_errors = { "destination": [ "Unable to create more than one generic site to vlan association to VLAN A (100) (destination)", ], } self.assertEqual(handler.exception.message_dict, expected_errors)
def test_clean_check_quantity_o2o(self): """Validate that one-to-one relationships can't have more than one relationship association per side.""" cra = RelationshipAssociation(relationship=self.o2o_1, source=self.racks[0], destination=self.sites[0]) cra.clean() cra.save() cra = RelationshipAssociation(relationship=self.o2o_1, source=self.racks[1], destination=self.sites[1]) cra.clean() cra.save() with self.assertRaises(ValidationError) as handler: cra = RelationshipAssociation(relationship=self.o2o_1, source=self.racks[0], destination=self.sites[2]) cra.clean() expected_errors = { "source": [ "Unable to create more than one Primary Rack per Site association to Rack A (source)" ] } self.assertEqual(handler.exception.message_dict, expected_errors) with self.assertRaises(ValidationError) as handler: cra = RelationshipAssociation(relationship=self.o2o_1, source=self.racks[2], destination=self.sites[0]) cra.clean() expected_errors = { "destination": [ "Unable to create more than one Primary Rack per Site association to Site A (destination)" ] } self.assertEqual(handler.exception.message_dict, expected_errors)
def test_clean_check_quantity_m2m(self): """Validate that many-to-many relationship can have many relationship associations.""" cra = RelationshipAssociation(relationship=self.m2m_1, source=self.racks[0], destination=self.vlans[0]) cra.clean() cra.save() cra = RelationshipAssociation(relationship=self.m2m_1, source=self.racks[0], destination=self.vlans[1]) cra.clean() cra.save() cra = RelationshipAssociation(relationship=self.m2m_1, source=self.racks[1], destination=self.vlans[2]) cra.clean() cra.save() cra = RelationshipAssociation(relationship=self.m2m_1, source=self.racks[2], destination=self.vlans[0]) cra.clean()