<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12250] twext/trunk/twext/who</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12250">12250</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-01-06 18:15:58 -0800 (Mon, 06 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Re-introduce _queryStringFromExpression().</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#twexttrunktwextwhoidirectorypy">twext/trunk/twext/who/idirectory.py</a></li>
<li><a href="#twexttrunktwextwhoopendirectory_constantspy">twext/trunk/twext/who/opendirectory/_constants.py</a></li>
<li><a href="#twexttrunktwextwhoopendirectory_servicepy">twext/trunk/twext/who/opendirectory/_service.py</a></li>
<li><a href="#twexttrunktwextwhoopendirectorytesttest_servicepy">twext/trunk/twext/who/opendirectory/test/test_service.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="twexttrunktwextwhoidirectorypy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/idirectory.py (12249 => 12250)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/idirectory.py        2014-01-07 02:10:02 UTC (rev 12249)
+++ twext/trunk/twext/who/idirectory.py        2014-01-07 02:15:58 UTC (rev 12250)
</span><span class="lines">@@ -73,6 +73,7 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Invalid directory record.
</span><span class="cx">     &quot;&quot;&quot;
</span><ins>+
</ins><span class="cx">     def __init__(self, message, fields):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @param message: An error message.
</span></span></pre></div>
<a id="twexttrunktwextwhoopendirectory_constantspy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/opendirectory/_constants.py (12249 => 12250)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/opendirectory/_constants.py        2014-01-07 02:10:02 UTC (rev 12249)
+++ twext/trunk/twext/who/opendirectory/_constants.py        2014-01-07 02:15:58 UTC (rev 12250)
</span><span class="lines">@@ -389,30 +389,39 @@
</span><span class="cx"> 
</span><span class="cx"> class ODMatchType(Values):
</span><span class="cx">     all = ValueConstant(0x0001)
</span><ins>+    all.queryString = u&quot;({attribute}=*)&quot;
</ins><span class="cx"> 
</span><span class="cx">     equals = ValueConstant(0x2001)
</span><span class="cx">     equals.matchType = MatchType.equals
</span><ins>+    equals.queryString = u&quot;({attribute}={value})&quot;
</ins><span class="cx"> 
</span><span class="cx">     startsWith = ValueConstant(0x2002)
</span><span class="cx">     startsWith.matchType = MatchType.startsWith
</span><ins>+    startsWith.queryString = u&quot;({attribute}={value}*)&quot;
</ins><span class="cx"> 
</span><span class="cx">     endsWith = ValueConstant(0x2003)
</span><span class="cx">     endsWith.matchType = MatchType.endsWith
</span><ins>+    endsWith.queryString = u&quot;({attribute}=*{value})&quot;
</ins><span class="cx"> 
</span><span class="cx">     contains = ValueConstant(0x2004)
</span><span class="cx">     contains.matchType = MatchType.contains
</span><ins>+    contains.queryString = u&quot;({attribute}=*{value}*)&quot;
</ins><span class="cx"> 
</span><span class="cx">     lessThan = ValueConstant(0x2005)
</span><span class="cx">     lessThan.matchType = MatchType.lessThan
</span><ins>+    lessThan.queryString = u&quot;({attribute}&lt;{value})&quot;
</ins><span class="cx"> 
</span><span class="cx">     greaterThan = ValueConstant(0x2006)
</span><span class="cx">     greaterThan.matchType = MatchType.greaterThan
</span><ins>+    greaterThan.queryString = u&quot;({attribute}&gt;{value})&quot;
</ins><span class="cx"> 
</span><span class="cx">     lessThanOrEqualTo = ValueConstant(0x2007)
</span><span class="cx">     lessThanOrEqualTo.matchType = MatchType.lessThanOrEqualTo
</span><ins>+    lessThanOrEqualTo.queryString = u&quot;({attribute}&lt;={value})&quot;
</ins><span class="cx"> 
</span><span class="cx">     greaterThanOrEqualTo = ValueConstant(0x2008)
</span><span class="cx">     greaterThanOrEqualTo.matchType = MatchType.greaterThanOrEqualTo
</span><ins>+    greaterThanOrEqualTo.queryString = u&quot;({attribute}&gt;={value})&quot;
</ins><span class="cx"> 
</span><span class="cx">     compound = ValueConstant(0x210B)
</span><span class="cx"> 
</span></span></pre></div>
<a id="twexttrunktwextwhoopendirectory_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/opendirectory/_service.py (12249 => 12250)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/opendirectory/_service.py        2014-01-07 02:10:02 UTC (rev 12249)
+++ twext/trunk/twext/who/opendirectory/_service.py        2014-01-07 02:15:58 UTC (rev 12250)
</span><span class="lines">@@ -40,7 +40,7 @@
</span><span class="cx">     DirectoryRecord as BaseDirectoryRecord,
</span><span class="cx"> )
</span><span class="cx"> from ..expression import (
</span><del>-    # CompoundExpression, Operand,
</del><ins>+    CompoundExpression, Operand,
</ins><span class="cx">     MatchExpression, MatchFlags,
</span><span class="cx"> )
</span><span class="cx"> from ..util import iterFlags, ConstantsContainer
</span><span class="lines">@@ -228,70 +228,102 @@
</span><span class="cx">             self._node = node
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    # def _queryStringFromExpression(self, expression):
-    #     &quot;&quot;&quot;
-    #     Converts either a MatchExpression or a CompoundExpression into a
-    #     native OpenDirectory query string.
</del><ins>+    def _queryStringFromMatchExpression(self, expression):
+        &quot;&quot;&quot;
+        Generates an LDAP query string from a match expression.
</ins><span class="cx"> 
</span><del>-    #     @param expression: The expression
-    #     @type expression: Either L{MatchExpression} or L{CompoundExpression}
</del><ins>+        @param expression: A match expression.
+        @type expression: L{MatchExpression}
</ins><span class="cx"> 
</span><del>-    #     @return: A native OpenDirectory query string
-    #     @rtype: C{unicode}
-    #     &quot;&quot;&quot;
</del><ins>+        @return: An LDAP query string.
+        @rtype: C{unicode}
+        &quot;&quot;&quot;
+        matchType = ODMatchType.fromMatchType(expression.matchType)
+        if matchType is None:
+            raise QueryNotSupportedError(
+                &quot;Unknown match type: {0}&quot;.format(matchType)
+            )
</ins><span class="cx"> 
</span><del>-    #     if isinstance(expression, MatchExpression):
-    #         matchType = ODMatchType.fromMatchType(expression.matchType)
-    #         if matchType is None:
-    #             raise QueryNotSupportedError(
-    #                 &quot;Unknown match type: {0}&quot;.format(matchType)
-    #             )
</del><ins>+        flags = tuple(iterFlags(expression.flags))
+        if MatchFlags.NOT in flags:
+            raise NotImplementedError(&quot;Need to handle NOT&quot;)
+        if MatchFlags.caseInsensitive in flags:
+            raise NotImplementedError(&quot;Need to handle caseInsensitive&quot;)
</ins><span class="cx"> 
</span><del>-    #         if expression.fieldName is self.fieldName.uid:
-    #             odAttr = ODAttribute.guid.value
-    #             value = expression.fieldValue
-    #         else:
-    #             odAttr = ODAttribute.fromFieldName(expression.fieldName)
-    #             if odAttr is None:
-    #                 raise OpenDirectoryQueryError(
-    #                     &quot;Unknown field name: {0}&quot;
-    #                     .format(expression.fieldName)
-    #                 )
-    #             odAttr = odAttr.value
-    #             value = expression.fieldValue
</del><ins>+        if expression.fieldName is self.fieldName.uid:
+            odAttr = ODAttribute.guid
+            value = expression.fieldValue
+        else:
+            odAttr = ODAttribute.fromFieldName(expression.fieldName)
+            if odAttr is None:
+                raise OpenDirectoryQueryError(
+                    &quot;Unknown field name: {0}&quot;
+                    .format(expression.fieldName)
+                )
+            value = expression.fieldValue
</ins><span class="cx"> 
</span><del>-    #         value = unicode(value)
</del><ins>+        value = unicode(value)
</ins><span class="cx"> 
</span><del>-    #         # FIXME: Shouldn't the value be quoted somehow?
-    #         queryString = {
-    #             ODMatchType.equals.value: u&quot;({attr}={value})&quot;,
-    #             ODMatchType.startsWith.value: u&quot;({attr}={value}*)&quot;,
-    #             ODMatchType.endsWith.value: u&quot;({attr}=*{value})&quot;,
-    #             ODMatchType.contains.value: u&quot;({attr}=*{value}*)&quot;,
-    #             ODMatchType.lessThan.value: u&quot;({attr}&lt;{value})&quot;,
-    #             ODMatchType.greaterThan.value: u&quot;({attr}&gt;{value})&quot;,
-    #         }.get(matchType.value, u&quot;({attr}=*{value}*)&quot;).format(
-    #             attr=odAttr,
-    #             value=value
-    #         )
</del><ins>+        # FIXME: Shouldn't the value be quoted somehow?
+        return matchType.queryString.format(
+            attribute=odAttr.value, value=value
+        )
</ins><span class="cx"> 
</span><del>-    #     elif isinstance(expression, CompoundExpression):
-    #         queryString = u&quot;&quot;
-    #         operand = u&quot;&amp;&quot; if expression.operand is Operand.AND else u&quot;|&quot;
</del><span class="cx"> 
</span><del>-    #         if len(expression.expressions) &gt; 1:
-    #             queryString += u&quot;(&quot;
-    #             queryString += operand
</del><ins>+    def _queryStringFromCompoundExpression(self, expression):
+        &quot;&quot;&quot;
+        Generates an LDAP query string from a compound expression.
</ins><span class="cx"> 
</span><del>-    #         for subExpression in expression.expressions:
-    #             queryString += self._queryStringFromExpression(subExpression)
</del><ins>+        @param expression: A match expression.
+        @type expression: L{MatchExpression}
</ins><span class="cx"> 
</span><del>-    #         if len(expression.expressions) &gt; 1:
-    #             queryString += u&quot;)&quot;
</del><ins>+        @return: An LDAP query string.
+        @rtype: C{unicode}
+        &quot;&quot;&quot;
+        queryTokens = []
</ins><span class="cx"> 
</span><del>-    #     return queryString
</del><ins>+        if len(expression.expressions) &gt; 1:
+            queryTokens.append(u&quot;(&quot;)
</ins><span class="cx"> 
</span><ins>+            if expression.operand is Operand.AND:
+                queryTokens.append(u&quot;&amp;&quot;)
+            else:
+                queryTokens.append(u&quot;|&quot;)
</ins><span class="cx"> 
</span><ins>+        for subExpression in expression.expressions:
+            queryTokens.append(
+                self._queryStringFromExpression(subExpression)
+            )
+
+        if len(expression.expressions) &gt; 1:
+            queryTokens.append(u&quot;)&quot;)
+
+        return u&quot;&quot;.join(queryTokens)
+
+
+    def _queryStringFromExpression(self, expression):
+        &quot;&quot;&quot;
+        Converts either a MatchExpression or a CompoundExpression into an LDAP
+        query string.
+
+        @param expression: An expression.
+        @type expression: L{MatchExpression} or L{CompoundExpression}
+
+        @return: A native OpenDirectory query string
+        @rtype: C{unicode}
+        &quot;&quot;&quot;
+
+        if isinstance(expression, MatchExpression):
+            return self._queryStringFromMatchExpression(expression)
+
+        if isinstance(expression, CompoundExpression):
+            return self._queryStringFromCompoundExpression(expression)
+
+        raise QueryNotSupportedError(
+            &quot;Unknown expression type: {0!r}&quot;.format(expression)
+        )
+
+
</ins><span class="cx">     # def _queryFromCompoundExpression(self, expression):
</span><span class="cx">     #     &quot;&quot;&quot;
</span><span class="cx">     #     Form an OpenDirectory query from a compound expression.
</span></span></pre></div>
<a id="twexttrunktwextwhoopendirectorytesttest_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/opendirectory/test/test_service.py (12249 => 12250)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/opendirectory/test/test_service.py        2014-01-07 02:10:02 UTC (rev 12249)
+++ twext/trunk/twext/who/opendirectory/test/test_service.py        2014-01-07 02:15:58 UTC (rev 12250)
</span><span class="lines">@@ -20,10 +20,11 @@
</span><span class="cx"> 
</span><span class="cx"> from twisted.trial import unittest
</span><span class="cx"> 
</span><del>-# from ...expression import (
-#     CompoundExpression, MatchExpression, MatchType, Operand
-# )
-# from .._service import DirectoryService
</del><ins>+from ...expression import (
+    CompoundExpression, Operand, MatchExpression, MatchType, MatchFlags
+)
+from .._constants import ODAttribute
+from .._service import DirectoryService
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -32,89 +33,149 @@
</span><span class="cx">     Tests for L{DirectoryService}.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    # def test_queryStringFromExpression(self):
-    #     service = DirectoryService()
</del><ins>+    def test_queryStringFromMatchExpression_matchTypes(self):
+        &quot;&quot;&quot;
+        Match expressions with each match type produces the correct
+        operator=value string.
+        &quot;&quot;&quot;
</ins><span class="cx"> 
</span><del>-    #     # MatchExpressions
</del><ins>+        service = DirectoryService()
</ins><span class="cx"> 
</span><del>-    #     for matchType, expected in (
-    #         (MatchType.equals, u&quot;=xyzzy&quot;),
-    #         (MatchType.startsWith, u&quot;=xyzzy*&quot;),
-    #         (MatchType.endsWith, u&quot;=*xyzzy&quot;),
-    #         (MatchType.contains, u&quot;=*xyzzy*&quot;),
-    #     ):
-    #         expression = MatchExpression(
-    #             service.fieldName.shortNames, u&quot;xyzzy&quot;,
-    #             matchType=matchType
-    #         )
-    #         queryString = service._queryStringFromExpression(expression)
-    #         self.assertEquals(
-    #             queryString,
-    #             u&quot;(dsAttrTypeStandard:RecordName{exp})&quot;.format(exp=expected)
-    #         )
</del><ins>+        for matchType, expected in (
+            (MatchType.equals, u&quot;=xyzzy&quot;),
+            (MatchType.startsWith, u&quot;=xyzzy*&quot;),
+            (MatchType.endsWith, u&quot;=*xyzzy&quot;),
+            (MatchType.contains, u&quot;=*xyzzy*&quot;),
+            (MatchType.lessThan, u&quot;&lt;xyzzy&quot;),
+            (MatchType.greaterThan, u&quot;&gt;xyzzy&quot;),
+            (MatchType.lessThanOrEqualTo, u&quot;&lt;=xyzzy&quot;),
+            (MatchType.greaterThanOrEqualTo, u&quot;&gt;=xyzzy&quot;),
+        ):
+            expression = MatchExpression(
+                service.fieldName.shortNames, u&quot;xyzzy&quot;,
+                matchType=matchType
+            )
+            queryString = service._queryStringFromExpression(expression)
+            self.assertEquals(
+                queryString,
+                u&quot;({attribute}{expected})&quot;.format(
+                    attribute=ODAttribute.shortName.value, expected=expected
+                )
+            )
</ins><span class="cx"> 
</span><del>-    #     # CompoundExpressions
</del><span class="cx"> 
</span><del>-    #     expression = CompoundExpression(
-    #         [
-    #             MatchExpression(
-    #                 service.fieldName.uid, u&quot;a&quot;,
-    #                 matchType=MatchType.contains
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.guid, u&quot;b&quot;,
-    #                 matchType=MatchType.contains
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.shortNames, u&quot;c&quot;,
-    #                 matchType=MatchType.contains
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.emailAddresses, u&quot;d&quot;,
-    #                 matchType=MatchType.startsWith
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.fullNames, u&quot;e&quot;,
-    #                 matchType=MatchType.equals
-    #             ),
-    #         ],
-    #         Operand.AND
-    #     )
-    #     queryString = service._queryStringFromExpression(expression)
-    #     self.assertEquals(
-    #         queryString,
-    #         (
-    #             u&quot;(&amp;(dsAttrTypeStandard:GeneratedUID=*a*)&quot;
-    #             u&quot;(dsAttrTypeStandard:GeneratedUID=*b*)&quot;
-    #             u&quot;(dsAttrTypeStandard:RecordName=*c*)&quot;
-    #             u&quot;(dsAttrTypeStandard:EMailAddress=d*)&quot;
-    #             u&quot;(dsAttrTypeStandard:RealName=e))&quot;
-    #         )
-    #     )
</del><ins>+    def test_queryStringFromMatchExpression_match_not(self):
+        &quot;&quot;&quot;
+        Match expression with the C{NOT} flag adds the C{!} operator.
+        &quot;&quot;&quot;
</ins><span class="cx"> 
</span><del>-    #     expression = CompoundExpression(
-    #         [
-    #             MatchExpression(
-    #                 service.fieldName.shortNames, u&quot;a&quot;,
-    #                 matchType=MatchType.contains
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.emailAddresses, u&quot;b&quot;,
-    #                 matchType=MatchType.startsWith
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.fullNames, u&quot;c&quot;,
-    #                 matchType=MatchType.equals
-    #             ),
-    #         ],
-    #         Operand.OR
-    #     )
-    #     queryString = service._queryStringFromExpression(expression)
-    #     self.assertEquals(
-    #         queryString,
-    #         (
-    #             u&quot;(|(dsAttrTypeStandard:RecordName=*a*)&quot;
-    #             u&quot;(dsAttrTypeStandard:EMailAddress=b*)&quot;
-    #             u&quot;(dsAttrTypeStandard:RealName=c))&quot;
-    #         )
-    #     )
</del><ins>+        service = DirectoryService()
+
+        expression = MatchExpression(
+            service.fieldName.shortNames, u&quot;xyzzy&quot;,
+            flags=MatchFlags.NOT
+        )
+        queryString = service._queryStringFromExpression(expression)
+        self.assertEquals(
+            queryString,
+            u&quot;(!{attribute}=xyzzy)&quot;.format(
+                attribute=ODAttribute.shortName.value,
+            )
+        )
+
+    test_queryStringFromMatchExpression_match_not.todo = &quot;unimplemented&quot;
+
+
+    def test_queryStringFromMatchExpression_match_caseInsensitive(self):
+        &quot;&quot;&quot;
+        Match expression with the C{caseInsensitive} flag adds the C{??????}
+        operator.
+        &quot;&quot;&quot;
+
+        service = DirectoryService()
+
+        expression = MatchExpression(
+            service.fieldName.shortNames, u&quot;xyzzy&quot;,
+            flags=MatchFlags.caseInsensitive
+        )
+        queryString = service._queryStringFromExpression(expression)
+        self.assertEquals(
+            queryString,
+            u&quot;???????({attribute}=xyzzy)&quot;.format(
+                attribute=ODAttribute.shortName.value,
+            )
+        )
+
+    test_queryStringFromMatchExpression_match_caseInsensitive.todo = (
+        &quot;unimplemented&quot;
+    )
+
+
+    def test_queryStringFromExpression(self):
+        service = DirectoryService()
+
+        # CompoundExpressions
+
+        expression = CompoundExpression(
+            [
+                MatchExpression(
+                    service.fieldName.uid, u&quot;a&quot;,
+                    matchType=MatchType.contains
+                ),
+                MatchExpression(
+                    service.fieldName.guid, u&quot;b&quot;,
+                    matchType=MatchType.contains
+                ),
+                MatchExpression(
+                    service.fieldName.shortNames, u&quot;c&quot;,
+                    matchType=MatchType.contains
+                ),
+                MatchExpression(
+                    service.fieldName.emailAddresses, u&quot;d&quot;,
+                    matchType=MatchType.startsWith
+                ),
+                MatchExpression(
+                    service.fieldName.fullNames, u&quot;e&quot;,
+                    matchType=MatchType.equals
+                ),
+            ],
+            Operand.AND
+        )
+        queryString = service._queryStringFromExpression(expression)
+        self.assertEquals(
+            queryString,
+            (
+                u&quot;(&amp;(dsAttrTypeStandard:GeneratedUID=*a*)&quot;
+                u&quot;(dsAttrTypeStandard:GeneratedUID=*b*)&quot;
+                u&quot;(dsAttrTypeStandard:RecordName=*c*)&quot;
+                u&quot;(dsAttrTypeStandard:EMailAddress=d*)&quot;
+                u&quot;(dsAttrTypeStandard:RealName=e))&quot;
+            )
+        )
+
+        expression = CompoundExpression(
+            [
+                MatchExpression(
+                    service.fieldName.shortNames, u&quot;a&quot;,
+                    matchType=MatchType.contains
+                ),
+                MatchExpression(
+                    service.fieldName.emailAddresses, u&quot;b&quot;,
+                    matchType=MatchType.startsWith
+                ),
+                MatchExpression(
+                    service.fieldName.fullNames, u&quot;c&quot;,
+                    matchType=MatchType.equals
+                ),
+            ],
+            Operand.OR
+        )
+        queryString = service._queryStringFromExpression(expression)
+        self.assertEquals(
+            queryString,
+            (
+                u&quot;(|(dsAttrTypeStandard:RecordName=*a*)&quot;
+                u&quot;(dsAttrTypeStandard:EMailAddress=b*)&quot;
+                u&quot;(dsAttrTypeStandard:RealName=c))&quot;
+            )
+        )
</ins></span></pre>
</div>
</div>

</body>
</html>