Example #1
0
    def test_genericipaddressfield_ok(self):
        correct_formats = (
            "192.168.100.128/25",
            "192.168/24",
            "192.168/25",
            "192.168.1",
            "192.168",
            "128.1",
            "128",
            "128.1.2",
            "10.1.2",
            "10.1",
            "10",
            "10.1.2.3/32",
            "2001:4f8:3:ba::/64",
            "2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128",
            "::ffff:1.2.3.0/120",
            "::ffff:1.2.3.0/128",
        )

        for ip_address in correct_formats:
            try:
                models.GenericIPAddressField().validate(ip_address)
            except AsyncOrmFieldError:
                self.fail("unexpectedly not valid IP address")
Example #2
0
 def test_genericipaddressfield_validation_protocol_correct_options(self):
     protocol = ("both", "ipv4", "ipv6")
     for prot in protocol:
         try:
             models.GenericIPAddressField(protocol=prot)
         except AsyncOrmFieldError:
             self.fail("Unexpectedly not recognized ip address")
Example #3
0
    def test_genericipaddressfield_validation_protocol_error_option(self):
        protocol = "ipv9"
        with self.assertRaises(FieldError) as exc:
            models.GenericIPAddressField(protocol=protocol)

        self.assertEqual(exc.exception.args[0],
                         '"{}" is not a recognized protocol'.format(protocol))
Example #4
0
 def test_genericipaddressfield_validation_unpack_protocol_correct_options(
         self):
     unpack_protocol = ("same", "ipv4", "ipv6")
     for prot in unpack_protocol:
         try:
             models.GenericIPAddressField(unpack_protocol=prot)
         except AsyncOrmFieldError:
             self.fail("Unexpectedly not a recognized protocol")
Example #5
0
class Publisher(models.Model):
    name = models.CharField(max_length=50, db_index=True)
    json = models.JsonField(max_length=50, null=True)

    mac = models.MACAdressField(null=True, dialect="unix")
    inet = models.GenericIPAddressField(null=True,
                                        protocol="both",
                                        unpack_protocol="ipv4")
Example #6
0
    def test_genericipaddressfield_validation_ipv6_error(self):
        with self.assertRaises(FieldError) as exc:
            models.GenericIPAddressField(protocol='ipv6', unpack_protocol='ipv4')

        self.assertEqual(
            exc.exception.args[0],
            'if the protocol is restricted the output will always be in the same protocol version, '
            'so unpack_protocol should be default value, "same"'
        )
Example #7
0
    def test_genericipaddressfield_ipv6_error(self):
        value = "1.1.1.1"
        protocol = "ipv6"
        with self.assertRaises(AsyncOrmFieldError) as exc:
            models.GenericIPAddressField(protocol=protocol).validate(value)

        self.assertEqual(
            exc.exception.args[0],
            "{} is not a correct {} IP address".format(value, protocol))
Example #8
0
    def test_genericipaddressfield_ok_ipv6(self):
        correct_formats = (
            '2001:4f8:3:ba::/64',
            '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128',
            '::ffff:1.2.3.0/120',
            '::ffff:1.2.3.0/128',
        )

        for ip_address in correct_formats:
            models.GenericIPAddressField(protocol='ipv6').validate(ip_address)
Example #9
0
    def test_genericipaddressfield_ipv6_error(self):
        value = '1.1.1.1'
        protocol = 'ipv6'
        with self.assertRaises(FieldError) as exc:
            models.GenericIPAddressField(protocol=protocol).validate(value)

        self.assertEqual(
            exc.exception.args[0],
            '{} is not a correct {} IP address'.format(value, protocol)
        )
Example #10
0
    def test_genericipaddressfield_ipv4_error(self):
        value = "::ffff:1.2.3.0/128"
        protocol = "ipv4"
        with self.assertRaises(FieldError) as exc:
            models.GenericIPAddressField(protocol=protocol).validate(value)

        self.assertEqual(
            exc.exception.args[0],
            "{} is not a correct {} IP address".format(value, protocol),
        )
Example #11
0
    def test_genericipaddressfield_ok_ipv6(self):
        correct_formats = (
            "2001:4f8:3:ba::/64",
            "2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128",
            "::ffff:1.2.3.0/120",
            "::ffff:1.2.3.0/128",
        )

        for ip_address in correct_formats:
            try:
                models.GenericIPAddressField(
                    protocol="ipv6").validate(ip_address)
            except AsyncOrmFieldError:
                self.fail("Unexpectedly not a correct format")
Example #12
0
    def test_genericipaddressfield_ok_ipv4(self):
        correct_formats = (
            "192.168.100.128/25",
            "192.168/24",
            "192.168/25",
            "192.168.1",
            "192.168",
            "128.1",
            "128",
            "128.1.2",
            "10.1.2",
            "10.1",
            "10",
            "10.1.2.3/32",
        )

        for ip_address in correct_formats:
            models.GenericIPAddressField(protocol="ipv4").validate(ip_address)
Example #13
0
    def test_genericipaddressfield_ok_ipv4(self):
        correct_formats = (
            '192.168.100.128/25',
            '192.168/24',
            '192.168/25',
            '192.168.1',
            '192.168',
            '128.1',
            '128',
            '128.1.2',
            '10.1.2',
            '10.1',
            '10',
            '10.1.2.3/32',
        )

        for ip_address in correct_formats:
            models.GenericIPAddressField(protocol='ipv4').validate(ip_address)
Example #14
0
    def test_genericipaddressfield_ok_ipv4(self):
        correct_formats = (
            "192.168.100.128/25",
            "192.168/24",
            "192.168/25",
            "192.168.1",
            "192.168",
            "128.1",
            "128",
            "128.1.2",
            "10.1.2",
            "10.1",
            "10",
            "10.1.2.3/32",
        )

        for ip_address in correct_formats:
            try:
                models.GenericIPAddressField(
                    protocol="ipv4").validate(ip_address)
            except AsyncOrmFieldError:
                self.fail("unexpectedly not valid IP address")
Example #15
0
    def test_genericipaddressfield_ok(self):
        correct_formats = (
            '192.168.100.128/25',
            '192.168/24',
            '192.168/25',
            '192.168.1',
            '192.168',
            '128.1',
            '128',
            '128.1.2',
            '10.1.2',
            '10.1',
            '10',
            '10.1.2.3/32',
            '2001:4f8:3:ba::/64',
            '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128',
            '::ffff:1.2.3.0/120',
            '::ffff:1.2.3.0/128',
        )

        for ip_address in correct_formats:
            models.GenericIPAddressField().validate(ip_address)
Example #16
0
    def test_genericipaddressfield_ok(self):
        correct_formats = (
            "192.168.100.128/25",
            "192.168/24",
            "192.168/25",
            "192.168.1",
            "192.168",
            "128.1",
            "128",
            "128.1.2",
            "10.1.2",
            "10.1",
            "10",
            "10.1.2.3/32",
            "2001:4f8:3:ba::/64",
            "2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128",
            "::ffff:1.2.3.0/120",
            "::ffff:1.2.3.0/128",
        )

        for ip_address in correct_formats:
            models.GenericIPAddressField().validate(ip_address)
Example #17
0
    def test_genericipaddressfield_error(self):
        with self.assertRaises(FieldError) as exc:
            models.GenericIPAddressField().validate('1.1.1.1000')

        self.assertEqual(exc.exception.args[0], 'Not a correct IP address')
Example #18
0
 def test_genericipaddressfield_validation_ok(self):
     try:
         models.GenericIPAddressField(protocol="ipv6",
                                      unpack_protocol="same")
     except AsyncOrmFieldError:
         self.fail("Unexpectedly not correctly matched")
Example #19
0
 def test_genericipaddressfield_validation_ok(self):
     models.GenericIPAddressField(protocol='ipv6', unpack_protocol='same')
Example #20
0
 def test_genericipaddressfield_validation_unpack_protocol_correct_options(self):
     unpack_protocol = ('same', 'ipv4', 'ipv6')
     for prot in unpack_protocol:
         models.GenericIPAddressField(unpack_protocol=prot)
Example #21
0
 def test_genericipaddressfield_validation_protocol_correct_options(self):
     protocol = ('both', 'ipv4', 'ipv6')
     for prot in protocol:
         models.GenericIPAddressField(protocol=prot)