Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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))
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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"'
        )
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 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)
        )
Exemplo n.º 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),
        )
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 18
0
 def test_genericipaddressfield_validation_ok(self):
     try:
         models.GenericIPAddressField(protocol="ipv6",
                                      unpack_protocol="same")
     except AsyncOrmFieldError:
         self.fail("Unexpectedly not correctly matched")
Exemplo n.º 19
0
 def test_genericipaddressfield_validation_ok(self):
     models.GenericIPAddressField(protocol='ipv6', unpack_protocol='same')
Exemplo n.º 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)
Exemplo n.º 21
0
 def test_genericipaddressfield_validation_protocol_correct_options(self):
     protocol = ('both', 'ipv4', 'ipv6')
     for prot in protocol:
         models.GenericIPAddressField(protocol=prot)