Fix validation of IPv{4,6}AddressType
The patch fixes a validation of IPv4AddressType and IPv6AddressType. Due to the fact that the the validation method should returns a proper value. Change-Id: Ib00f9cc5012875055c882cf5a7bfce6c89f8f14d Closes-Bug: #1287152
This commit is contained in:
parent
2e1863db6c
commit
d34eb82353
@ -328,8 +328,8 @@ Value: 'v3'. Value should be one of: v., v.",
|
|||||||
|
|
||||||
def test_validate_ipv4_address_type(self):
|
def test_validate_ipv4_address_type(self):
|
||||||
v = types.IPv4AddressType()
|
v = types.IPv4AddressType()
|
||||||
v.validate('127.0.0.1')
|
self.assertEqual(v.validate('127.0.0.1'), '127.0.0.1')
|
||||||
v.validate('192.168.0.1')
|
self.assertEqual(v.validate('192.168.0.1'), '192.168.0.1')
|
||||||
self.assertRaises(ValueError, v.validate, '')
|
self.assertRaises(ValueError, v.validate, '')
|
||||||
self.assertRaises(ValueError, v.validate, 'foo')
|
self.assertRaises(ValueError, v.validate, 'foo')
|
||||||
self.assertRaises(ValueError, v.validate,
|
self.assertRaises(ValueError, v.validate,
|
||||||
@ -337,8 +337,10 @@ Value: 'v3'. Value should be one of: v., v.",
|
|||||||
|
|
||||||
def test_validate_ipv6_address_type(self):
|
def test_validate_ipv6_address_type(self):
|
||||||
v = types.IPv6AddressType()
|
v = types.IPv6AddressType()
|
||||||
v.validate('0:0:0:0:0:0:0:1')
|
self.assertEqual(v.validate('0:0:0:0:0:0:0:1'),
|
||||||
v.validate('2001:0db8:bd05:01d2:288a:1fc0:0001:10ee')
|
'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, '')
|
||||||
self.assertRaises(ValueError, v.validate, 'foo')
|
self.assertRaises(ValueError, v.validate, 'foo')
|
||||||
self.assertRaises(ValueError, v.validate, '192.168.0.1')
|
self.assertRaises(ValueError, v.validate, '192.168.0.1')
|
||||||
|
@ -238,11 +238,15 @@ class IPv4AddressType(UserType):
|
|||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
error = 'Value should be IPv4 format'
|
error = 'Value should be IPv4 format'
|
||||||
raise ValueError(error)
|
raise ValueError(error)
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class IPv6AddressType(UserType):
|
class IPv6AddressType(UserType):
|
||||||
"""
|
"""
|
||||||
A simple IPv6 type.
|
A simple IPv6 type.
|
||||||
|
|
||||||
|
This type represents IPv6 addresses in the short format.
|
||||||
"""
|
"""
|
||||||
basetype = six.string_types
|
basetype = six.string_types
|
||||||
name = "ipv6address"
|
name = "ipv6address"
|
||||||
@ -254,6 +258,8 @@ class IPv6AddressType(UserType):
|
|||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
error = 'Value should be IPv6 format'
|
error = 'Value should be IPv6 format'
|
||||||
raise ValueError(error)
|
raise ValueError(error)
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class UuidType(UserType):
|
class UuidType(UserType):
|
||||||
|
Loading…
Reference in New Issue
Block a user