[CalendarServer-changes] [11976] CalendarServer/trunk/twext/who/test/test_directory.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:24:58 PDT 2014


Revision: 11976
          http://trac.calendarserver.org//changeset/11976
Author:   wsanchez at apple.com
Date:     2013-11-19 14:51:43 -0800 (Tue, 19 Nov 2013)
Log Message:
-----------
More refactor

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

Modified: CalendarServer/trunk/twext/who/test/test_directory.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_directory.py	2013-11-19 22:38:56 UTC (rev 11975)
+++ CalendarServer/trunk/twext/who/test/test_directory.py	2013-11-19 22:51:43 UTC (rev 11976)
@@ -36,6 +36,54 @@
 
 
 
+class StubDirectoryService(DirectoryService):
+    """
+    Stub directory service with some built-in records and an implementation
+    of C{recordsFromNonCompoundExpression}.
+    """
+
+    def __init__(self, realmName):
+        DirectoryService.__init__(self, realmName)
+
+        self.records = RecordStorage(self, DirectoryRecord)
+
+
+    def recordsFromExpression(self, expression):
+        self.seenExpressions = []
+
+        return DirectoryService.recordsFromExpression(self, expression)
+
+
+    def recordsFromNonCompoundExpression(self, expression, records=None):
+        """
+        This implementation handles three expressions:
+
+        The expression C{u"None"} will match no records.
+
+        The expressions C{u"twistedmatrix.com"} and C{u"calendarserver.org"}
+        will match records that have an email address ending with the
+        given expression.
+        """
+        self.seenExpressions.append(expression)
+
+        if expression == u"None":
+            return succeed([])
+
+        if expression in (u"twistedmatrix.com", u"calendarserver.org"):
+            result = []
+            for record in self.records:
+                for email in record.emailAddresses:
+                    if email.endswith(expression):
+                        result.append(record)
+                        break
+            return succeed(result)
+
+        return DirectoryService.recordsFromNonCompoundExpression(
+            self, expression, records=records
+        )
+
+
+
 class ServiceMixIn(object):
     """
     MixIn that sets up a service appropriate for testing.
@@ -216,7 +264,7 @@
     """
     Tests for L{DirectoryService.recordsFromExpression}.
     """
-    serviceClass = DirectoryService
+    serviceClass = StubDirectoryService
     directoryRecordClass = DirectoryRecord
 
     @inlineCallbacks
@@ -775,62 +823,6 @@
 
 
 
-class RFNCEMixIn(object):
-    """
-    Mixin class that implements C{recordsFromNonCompoundExpression}.
-
-    This class also sets a C{seenExpressions} attribute to C{[]} when
-    C{recordsFromExpression} is called and appends the expressions seen when
-    C{recordsFromNonCompoundExpression} is subsequently called to that list.
-    """
-
-    def recordsFromExpression(self, expression):
-        self.seenExpressions = []
-
-        return DirectoryService.recordsFromExpression(self, expression)
-
-
-    def recordsFromNonCompoundExpression(self, expression, records=None):
-        """
-        This implementation handles three expressions:
-
-        The expression C{u"None"} will match no records.
-
-        The expressions C{u"twistedmatrix.com"} and C{u"calendarserver.org"}
-        will match records that have an email address ending with the
-        given expression.
-        """
-        self.seenExpressions.append(expression)
-
-        if expression == u"None":
-            return succeed([])
-
-        if expression in (u"twistedmatrix.com", u"calendarserver.org"):
-            result = []
-            for record in self.records:
-                for email in record.emailAddresses:
-                    if email.endswith(expression):
-                        result.append(record)
-                        break
-            return succeed(result)
-
-        return DirectoryService.recordsFromNonCompoundExpression(
-            self, expression, records=records
-        )
-
-
-class StubDirectoryService(RFNCEMixIn, DirectoryService):
-    """
-    Stub directory service with some built-in records and an implementation
-    of C{recordsFromNonCompoundExpression}.
-    """
-
-    def __init__(self):
-        DirectoryService.__init__(self, u"Stub")
-
-        self.records = RecordStorage(self, DirectoryRecord)
-
-
 class RecordStorage(object):
     """
     Container for directory records.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/a7aafd02/attachment.html>


More information about the calendarserver-changes mailing list