[CalendarServer-changes] [11984] CalendarServer/trunk/twext/who
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:19:46 PDT 2014
Revision: 11984
http://trac.calendarserver.org//changeset/11984
Author: wsanchez at apple.com
Date: 2013-11-20 00:34:59 -0800 (Wed, 20 Nov 2013)
Log Message:
-----------
Add:
- test_indexedRecordsFromMatchExpression_notIndexed
- test_indexedRecordsFromMatchExpression_notMatchExpression
Modified Paths:
--------------
CalendarServer/trunk/twext/who/index.py
CalendarServer/trunk/twext/who/test/test_index.py
Modified: CalendarServer/trunk/twext/who/index.py
===================================================================
--- CalendarServer/trunk/twext/who/index.py 2013-11-20 08:03:57 UTC (rev 11983)
+++ CalendarServer/trunk/twext/who/index.py 2013-11-20 08:34:59 UTC (rev 11984)
@@ -30,7 +30,7 @@
from twisted.internet.defer import succeed, inlineCallbacks, returnValue
from twext.who.util import ConstantsContainer
-from twext.who.util import describe, uniqueResult
+from twext.who.util import uniqueResult
from twext.who.idirectory import FieldName as BaseFieldName
from twext.who.expression import MatchExpression, MatchType, MatchFlags
from twext.who.directory import DirectoryService as BaseDirectoryService
@@ -245,7 +245,15 @@
predicate = MatchFlags.predicator(expression.flags)
normalize = MatchFlags.normalizer(expression.flags)
- fieldIndex = self.index[expression.fieldName]
+ try:
+ fieldIndex = self.index[expression.fieldName]
+ except KeyError:
+ raise TypeError(
+ "indexedRecordsFromMatchExpression() was passed an "
+ "expression with an unindexed field: {0!r}"
+ .format(expression.fieldName)
+ )
+
matchValue = normalize(expression.fieldValue)
matchType = expression.matchType
@@ -269,7 +277,7 @@
)
else:
raise NotImplementedError(
- "Unknown match type: {0}".format(describe(matchType))
+ "Unknown match type: {0!r}".format(matchType)
)
matchingRecords = set()
@@ -313,7 +321,7 @@
match = lambda fieldValue: predicate(fieldValue == matchValue)
else:
raise NotImplementedError(
- "Unknown match type: {0}".format(describe(matchType))
+ "Unknown match type: {0!r}".format(matchType)
)
result = set()
Modified: CalendarServer/trunk/twext/who/test/test_index.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_index.py 2013-11-20 08:03:57 UTC (rev 11983)
+++ CalendarServer/trunk/twext/who/test/test_index.py 2013-11-20 08:34:59 UTC (rev 11984)
@@ -127,13 +127,17 @@
@inlineCallbacks
- def _test_indexedRecordsFromMatchExpression(self, inOut, matchType):
+ def _test_indexedRecordsFromMatchExpression(
+ self,
+ inOut, matchType,
+ fieldName=BaseFieldName.shortNames,
+ ):
service = self.noLoadServicePopulated()
for subString, uids in (inOut):
records = yield service.indexedRecordsFromMatchExpression(
MatchExpression(
- service.fieldName.shortNames, subString,
+ fieldName, subString,
matchType
)
)
@@ -187,6 +191,35 @@
)
+ def test_indexedRecordsFromMatchExpression_notIndexed(self):
+ """
+ L{DirectoryService.indexedRecordsFromMatchExpression} with an
+ unindexed field name.
+ """
+ result = self._test_indexedRecordsFromMatchExpression(
+ (
+ (u"zehcnasw", (u"__wsanchez__",)),
+ ),
+ MatchType.equals,
+ fieldName=BaseFieldName.password
+ )
+ self.assertFailure(result, TypeError)
+
+
+ def test_indexedRecordsFromMatchExpression_notMatchExpression(self):
+ """
+ L{DirectoryService.indexedRecordsFromMatchExpression} with a
+ non-match expression.
+ """
+ result = self._test_indexedRecordsFromMatchExpression(
+ (
+ (u"zehcnasw", (u"__wsanchez__",)),
+ ),
+ "Not a match type we know about"
+ )
+ self.assertFailure(result, NotImplementedError)
+
+
def test_unIndexedRecordsFromMatchExpression(self):
"""
L{DirectoryService.unIndexedRecordsFromMatchExpression} ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/46df34be/attachment.html>
More information about the calendarserver-changes
mailing list