From 5de10eabe1ae14c2d4e0d281f8d3a042a124ff42 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Wed, 20 Nov 2013 16:32:58 +0000 Subject: [PATCH] Fix printing object reference on StringType .pattern is the correct pattern string from which the object was compiled from. Change-Id: I35eeca17d6edcc1a210ed7b3de2856a678fdc180 Closes-Bug: #1340879 --- wsme/tests/test_types.py | 9 +++++++++ wsme/types.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/wsme/tests/test_types.py b/wsme/tests/test_types.py index c3805a2..acdf21d 100644 --- a/wsme/tests/test_types.py +++ b/wsme/tests/test_types.py @@ -326,6 +326,15 @@ Value: 'v3'. Value should be one of: v., v.", v.validate('A') self.assertRaises(ValueError, v.validate, '_') + def test_validate_string_type_pattern_exception_message(self): + regex = '^[a-zA-Z0-9]*$' + v = types.StringType(pattern=regex) + try: + v.validate('_') + self.assertFail() + except ValueError as e: + self.assertIn(regex, str(e)) + def test_validate_ipv4_address_type(self): v = types.IPv4AddressType() v.validate('127.0.0.1') diff --git a/wsme/types.py b/wsme/types.py index 383dea6..b65143c 100644 --- a/wsme/types.py +++ b/wsme/types.py @@ -218,7 +218,7 @@ class StringType(UserType): raise ValueError(error) if self.pattern is not None and not self.pattern.search(value): - error = 'Value should match the pattern %s' % self.pattern + error = 'Value should match the pattern %s' % self.pattern.pattern raise ValueError(error) return value