[CalendarServer-changes] [12519] twext/trunk/twext/who

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:23:23 PDT 2014


Revision: 12519
          http://trac.calendarserver.org//changeset/12519
Author:   wsanchez at apple.com
Date:     2014-01-31 14:08:56 -0800 (Fri, 31 Jan 2014)
Log Message:
-----------
MatchExpression() now raises if the field value doesn't match the expected type for the field.

Modified Paths:
--------------
    twext/trunk/twext/who/expression.py
    twext/trunk/twext/who/test/test_expression.py

Modified: twext/trunk/twext/who/expression.py
===================================================================
--- twext/trunk/twext/who/expression.py	2014-01-31 22:03:44 UTC (rev 12518)
+++ twext/trunk/twext/who/expression.py	2014-01-31 22:08:56 UTC (rev 12519)
@@ -205,6 +205,14 @@
         fieldName, fieldValue,
         matchType=MatchType.equals, flags=MatchFlags.none
     ):
+        valueType = FieldName.valueType(fieldName)
+        if not isinstance(fieldValue, valueType):
+            raise TypeError(
+                "Field value {value!r} for field {field} in match expression "
+                "is not of expected type {type}."
+                .format(value=fieldValue, field=fieldName, type=valueType)
+            )
+
         self.fieldName = fieldName
         self.fieldValue = fieldValue
         self.matchType = matchType

Modified: twext/trunk/twext/who/test/test_expression.py
===================================================================
--- twext/trunk/twext/who/test/test_expression.py	2014-01-31 22:03:44 UTC (rev 12518)
+++ twext/trunk/twext/who/test/test_expression.py	2014-01-31 22:08:56 UTC (rev 12519)
@@ -75,6 +75,19 @@
     Tests for L{MatchExpression}.
     """
 
+    def test_initBadType_value(self):
+        """
+        L{MatchExpression.__init__} raises if the field value doesn't match the
+        expected type for the field.
+        """
+        # guid field expects a UUID, not a string.
+        self.assertRaises(
+            TypeError,
+            MatchExpression,
+            FieldName.guid, u"00000000-0000-0000-0000-000000000000"
+        )
+
+
     def test_repr_name(self):
         """
         L{MatchExpression.__repr__} emits field name and value.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/2536e366/attachment.html>


More information about the calendarserver-changes mailing list