Merge "Fix validation of IPv{4,6}AddressType"
This commit is contained in:
commit
ed4a5cc6bf
@ -337,8 +337,8 @@ Value: 'v3'. Value should be one of: v., v.",
|
||||
|
||||
def test_validate_ipv4_address_type(self):
|
||||
v = types.IPv4AddressType()
|
||||
v.validate('127.0.0.1')
|
||||
v.validate('192.168.0.1')
|
||||
self.assertEqual(v.validate('127.0.0.1'), '127.0.0.1')
|
||||
self.assertEqual(v.validate('192.168.0.1'), '192.168.0.1')
|
||||
self.assertRaises(ValueError, v.validate, '')
|
||||
self.assertRaises(ValueError, v.validate, 'foo')
|
||||
self.assertRaises(ValueError, v.validate,
|
||||
@ -346,8 +346,10 @@ Value: 'v3'. Value should be one of: v., v.",
|
||||
|
||||
def test_validate_ipv6_address_type(self):
|
||||
v = types.IPv6AddressType()
|
||||
v.validate('0:0:0:0:0:0:0:1')
|
||||
v.validate('2001:0db8:bd05:01d2:288a:1fc0:0001:10ee')
|
||||
self.assertEqual(v.validate('0:0:0:0:0:0:0:1'),
|
||||
'0:0:0:0:0:0:0:1')
|
||||
self.assertEqual(v.validate('2001:0db8:bd05:01d2:288a:1fc0:0001:10ee'),
|
||||
'2001:0db8:bd05:01d2:288a:1fc0:0001:10ee')
|
||||
self.assertRaises(ValueError, v.validate, '')
|
||||
self.assertRaises(ValueError, v.validate, 'foo')
|
||||
self.assertRaises(ValueError, v.validate, '192.168.0.1')
|
||||
|
@ -238,11 +238,15 @@ class IPv4AddressType(UserType):
|
||||
except ipaddress.AddressValueError:
|
||||
error = 'Value should be IPv4 format'
|
||||
raise ValueError(error)
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
class IPv6AddressType(UserType):
|
||||
"""
|
||||
A simple IPv6 type.
|
||||
|
||||
This type represents IPv6 addresses in the short format.
|
||||
"""
|
||||
basetype = six.string_types
|
||||
name = "ipv6address"
|
||||
@ -254,6 +258,8 @@ class IPv6AddressType(UserType):
|
||||
except ipaddress.AddressValueError:
|
||||
error = 'Value should be IPv6 format'
|
||||
raise ValueError(error)
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
class UuidType(UserType):
|
||||
|
Loading…
Reference in New Issue
Block a user