[CalendarServer-changes] [11983] CalendarServer/trunk/twext/who/test/test_index.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:15:56 PDT 2014


Revision: 11983
          http://trac.calendarserver.org//changeset/11983
Author:   wsanchez at apple.com
Date:     2013-11-20 00:03:57 -0800 (Wed, 20 Nov 2013)
Log Message:
-----------
Add test_indexedRecordsFromMatchExpression_*

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

Modified: CalendarServer/trunk/twext/who/test/test_index.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_index.py	2013-11-20 02:54:52 UTC (rev 11982)
+++ CalendarServer/trunk/twext/who/test/test_index.py	2013-11-20 08:03:57 UTC (rev 11983)
@@ -19,8 +19,10 @@
 """
 
 from twisted.trial import unittest
+from twisted.internet.defer import inlineCallbacks
 
 from twext.who.idirectory import FieldName as BaseFieldName
+from twext.who.expression import MatchExpression, MatchType
 from twext.who.index import DirectoryService, DirectoryRecord
 from twext.who.test import test_directory
 from twext.who.test.test_directory import RecordStorage
@@ -124,35 +126,67 @@
         self.assertTrue(emptyIndex(service.index))
 
 
+    @inlineCallbacks
+    def _test_indexedRecordsFromMatchExpression(self, inOut, matchType):
+        service = self.noLoadServicePopulated()
+
+        for subString, uids in (inOut):
+            records = yield service.indexedRecordsFromMatchExpression(
+                MatchExpression(
+                    service.fieldName.shortNames, subString,
+                    matchType
+                )
+            )
+            self.assertEquals(
+                set((record.uid for record in records)),
+                set(uids)
+            )
+
+
     def test_indexedRecordsFromMatchExpression_startsWith(self):
         """
-        L{DirectoryService.indexedRecordsFromMatchExpression} ...
+        L{DirectoryService.indexedRecordsFromMatchExpression} with a startsWith
+        expression.
         """
-        # service = self.noLoadServicePopulated()
+        return self._test_indexedRecordsFromMatchExpression(
+            (
+                (u"w", (u"__wsanchez__",)),           # Duplicates
+                (u"dr", (u"__dre__", u"__dreid__")),  # Multiple
+                (u"sage", (u"__sagen__",)),           # Single
+            ),
+            MatchType.startsWith
+        )
 
-        raise NotImplementedError()
 
-    test_indexedRecordsFromMatchExpression_startsWith.todo = "Unimplemented"
-
-
     def test_indexedRecordsFromMatchExpression_contains(self):
         """
-        L{DirectoryService.indexedRecordsFromMatchExpression} ...
+        L{DirectoryService.indexedRecordsFromMatchExpression} with a contains
+        expression.
         """
-        raise NotImplementedError()
+        return self._test_indexedRecordsFromMatchExpression(
+            (
+                (u"sanch", (u"__wsanchez__",)),       # Duplicates
+                (u"dr", (u"__dre__", u"__dreid__")),  # Multiple
+                (u"agen", (u"__sagen__",)),           # Single
+            ),
+            MatchType.contains
+        )
 
-    test_indexedRecordsFromMatchExpression_contains.todo = "Unimplemented"
 
-
     def test_indexedRecordsFromMatchExpression_equals(self):
         """
-        L{DirectoryService.indexedRecordsFromMatchExpression} ...
+        L{DirectoryService.indexedRecordsFromMatchExpression} with an equals
+        expression.
         """
-        raise NotImplementedError()
+        return self._test_indexedRecordsFromMatchExpression(
+            (
+                (u"wsanchez", (u"__wsanchez__",)),  # MultiValue
+                (u"dre", (u"__dre__",)),            # Single value
+            ),
+            MatchType.equals
+        )
 
-    test_indexedRecordsFromMatchExpression_equals.todo = "Unimplemented"
 
-
     def test_unIndexedRecordsFromMatchExpression(self):
         """
         L{DirectoryService.unIndexedRecordsFromMatchExpression} ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/f7ed5851/attachment.html>


More information about the calendarserver-changes mailing list