Ejemplo n.º 1
0
    def test_clean_wrong_type(self):
        # Create with the wrong source Type
        with self.assertRaises(ValidationError) as handler:
            cra = RelationshipAssociation(relationship=self.m2m_1,
                                          source=self.sites[0],
                                          destination=self.vlans[0])
            cra.clean()
        expected_errors = {
            "source_type":
            ["source_type has a different value than defined in Vlan to Rack"]
        }
        self.assertEqual(handler.exception.message_dict, expected_errors)

        # Create with the wrong destination Type
        with self.assertRaises(ValidationError) as handler:
            cra = RelationshipAssociation(relationship=self.m2m_1,
                                          source=self.racks[0],
                                          destination=self.racks[0])
            cra.clean()
        expected_errors = {
            "destination_type": [
                "destination_type has a different value than defined in Vlan to Rack"
            ]
        }
        self.assertEqual(handler.exception.message_dict, expected_errors)
Ejemplo n.º 2
0
    def test_clean_wrong_type(self):
        # Create with the wrong source Type
        with self.assertRaises(ValidationError):
            cra = RelationshipAssociation(relationship=self.m2m_1, source=self.sites[0], destination=self.vlans[0])
            cra.clean()

        # Create with the wrong destination Type
        with self.assertRaises(ValidationError):
            cra = RelationshipAssociation(relationship=self.m2m_1, source=self.racks[0], destination=self.racks[0])
            cra.clean()
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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.validated_save()

        cra = RelationshipAssociation(relationship=self.o2m_1,
                                      source=self.sites[0],
                                      destination=self.vlans[1])
        cra.validated_save()

        cra = RelationshipAssociation(relationship=self.o2m_1,
                                      source=self.sites[1],
                                      destination=self.vlans[2])
        cra.validated_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)

        # Shouldn't be possible to create another copy of the same RelationshipAssociation
        with self.assertRaises(ValidationError) as handler:
            cra = RelationshipAssociation(relationship=self.o2m_1,
                                          source=self.sites[0],
                                          destination=self.vlans[0])
            cra.validated_save()
        expected_errors = {
            "__all__": [
                "Relationship association with this Relationship, Source type, Source id, Destination type "
                "and Destination id already exists."
            ],
            "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)
Ejemplo n.º 5
0
 def test_relationship_association_validator_raises_exception(self):
     status_active = Status.objects.create(name="status1", slug="status1")
     prefix = Prefix.objects.create(
         prefix=netaddr.IPNetwork("192.168.10.0/24"))
     ipaddress = IPAddress.objects.create(address="192.168.22.1/24",
                                          status=status_active)
     relationship = Relationship.objects.create(
         name="Test Relationship",
         slug="test-relationship",
         source_type=ContentType.objects.get_for_model(Prefix),
         destination_type=ContentType.objects.get_for_model(IPAddress),
         type=RelationshipTypeChoices.TYPE_ONE_TO_MANY,
     )
     relationship_assoc = RelationshipAssociation(relationship=relationship,
                                                  source=prefix,
                                                  destination=ipaddress)
     with self.assertRaises(ValidationError):
         relationship_assoc.clean()
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
    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):
            cra = RelationshipAssociation(relationship=self.o2o_1, source=self.sites[2], destination=self.vlans[0])
            cra.clean()
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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.validated_save()

        cra = RelationshipAssociation(relationship=self.o2o_1,
                                      source=self.racks[1],
                                      destination=self.sites[1])
        cra.validated_save()

        cra = RelationshipAssociation(relationship=self.o2os_1,
                                      source=self.racks[0],
                                      destination=self.racks[1])
        cra.validated_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)

        with self.assertRaises(ValidationError) as handler:
            cra = RelationshipAssociation(relationship=self.o2os_1,
                                          source=self.racks[0],
                                          destination=self.racks[2])
            cra.clean()
        expected_errors = {
            "source": [
                "Unable to create more than one Redundant Rack association to Rack A (source)"
            ]
        }
        self.assertEqual(handler.exception.message_dict, expected_errors)

        # Slightly tricky case - a symmetric one-to-one relationship where the proposed *source* is already in use
        # as a *destination* in a different RelationshipAssociation
        with self.assertRaises(ValidationError) as handler:
            cra = RelationshipAssociation(relationship=self.o2os_1,
                                          source=self.racks[1],
                                          destination=self.racks[2])
            cra.clean()
        expected_errors = {
            "source": [
                "Unable to create more than one Redundant Rack association involving Rack B (peer)"
            ]
        }
        self.assertEqual(handler.exception.message_dict, expected_errors)