[CalendarServer-changes] [11979] CalendarServer/trunk/twext/who/test

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


Revision: 11979
          http://trac.calendarserver.org//changeset/11979
Author:   wsanchez at apple.com
Date:     2013-11-19 17:24:56 -0800 (Tue, 19 Nov 2013)
Log Message:
-----------
More test refactoring.

Modified Paths:
--------------
    CalendarServer/trunk/twext/who/test/test_aggregate.py
    CalendarServer/trunk/twext/who/test/test_directory.py
    CalendarServer/trunk/twext/who/test/test_index.py
    CalendarServer/trunk/twext/who/test/test_xml.py

Modified: CalendarServer/trunk/twext/who/test/test_aggregate.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_aggregate.py	2013-11-20 01:24:20 UTC (rev 11978)
+++ CalendarServer/trunk/twext/who/test/test_aggregate.py	2013-11-20 01:24:56 UTC (rev 11979)
@@ -31,7 +31,7 @@
 
 
 class BaseTest(object):
-    def service(self, services=None):
+    def service(self, subClass=None, services=None):
         if services is None:
             services = (self.xmlService(),)
 
@@ -45,14 +45,21 @@
             for s in services
         ))
 
-        class TestService(DirectoryService, QueryMixIn):
+        if subClass is None:
+            subClass = DirectoryService
+
+        class TestService(subClass, QueryMixIn):
             pass
 
         return TestService(u"xyzzy", services)
 
 
     def xmlService(self, xmlData=None, serviceClass=None):
-        return xmlService(self.mktemp(), xmlData, serviceClass)
+        return xmlService(
+            self.mktemp(),
+            xmlData=xmlData,
+            serviceClass=serviceClass
+        )
 
 
 
@@ -81,7 +88,7 @@
 
 
 class AggregatedBaseTest(BaseTest):
-    def service(self):
+    def service(self, subClass=None):
         class UsersDirectoryService(XMLTestService):
             recordType = ConstantsContainer((XMLTestService.recordType.user,))
 
@@ -89,15 +96,19 @@
             recordType = ConstantsContainer((XMLTestService.recordType.group,))
 
         usersService = self.xmlService(
-            testXMLConfigUsers,
-            UsersDirectoryService
+            xmlData=testXMLConfigUsers,
+            serviceClass=UsersDirectoryService
         )
         groupsService = self.xmlService(
-            testXMLConfigGroups,
-            GroupsDirectoryService
+            xmlData=testXMLConfigGroups,
+            serviceClass=GroupsDirectoryService
         )
 
-        return BaseTest.service(self, (usersService, groupsService))
+        return BaseTest.service(
+            self,
+            subClass=None,
+            services=(usersService, groupsService)
+        )
 
 
 
@@ -129,8 +140,8 @@
     def test_conflictingRecordTypes(self):
         self.assertRaises(
             DirectoryConfigurationError,
-            BaseTest.service, self,
-            (self.xmlService(), self.xmlService(testXMLConfigUsers)),
+            self.service,
+            services=(self.xmlService(), self.xmlService(testXMLConfigUsers)),
         )
 
 

Modified: CalendarServer/trunk/twext/who/test/test_directory.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_directory.py	2013-11-20 01:24:20 UTC (rev 11978)
+++ CalendarServer/trunk/twext/who/test/test_directory.py	2013-11-20 01:24:56 UTC (rev 11979)
@@ -92,9 +92,11 @@
     realmName = u"xyzzy"
 
 
-    def service(self):
+    def service(self, subClass=None):
         if not hasattr(self, "_service"):
-            self._service = self.serviceClass(self.realmName)
+            if subClass is None:
+                subClass = self.serviceClass
+            self._service = subClass(self.realmName)
         return self._service
 
 

Modified: CalendarServer/trunk/twext/who/test/test_index.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_index.py	2013-11-20 01:24:20 UTC (rev 11978)
+++ CalendarServer/trunk/twext/who/test/test_index.py	2013-11-20 01:24:56 UTC (rev 11979)
@@ -27,10 +27,12 @@
 
 
 
-class NoLoadDirectoryService(DirectoryService):
-    def loadRecords(self):
-        pass
+def noLoadDirectoryService(superClass):
+    class NoLoadDirectoryService(superClass):
+        def loadRecords(self):
+            pass
 
+    return NoLoadDirectoryService
 
 
 # class StubDirectoryService(DirectoryService):
@@ -55,7 +57,9 @@
         L{DirectoryService.indexRecords} ensures all record data is in the
         index.
         """
-        service = NoLoadDirectoryService(u"")
+        service = self.service(
+            subClass=noLoadDirectoryService(self.serviceClass)
+        )
         records = RecordStorage(service, DirectoryRecord)
 
         service.indexRecords(records)
@@ -85,7 +89,9 @@
         """
         L{DirectoryService.indexRecords} does not have extra data in the index.
         """
-        service = NoLoadDirectoryService(u"")
+        service = self.service(
+            subClass=noLoadDirectoryService(self.serviceClass)
+        )
         records = RecordStorage(service, DirectoryRecord)
 
         service.indexRecords(records)
@@ -149,7 +155,9 @@
         """
         C{flush} sets the index to C{None}.
         """
-        service = NoLoadDirectoryService(u"")
+        service = self.service(
+            subClass=noLoadDirectoryService(self.serviceClass)
+        )
         service._index = {}
         service.flush()
         self.assertTrue(emptyIndex(service._index))

Modified: CalendarServer/trunk/twext/who/test/test_xml.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_xml.py	2013-11-20 01:24:20 UTC (rev 11978)
+++ CalendarServer/trunk/twext/who/test/test_xml.py	2013-11-20 01:24:56 UTC (rev 11979)
@@ -36,8 +36,12 @@
 
 
 class BaseTest(object):
-    def service(self, xmlData=None):
-        return xmlService(self.mktemp(), xmlData)
+    def service(self, subClass=None, xmlData=None):
+        return xmlService(
+            self.mktemp(),
+            xmlData=xmlData,
+            serviceClass=subClass
+        )
 
 
     def assertRecords(self, records, uids):
@@ -842,7 +846,13 @@
     filePath = FilePath(tmp)
     filePath.setContent(xmlData)
 
-    return serviceClass(filePath)
+    try:
+        return serviceClass(filePath)
+    except Exception as e:
+        raise AssertionError(
+            "Unable to instantiate XML service {0}: {1}"
+            .format(serviceClass, e)
+        )
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/58a192f3/attachment.html>


More information about the calendarserver-changes mailing list