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

source_changes at macosforge.org source_changes at macosforge.org
Thu Feb 21 16:37:09 PST 2013


Revision: 10779
          http://trac.calendarserver.org//changeset/10779
Author:   wsanchez at apple.com
Date:     2013-02-21 16:37:09 -0800 (Thu, 21 Feb 2013)
Log Message:
-----------
Basic tests and fixes for aggregate.

Modified Paths:
--------------
    CalendarServer/trunk/twext/who/aggregate.py
    CalendarServer/trunk/twext/who/test/test_aggregate.py

Modified: CalendarServer/trunk/twext/who/aggregate.py
===================================================================
--- CalendarServer/trunk/twext/who/aggregate.py	2013-02-22 00:11:05 UTC (rev 10778)
+++ CalendarServer/trunk/twext/who/aggregate.py	2013-02-22 00:37:09 UTC (rev 10779)
@@ -26,13 +26,14 @@
 
 from itertools import chain
 
-from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.internet.defer import gatherResults
+#from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.defer import gatherResults, FirstError
 
 from twext.who.idirectory import DirectoryConfigurationError
 from twext.who.idirectory import IDirectoryService
 from twext.who.index import DirectoryService as BaseDirectoryService
 from twext.who.index import DirectoryRecord
+from twext.who.util import ConstantsContainer
 
 
 class DirectoryService(BaseDirectoryService):
@@ -44,7 +45,7 @@
         recordTypes = set()
 
         for service in services:
-            if not IDirectoryService.implementedBy(service):
+            if not IDirectoryService.implementedBy(service.__class__):
                 raise ValueError("Not a directory service: %s" % (service,))
 
             for recordType in service.recordTypes():
@@ -64,23 +65,27 @@
         return self._services
 
 
-    @inlineCallbacks
-    def recordTypes(self):
-        if not hasattr(self, "_recordTypes"):
-            recordTypes = set()
-            for service in self._services:
-                for recordType in (yield service.recordTypes()):
-                    recordTypes.add(recordType)
+    @property
+    def recordType(self):
+        if not hasattr(self, "_recordType"):
+            self._recordType = ConstantsContainer(chain(*tuple(
+                s.recordTypes()
+                for s in self.services
+            )))
+        return self._recordType
 
-            self._recordTypes = recordTypes
 
-        returnValue(self._recordTypes)
-
-
     def recordsFromExpression(self, expression, records=None):
         ds = []
         for service in self.services:
             d = service.recordsFromExpression(expression, records)
             ds.append(d)
 
-        return gatherResults(ds).addCallback(chain)
+        def unwrapFirstError(f):
+            f.trap(FirstError)
+            return f.value.subFailure
+
+        d = gatherResults(ds, consumeErrors=True)
+        d.addCallback(chain)
+        d.addErrback(unwrapFirstError)
+        return d

Modified: CalendarServer/trunk/twext/who/test/test_aggregate.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_aggregate.py	2013-02-22 00:11:05 UTC (rev 10778)
+++ CalendarServer/trunk/twext/who/test/test_aggregate.py	2013-02-22 00:37:09 UTC (rev 10779)
@@ -18,21 +18,38 @@
 Aggregate directory service tests
 """
 
+from twisted.python.components import proxyForInterface
+
+from twext.who.idirectory import IDirectoryService
 from twext.who.aggregate import DirectoryService
 
-#from twext.who.test import test_directory
+from twext.who.test import test_directory
 from twext.who.test.test_xml import xmlService
 
 
 
 class BaseTest(object):
-    def service(self, subservices=()):
-        return DirectoryService("xyzzy", subservices)
+    def service(self, services=None):
+        if services is None:
+            services = (self.xmlService(),)
 
+        #
+        # Make sure aggregate DirectoryService isn't making
+        # implementation assumptions about the IDirectoryService
+        # objects it gets.
+        #
+#        services = tuple((
+#            proxyForInterface(IDirectoryService)(s)
+#            for s in services
+#        ))
+
+        return DirectoryService("xyzzy", services)
+
+
     def xmlService(self, xmlData=None):
         return xmlService(self.mktemp(), xmlData)
 
 
 
-#class DirectoryServiceTest(BaseTest, test_directory.DirectoryServiceTest):
-#    pass
+class DirectoryServiceTest(BaseTest, test_directory.DirectoryServiceTest):
+    pass
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130221/e5d69299/attachment-0001.html>


More information about the calendarserver-changes mailing list