Revision
12755
Author
sagen@apple.com
Date
2014-02-26 13:17:32 -0800 (Wed, 26 Feb 2014)

Log Message

None is a legal value

Modified Paths

Diff

Modified: twext/trunk/twext/who/directory.py (12754 => 12755)


--- twext/trunk/twext/who/directory.py	2014-02-26 02:23:34 UTC (rev 12754)
+++ twext/trunk/twext/who/directory.py	2014-02-26 21:17:32 UTC (rev 12755)
@@ -365,7 +365,7 @@
             elif issubclass(expectedType, Names):
                 expectedType = NamedConstant
 
-            if not isinstance(value, expectedType):
+            if value is not None and not isinstance(value, expectedType):
                 raise InvalidDirectoryRecordError(
                     "Value {0!r} for field {1} is not of type {2}".format(
                         value, name, expectedType

Modified: twext/trunk/twext/who/test/test_directory.py (12754 => 12755)


--- twext/trunk/twext/who/test/test_directory.py	2014-02-26 02:23:34 UTC (rev 12754)
+++ twext/trunk/twext/who/test/test_directory.py	2014-02-26 21:17:32 UTC (rev 12755)
@@ -588,6 +588,13 @@
         FieldName.shortNames: (u"nobody",),
     }
 
+    fields_none_password = {
+        FieldName.uid: u"UID:nobody",
+        FieldName.recordType: RecordType.user,
+        FieldName.shortNames: (u"nobody",),
+        FieldName.password: None,
+    }
+
     fields_staff = {
         FieldName.uid: u"UID:staff",
         FieldName.recordType: RecordType.group,
@@ -732,6 +739,16 @@
         )
 
 
+    def test_noneIsAllowed(self):
+        """
+        Verify a value of None is allowed
+        """
+        service  = self.service()
+        record = self.makeRecord(self.fields_none_password, service=service)
+
+        self.assertEquals(record.password, None)
+
+
     def _test_containerClassFieldType(self, callback):
         """
         Scaffold for test_initWithContainerClassFieldType_*.