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

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 19 17:16:14 PDT 2014


Revision: 12977
          http://trac.calendarserver.org//changeset/12977
Author:   wsanchez at apple.com
Date:     2014-03-19 17:16:14 -0700 (Wed, 19 Mar 2014)
Log Message:
-----------
raise InvalidDirectoryRecordError if a field name is not a NamedConstant.

Modified Paths:
--------------
    twext/trunk/twext/who/directory.py
    twext/trunk/twext/who/test/test_directory.py

Modified: twext/trunk/twext/who/directory.py
===================================================================
--- twext/trunk/twext/who/directory.py	2014-03-20 00:09:13 UTC (rev 12976)
+++ twext/trunk/twext/who/directory.py	2014-03-20 00:16:14 UTC (rev 12977)
@@ -276,8 +276,12 @@
                     yield self.recordsFromExpression(
                         CompoundExpression(
                             (
-                                MatchExpression(FieldName.recordType, recordType),
-                                MatchExpression(FieldName.shortNames, shortName),
+                                MatchExpression(
+                                    FieldName.recordType, recordType
+                                ),
+                                MatchExpression(
+                                    FieldName.shortNames, shortName
+                                ),
                             ),
                             operand=Operand.AND
                         )
@@ -380,6 +384,12 @@
         # Normalize fields
         normalizedFields = {}
         for name, value in fields.items():
+            if not isinstance(name, NamedConstant):
+                raise InvalidDirectoryRecordError(
+                    "Field name {} is not a named constant".format(name),
+                    fields
+                )
+
             normalize = service.normalizedFields.get(name, None)
 
             if normalize is None:

Modified: twext/trunk/twext/who/test/test_directory.py
===================================================================
--- twext/trunk/twext/who/test/test_directory.py	2014-03-20 00:09:13 UTC (rev 12976)
+++ twext/trunk/twext/who/test/test_directory.py	2014-03-20 00:16:14 UTC (rev 12977)
@@ -646,6 +646,21 @@
         self.assertEquals(wsanchez.fields, self.fields_wsanchez)
 
 
+    def test_initWithNonConstantFieldName(self):
+        """
+        Directory record field names must be L{NamedConstant}s.
+        """
+        service = self.service()
+
+        fields = self.fields_wsanchez.copy()
+        fields["name"] = u"value"  # Key is not a NamedConstant.
+
+        self.assertRaises(
+            InvalidDirectoryRecordError,
+            self.makeRecord, fields, service=service
+        )
+
+
     def test_initWithNoUID(self):
         """
         Directory records must have a UID.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140319/8ea024a3/attachment.html>


More information about the calendarserver-changes mailing list