[CalendarServer-changes] [13259] twext/trunk/twext/who/opendirectory
source_changes at macosforge.org
source_changes at macosforge.org
Thu Apr 10 17:38:45 PDT 2014
Revision: 13259
http://trac.calendarserver.org//changeset/13259
Author: gaya at apple.com
Date: 2014-04-10 17:38:45 -0700 (Thu, 10 Apr 2014)
Log Message:
-----------
Add test_queryStringFromExpression_recordType test and fix recordType NOT match
Modified Paths:
--------------
twext/trunk/twext/who/opendirectory/_service.py
twext/trunk/twext/who/opendirectory/test/test_service.py
Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py 2014-04-11 00:24:32 UTC (rev 13258)
+++ twext/trunk/twext/who/opendirectory/_service.py 2014-04-11 00:38:45 UTC (rev 13259)
@@ -279,8 +279,10 @@
for subExpression in expression.expressions:
queryToken, subExpRecordTypes = self._queryStringAndRecordTypesFromExpression(subExpression)
if subExpRecordTypes:
- if expression.operand is Operand.AND or queryToken == u"!": # AND or NOR
+ if expression.operand is Operand.AND:
recordTypes |= subExpRecordTypes
+ elif queryToken == u"!": #NOR
+ recordTypes |= set([t.value for t in ODRecordType.iterconstants()]) - subExpRecordTypes
else:
raise QueryNotSupportedError(
"Record type matches must AND or NOR"
@@ -398,9 +400,6 @@
flags = tuple(expression.flags)
- if MatchFlags.NOT in flags:
- raise NotImplementedError()
-
if MatchFlags.caseInsensitive in flags:
caseInsensitive = 0x100
else:
@@ -425,11 +424,17 @@
recordTypes = ODRecordType.fromRecordType(
expression.fieldValue
).value
+ if MatchFlags.NOT in flags:
+ recordTypes = set([t.value for t in ODRecordType.iterconstants()]) - recordTypes
+
matchType = ODMatchType.any.value
queryAttribute = None
queryValue = None
else:
+ if MatchFlags.NOT in flags:
+ raise NotImplementedError()
+
if recordType is None:
recordTypes = [t.value for t in ODRecordType.iterconstants()]
else:
Modified: twext/trunk/twext/who/opendirectory/test/test_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/test/test_service.py 2014-04-11 00:24:32 UTC (rev 13258)
+++ twext/trunk/twext/who/opendirectory/test/test_service.py 2014-04-11 00:38:45 UTC (rev 13259)
@@ -27,9 +27,9 @@
)
from .._constants import ODAttribute
from .._service import DirectoryService
+from ...idirectory import QueryNotSupportedError
-
class OpenDirectoryServiceTestCase(unittest.TestCase):
"""
Tests for L{DirectoryService}.
@@ -225,3 +225,139 @@
u"(dsAttrTypeStandard:RealName=c))"
)
)
+
+
+ def test_queryStringFromExpression_recordType(self):
+ """
+ Record type in expression
+ """
+ service = DirectoryService()
+
+ # AND expression
+ expression = CompoundExpression(
+ [
+ MatchExpression(
+ service.fieldName.shortNames,
+ u"xyzzy",
+ matchType=MatchType.equals
+ ),
+ MatchExpression(
+ service.fieldName.recordType,
+ service.recordType.group,
+ matchType=MatchType.equals
+ ),
+ MatchExpression(
+ service.fieldName.recordType,
+ service.recordType.user,
+ matchType=MatchType.equals
+ ),
+ ],
+ Operand.AND
+ )
+ queryString, recordTypes = service._queryStringAndRecordTypesFromExpression(expression)
+ self.assertEquals(set(recordTypes), set([u"dsRecTypeStandard:Groups", u"dsRecTypeStandard:Users"]))
+ self.assertEquals(
+ queryString,
+ u"(dsAttrTypeStandard:RecordName=xyzzy)"
+ )
+
+ # AND subexpression
+ expression = CompoundExpression(
+ [
+ MatchExpression(
+ service.fieldName.shortNames,
+ u"xyzzy",
+ matchType=MatchType.equals
+ ),
+ CompoundExpression(
+ [
+
+ MatchExpression(
+ service.fieldName.recordType,
+ service.recordType.group,
+ matchType=MatchType.equals
+ ),
+ MatchExpression(
+ service.fieldName.recordType,
+ service.recordType.user,
+ matchType=MatchType.equals
+ ),
+ ],
+ Operand.AND
+ ),
+ ],
+ Operand.AND
+ )
+ queryString, recordTypes = service._queryStringAndRecordTypesFromExpression(expression)
+ self.assertEquals(set(recordTypes), set([u"dsRecTypeStandard:Groups", u"dsRecTypeStandard:Users"]))
+ self.assertEquals(
+ queryString,
+ u"(dsAttrTypeStandard:RecordName=xyzzy)"
+ )
+
+ # NOR expression
+ expression = CompoundExpression(
+ [
+ MatchExpression(
+ service.fieldName.shortNames,
+ u"xxxxx",
+ matchType=MatchType.equals
+ ),
+ MatchExpression(
+ service.fieldName.shortNames,
+ u"yyyyy",
+ matchType=MatchType.equals
+ ),
+ MatchExpression(
+ service.fieldName.recordType,
+ service.recordType.user,
+ matchType=MatchType.equals,
+ flags=MatchFlags.NOT
+ ),
+ ],
+ Operand.OR
+ )
+ queryString, recordTypes = service._queryStringAndRecordTypesFromExpression(expression)
+ self.assertEquals(set(recordTypes), set([u"dsRecTypeStandard:Groups"]))
+ self.assertEquals(
+ queryString,
+ u"("
+ u"|(dsAttrTypeStandard:RecordName=xxxxx)"
+ u"(dsAttrTypeStandard:RecordName=yyyyy)"
+ u")"
+ )
+
+ # Simple AND expression -> empty query string
+ expression = CompoundExpression(
+ [
+ MatchExpression(
+ service.fieldName.recordType,
+ service.recordType.user,
+ matchType=MatchType.equals
+ ),
+ ],
+ Operand.AND
+ )
+ queryString, recordTypes = service._queryStringAndRecordTypesFromExpression(expression)
+ self.assertEquals(set(recordTypes), set([u"dsRecTypeStandard:Users"]))
+ self.assertEquals(
+ queryString,
+ u""
+ )
+
+ # recordType OR expression raises QueryNotSupportedError
+ expression = CompoundExpression(
+ [
+ MatchExpression(
+ service.fieldName.recordType,
+ service.recordType.user,
+ matchType=MatchType.equals
+ ),
+ ],
+ Operand.OR
+ )
+ self.assertRaises(
+ QueryNotSupportedError,
+ service._queryStringAndRecordTypesFromExpression,
+ expression,
+ )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140410/38144a5a/attachment-0001.html>
More information about the calendarserver-changes
mailing list