From d34eb82353458921c65427215d9725ab7cc633c4 Mon Sep 17 00:00:00 2001 From: Ilya Kharin Date: Mon, 3 Mar 2014 12:09:36 +0400 Subject: [PATCH] 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 --- wsme/tests/test_types.py | 10 ++++++---- wsme/types.py | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/wsme/tests/test_types.py b/wsme/tests/test_types.py index c3805a2..8301487 100644 --- a/wsme/tests/test_types.py +++ b/wsme/tests/test_types.py @@ -328,8 +328,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, @@ -337,8 +337,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') diff --git a/wsme/types.py b/wsme/types.py index 383dea6..b8e8ef7 100644 --- a/wsme/types.py +++ b/wsme/types.py @@ -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):