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

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


Revision: 11911
          http://trac.calendarserver.org//changeset/11911
Author:   wsanchez at apple.com
Date:     2013-11-07 18:59:43 -0800 (Thu, 07 Nov 2013)
Log Message:
-----------
test docs

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

Modified: CalendarServer/trunk/twext/who/directory.py
===================================================================
--- CalendarServer/trunk/twext/who/directory.py	2013-11-08 02:19:57 UTC (rev 11910)
+++ CalendarServer/trunk/twext/who/directory.py	2013-11-08 02:59:43 UTC (rev 11911)
@@ -132,6 +132,11 @@
 
         @param records: a set of records to limit the search to. C{None} if
             the whole directory should be searched.
+            This is provided by L{recordsFromExpression} when it has already
+            narrowed down results to a set of records.
+            That is, it's a performance optimization; ignoring this and
+            searching the entire directory will also work.
+
         @type records: L{set} or L{frozenset}
 
         @return: The matching records.
@@ -140,6 +145,12 @@
         @raises: L{QueryNotSupportedError} if the expression is not
             supported by this directory service.
         """
+        if records is not None:
+            for record in records:
+                break
+            else:
+                return succeed(())
+
         return fail(QueryNotSupportedError(
             "Unknown expression: {0}".format(expression)
         ))

Modified: CalendarServer/trunk/twext/who/test/test_directory.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_directory.py	2013-11-08 02:19:57 UTC (rev 11910)
+++ CalendarServer/trunk/twext/who/test/test_directory.py	2013-11-08 02:59:43 UTC (rev 11911)
@@ -27,11 +27,15 @@
 from twext.who.idirectory import QueryNotSupportedError, NotAllowedError
 from twext.who.idirectory import RecordType, FieldName
 from twext.who.idirectory import IDirectoryService, IDirectoryRecord
+from twext.who.idirectory import Operand
 from twext.who.expression import CompoundExpression
 from twext.who.directory import DirectoryService, DirectoryRecord
 
 
 class ServiceMixIn(object):
+    """
+    MixIn that sets up a service appropriate for testing.
+    """
     realmName = u"xyzzy"
 
 
@@ -43,7 +47,14 @@
 
 
 class BaseDirectoryServiceTest(ServiceMixIn):
+    """
+    Tests for directory services.
+    """
+
     def test_interface(self):
+        """
+        Service instance conforms to L{IDirectoryService}.
+        """
         service = self.service()
         try:
             verifyObject(IDirectoryService, service)
@@ -52,16 +63,27 @@
 
 
     def test_init(self):
+        """
+        Test initialization.
+        """
         service = self.service()
         self.assertEquals(service.realmName, self.realmName)
 
 
     def test_repr(self):
+        """
+        C{repr()} returns the expected string.
+        """
         service = self.service()
         self.assertEquals(repr(service), "<DirectoryService u'xyzzy'>")
 
 
     def test_recordTypes(self):
+        """
+        C{recordTypes} returns the supported set of record types.
+        For L{DirectoryService}, that's the set of constants in the
+        C{recordType} attribute.
+        """
         service = self.service()
         self.assertEquals(
             set(service.recordTypes()),
@@ -69,22 +91,58 @@
         )
 
 
-    # @inlineCallbacks
-    # def test_recordsFromExpressionNone(self):
-    #     service = self.service()
-    #     records = (yield service.recordsFromExpression(CompoundExpression()))
-    #     for record in records:
-    #         self.failTest("No records expected")
+    def test_recordsFromNonCompoundExpression_unknown(self):
+        """
+        C{recordsFromNonCompoundExpression} with an unknown expression type
+        fails with L{QueryNotSupportedError}.
+        """
+        service = self.service()
+        self.assertFailure(
+            service.recordsFromNonCompoundExpression(object()),
+            QueryNotSupportedError
+        )
 
 
-    # def test_recordsFromExpressionBogus(self):
-    #     service = self.service()
-    #     self.assertFailure(
-    #         service.recordsFromQuery(CompoundExpression(object(),)),
-    #         QueryNotSupportedError
-    #     )
+    @inlineCallbacks
+    def test_recordsFromNonCompoundExpression_unknown_empty(self):
+        """
+        C{recordsFromNonCompoundExpression} with an unknown expression type
+        and an empty C{records} set returns an empty result.
+        """
+        service = self.service()
+        result = (
+            yield service.recordsFromNonCompoundExpression(
+                object(), records=()
+            )
+        )
+        self.assertEquals(set(result), set(()))
 
 
+    def test_recordsFromExpression_unknown(self):
+        """
+        C{recordsFromExpression} with an unknown expression type fails with
+        L{QueryNotSupportedError}.
+        """
+        service = self.service()
+        result = yield(service.recordsFromExpression(object()))
+        self.assertFailure(result, QueryNotSupportedError)
+
+
+    @inlineCallbacks
+    def test_recordsFromExpression_empty(self):
+        """
+        C{recordsFromExpression} with an unknown expression type and an empty
+        C{records} set returns an empty result.
+        """
+        service = self.service()
+
+        for operand in Operand.iterconstants():
+            result = yield(service.recordsFromExpression(
+                CompoundExpression((), operand)
+            ))
+            self.assertEquals(set(result), set(()))
+
+
     def test_recordWithUID(self):
         raise SkipTest("Subclasses should implement this test.")
 
@@ -107,12 +165,6 @@
 
 
 class DirectoryServiceTest(unittest.TestCase, BaseDirectoryServiceTest):
-    def test_recordsFromExpression(self):
-        service = self.service()
-        result = yield(service.recordsFromExpression(None))
-        self.assertFailure(result, QueryNotSupportedError)
-
-
     def test_recordWithUID(self):
         service = self.service()
         self.assertFailure(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/33331b11/attachment.html>


More information about the calendarserver-changes mailing list