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

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


Revision: 12522
          http://trac.calendarserver.org//changeset/12522
Author:   wsanchez at apple.com
Date:     2014-01-31 14:23:49 -0800 (Fri, 31 Jan 2014)
Log Message:
-----------
MatchExpression() now raises if the field name is not a L{NamedConstant}.

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:23:11 UTC (rev 12521)
+++ twext/trunk/twext/who/expression.py	2014-01-31 22:23:49 UTC (rev 12522)
@@ -205,6 +205,12 @@
         fieldName, fieldValue,
         matchType=MatchType.equals, flags=MatchFlags.none
     ):
+        if not isinstance(fieldName, NamedConstant):
+            raise TypeError(
+                "Field name {name} in match expression is not a NamedConstant."
+                .format(name=fieldName)
+            )
+
         valueType = FieldName.valueType(fieldName)
         if not isinstance(fieldValue, valueType):
             raise TypeError(

Modified: twext/trunk/twext/who/test/test_expression.py
===================================================================
--- twext/trunk/twext/who/test/test_expression.py	2014-01-31 22:23:11 UTC (rev 12521)
+++ twext/trunk/twext/who/test/test_expression.py	2014-01-31 22:23:49 UTC (rev 12522)
@@ -75,6 +75,17 @@
     Tests for L{MatchExpression}.
     """
 
+    def test_initBadType_name(self):
+        """
+        L{MatchExpression.__init__} raises if the field name is not a
+        L{NamedConstant}.
+        """
+        self.assertRaises(
+            TypeError,
+            MatchExpression, u"uid", u"some value"
+        )
+
+
     def test_initBadType_value(self):
         """
         L{MatchExpression.__init__} raises if the field value doesn't match the
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/380fac11/attachment.html>


More information about the calendarserver-changes mailing list