<!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>[13867] 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/13867">13867</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-08-12 12:57:18 -0700 (Tue, 12 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Adds ExistsExpression (true if an attribute has a value) and BooleanExpression (true if the associated directory attribute has a specific value)</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#twexttrunktwextwhoexpressionpy">twext/trunk/twext/who/expression.py</a></li>
<li><a href="#twexttrunktwextwholdap_servicepy">twext/trunk/twext/who/ldap/_service.py</a></li>
<li><a href="#twexttrunktwextwholdap_utilpy">twext/trunk/twext/who/ldap/_util.py</a></li>
<li><a href="#twexttrunktwextwholdaptesttest_servicepy">twext/trunk/twext/who/ldap/test/test_service.py</a></li>
<li><a href="#twexttrunktwextwholdaptesttest_utilpy">twext/trunk/twext/who/ldap/test/test_util.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="twexttrunktwextwhoexpressionpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/expression.py (13866 => 13867)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/expression.py        2014-08-11 21:31:01 UTC (rev 13866)
+++ twext/trunk/twext/who/expression.py        2014-08-12 19:57:18 UTC (rev 13867)
</span><span class="lines">@@ -21,8 +21,9 @@
</span><span class="cx"> 
</span><span class="cx"> __all__ = [
</span><span class="cx">     &quot;Operand&quot;,
</span><ins>+    &quot;BooleanExpression&quot;,
</ins><span class="cx">     &quot;CompoundExpression&quot;,
</span><del>-
</del><ins>+    &quot;ExistsExpression&quot;,
</ins><span class="cx">     &quot;MatchType&quot;,
</span><span class="cx">     &quot;MatchFlags&quot;,
</span><span class="cx">     &quot;MatchExpression&quot;,
</span><span class="lines">@@ -334,3 +335,71 @@
</span><span class="cx">         return predicate(match(
</span><span class="cx">             normalize(value), normalize(self.fieldValue)
</span><span class="cx">         ))
</span><ins>+
+
+class ExistsExpression(object):
+    &quot;&quot;&quot;
+    Query for the existence a given field.
+
+    @ivar fieldName: A L{NamedConstant} specifying the field.
+    &quot;&quot;&quot;
+
+    def __init__(self, fieldName):
+        if not isinstance(fieldName, NamedConstant):
+            raise TypeError(
+                &quot;Field name {name} in exists expression is not a NamedConstant.&quot;
+                .format(name=fieldName)
+            )
+
+        self.fieldName = fieldName
+
+
+    def __repr__(self):
+        return (
+            &quot;&lt;{self.__class__.__name__}: {fieldName!r} &quot;
+            .format(
+                self=self,
+                fieldName=describe(self.fieldName),
+            )
+        )
+
+
+    def __eq__(self, other):
+        if isinstance(other, ExistsExpression):
+            return (self.fieldName is other.fieldName)
+        else:
+            return NotImplemented
+
+
+class BooleanExpression(object):
+    &quot;&quot;&quot;
+    Query for the &quot;True&quot; value of a given field.
+
+    @ivar fieldName: A L{NamedConstant} specifying the field.
+    &quot;&quot;&quot;
+
+    def __init__(self, fieldName):
+        if not isinstance(fieldName, NamedConstant):
+            raise TypeError(
+                &quot;Field name {name} in boolean expression is not a NamedConstant.&quot;
+                .format(name=fieldName)
+            )
+
+        self.fieldName = fieldName
+
+
+    def __repr__(self):
+        return (
+            &quot;&lt;{self.__class__.__name__}: {fieldName!r} &quot;
+            .format(
+                self=self,
+                fieldName=describe(self.fieldName),
+            )
+        )
+
+
+    def __eq__(self, other):
+        if isinstance(other, BooleanExpression):
+            return (self.fieldName is other.fieldName)
+        else:
+            return NotImplemented
</ins></span></pre></div>
<a id="twexttrunktwextwholdap_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/ldap/_service.py (13866 => 13867)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/ldap/_service.py        2014-08-11 21:31:01 UTC (rev 13866)
+++ twext/trunk/twext/who/ldap/_service.py        2014-08-12 19:57:18 UTC (rev 13867)
</span><span class="lines">@@ -47,12 +47,14 @@
</span><span class="cx">     DirectoryService as BaseDirectoryService,
</span><span class="cx">     DirectoryRecord as BaseDirectoryRecord,
</span><span class="cx"> )
</span><del>-from ..expression import MatchExpression
</del><ins>+from ..expression import MatchExpression, ExistsExpression, BooleanExpression
</ins><span class="cx"> from ..util import ConstantsContainer
</span><span class="cx"> from ._constants import LDAPAttribute, LDAPObjectClass
</span><span class="cx"> from ._util import (
</span><span class="cx">     ldapQueryStringFromMatchExpression,
</span><span class="cx">     ldapQueryStringFromCompoundExpression,
</span><ins>+    ldapQueryStringFromBooleanExpression,
+    ldapQueryStringFromExistsExpression,
</ins><span class="cx"> )
</span><span class="cx"> from zope.interface import implementer
</span><span class="cx"> 
</span><span class="lines">@@ -573,7 +575,12 @@
</span><span class="cx">                 recordTypes = self.recordTypes()
</span><span class="cx"> 
</span><span class="cx">             for recordType in recordTypes:
</span><del>-                rdn = self._recordTypeSchemas[recordType].relativeDN
</del><ins>+                try:
+                    rdn = self._recordTypeSchemas[recordType].relativeDN
+                except KeyError:
+                    # Skip this unknown record type
+                    continue
+
</ins><span class="cx">                 rdn = (
</span><span class="cx">                     ldap.dn.str2dn(rdn.lower()) +
</span><span class="cx">                     ldap.dn.str2dn(self._baseDN.lower())
</span><span class="lines">@@ -600,7 +607,7 @@
</span><span class="cx">                     raise LDAPQueryError(&quot;Unable to perform query&quot;, e)
</span><span class="cx"> 
</span><span class="cx">                 except ldap.NO_SUCH_OBJECT as e:
</span><del>-                    self.log.warn(&quot;RDN {rdn} does not exist, skipping&quot;, rdn=rdn)
</del><ins>+                    # self.log.warn(&quot;RDN {rdn} does not exist, skipping&quot;, rdn=rdn)
</ins><span class="cx">                     continue
</span><span class="cx"> 
</span><span class="cx">                 records.extend(
</span><span class="lines">@@ -628,13 +635,19 @@
</span><span class="cx"> 
</span><span class="cx">             self.log.debug(&quot;Performing LDAP DN query: {dn}&quot;, dn=dn)
</span><span class="cx"> 
</span><del>-            reply = connection.search_s(
-                dn,
-                ldap.SCOPE_SUBTREE,
-                &quot;(objectClass=*)&quot;,
-                attrlist=self._attributesToFetch
-            )
-            records = self._recordsFromReply(reply)
</del><ins>+            try:
+                reply = connection.search_s(
+                    dn,
+                    ldap.SCOPE_SUBTREE,
+                    &quot;(objectClass=*)&quot;,
+                    attrlist=self._attributesToFetch
+                )
+                records = self._recordsFromReply(reply)
+            except ldap.NO_SUCH_OBJECT:
+                records = []
+            except ldap.INVALID_DN_SYNTAX:
+                self.log.warn(&quot;Invalid LDAP DN syntax: '{dn}'&quot;, dn=dn)
+                records = []
</ins><span class="cx"> 
</span><span class="cx">         if len(records):
</span><span class="cx">             return records[0]
</span><span class="lines">@@ -705,6 +718,21 @@
</span><span class="cx">                         else:
</span><span class="cx">                             fields[fieldName] = newValues[0]
</span><span class="cx"> 
</span><ins>+                    elif valueType is bool:
+                        if not isinstance(values, list):
+                            values = [values]
+                        if &quot;=&quot; in attribute:
+                            attribute, trueValue = attribute.split(&quot;=&quot;)
+                        else:
+                            trueValue = &quot;true&quot;
+
+                        for value in values:
+                            if value == trueValue:
+                                fields[fieldName] = True
+                                break
+                        else:
+                            fields[fieldName] = False
+
</ins><span class="cx">                     else:
</span><span class="cx">                         raise LDAPConfigurationError(
</span><span class="cx">                             &quot;Unknown value type {0} for field {1}&quot;.format(
</span><span class="lines">@@ -741,6 +769,24 @@
</span><span class="cx">                 queryString, recordTypes=recordTypes
</span><span class="cx">             )
</span><span class="cx"> 
</span><ins>+        elif isinstance(expression, ExistsExpression):
+            queryString = ldapQueryStringFromExistsExpression(
+                expression,
+                self._fieldNameToAttributesMap, self._recordTypeSchemas
+            )
+            return self._recordsFromQueryString(
+                queryString, recordTypes=recordTypes
+            )
+
+        elif isinstance(expression, BooleanExpression):
+            queryString = ldapQueryStringFromBooleanExpression(
+                expression,
+                self._fieldNameToAttributesMap, self._recordTypeSchemas
+            )
+            return self._recordsFromQueryString(
+                queryString, recordTypes=recordTypes
+            )
+
</ins><span class="cx">         return BaseDirectoryService.recordsFromNonCompoundExpression(
</span><span class="cx">             self, expression, records=records
</span><span class="cx">         )
</span><span class="lines">@@ -762,9 +808,13 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def recordsWithRecordType(self, recordType):
</span><del>-        return self.recordsWithFieldValue(
-            BaseFieldName.uid, u&quot;*&quot;, recordTypes=[recordType]
</del><ins>+        queryString = ldapQueryStringFromExistsExpression(
+            ExistsExpression(self.fieldName.uid),
+            self._fieldNameToAttributesMap, self._recordTypeSchemas
</ins><span class="cx">         )
</span><ins>+        return self._recordsFromQueryString(
+            queryString, recordTypes=[recordType]
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     # def updateRecords(self, records, create=False):
</span><span class="lines">@@ -813,7 +863,16 @@
</span><span class="cx">         return self.service._authenticateUsernamePassword(self.dn, password)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+def normalizeDNstr(dnStr):
+    &quot;&quot;&quot;
+    Convert to lowercase and remove extra whitespace
+    @param dnStr: dn
+    @type dnStr: C{str}
+    @return: normalized dn C{str}
+    &quot;&quot;&quot;
+    return ' '.join(ldap.dn.dn2str(ldap.dn.str2dn(dnStr.lower())).split())
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> def reverseDict(source):
</span><span class="cx">     new = {}
</span><span class="cx"> 
</span></span></pre></div>
<a id="twexttrunktwextwholdap_utilpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/ldap/_util.py (13866 => 13867)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/ldap/_util.py        2014-08-11 21:31:01 UTC (rev 13866)
+++ twext/trunk/twext/who/ldap/_util.py        2014-08-12 19:57:18 UTC (rev 13867)
</span><span class="lines">@@ -17,8 +17,8 @@
</span><span class="cx"> 
</span><span class="cx"> from ..idirectory import QueryNotSupportedError, FieldName
</span><span class="cx"> from ..expression import (
</span><del>-    CompoundExpression, Operand,
-    MatchExpression, MatchFlags,
</del><ins>+    CompoundExpression, ExistsExpression, MatchExpression,
+    MatchFlags, Operand, BooleanExpression
</ins><span class="cx"> )
</span><span class="cx"> from ._constants import LDAPOperand, LDAPMatchType, LDAPMatchFlags
</span><span class="cx"> 
</span><span class="lines">@@ -154,7 +154,102 @@
</span><span class="cx">     raise AssertionError(&quot;We shouldn't be here.&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+def ldapQueryStringFromExistsExpression(
+    expression, fieldNameToAttributesMap, recordTypeSchemas
+):
+    &quot;&quot;&quot;
+    Generates an LDAP query string from an exists expression.
</ins><span class="cx"> 
</span><ins>+    @param expression: An exists expression.
+    @type expression: L{ExistsExpression}
+
+    @param fieldNameToAttributesMap: A mapping from field names to native LDAP
+        attribute names.
+    @type fieldNameToAttributesMap: L{dict} with L{FieldName} keys and sequence
+        of L{unicode} values.
+
+    @param recordTypeSchemas: Schema information for record types.
+    @type recordTypeSchemas: mapping from L{NamedConstant} to
+        L{RecordTypeSchema}
+
+    @return: An LDAP query string.
+    @rtype: L{unicode}
+
+    @raises QueryNotSupportedError: if the expresion references an unknown
+        field name (meaning a field name not in C{fieldNameToAttributeMap}).
+    &quot;&quot;&quot;
+
+    fieldName = expression.fieldName
+
+    try:
+        attributes = fieldNameToAttributesMap[fieldName]
+    except KeyError:
+        raise QueryNotSupportedError(
+            &quot;Unmapped field name: {0}&quot;.format(expression.fieldName)
+        )
+
+    queryStrings = [
+        u&quot;({attribute}=*)&quot;.format(attribute=attribute)
+        for attribute in attributes
+    ]
+
+    operand = LDAPOperand.OR.value
+    return ldapQueryStringFromQueryStrings(operand, queryStrings)
+
+
+def ldapQueryStringFromBooleanExpression(
+    expression, fieldNameToAttributesMap, recordTypeSchemas
+):
+    &quot;&quot;&quot;
+    Generates an LDAP query string from a boolean expression.
+
+    @param expression: An boolean expression.
+    @type expression: L{BooleanExpression}
+
+    @param fieldNameToAttributesMap: A mapping from field names to native LDAP
+        attribute names.
+    @type fieldNameToAttributesMap: L{dict} with L{FieldName} keys and sequence
+        of L{unicode} values.
+
+    @param recordTypeSchemas: Schema information for record types.
+    @type recordTypeSchemas: mapping from L{NamedConstant} to
+        L{RecordTypeSchema}
+
+    @return: An LDAP query string.
+    @rtype: L{unicode}
+
+    @raises QueryNotSupportedError: if the expresion references an unknown
+        field name (meaning a field name not in C{fieldNameToAttributeMap}).
+    &quot;&quot;&quot;
+
+    fieldName = expression.fieldName
+
+    try:
+        attributes = fieldNameToAttributesMap[fieldName]
+    except KeyError:
+        raise QueryNotSupportedError(
+            &quot;Unmapped field name: {0}&quot;.format(expression.fieldName)
+        )
+
+    queryStrings = []
+    for attribute in attributes:
+        if &quot;=&quot; in attribute:
+            attribute, trueValue = attribute.split(&quot;=&quot;)
+        else:
+            trueValue = &quot;true&quot;
+
+        queryStrings.append(
+            u&quot;({attribute}={trueValue})&quot;.format(
+                attribute=attribute,
+                trueValue=trueValue
+            )
+        )
+
+
+    operand = LDAPOperand.OR.value
+    return ldapQueryStringFromQueryStrings(operand, queryStrings)
+
+
</ins><span class="cx"> def ldapQueryStringFromCompoundExpression(
</span><span class="cx">     expression, fieldNameToAttributesMap, recordTypeSchemas
</span><span class="cx"> ):
</span><span class="lines">@@ -227,6 +322,16 @@
</span><span class="cx">             expression, fieldNameToAttributesMap, recordTypeSchemas
</span><span class="cx">         )
</span><span class="cx"> 
</span><ins>+    if isinstance(expression, BooleanExpression):
+        return ldapQueryStringFromBooleanExpression(
+            expression, fieldNameToAttributesMap, recordTypeSchemas
+        )
+
+    if isinstance(expression, ExistsExpression):
+        return ldapQueryStringFromExistsExpression(
+            expression, fieldNameToAttributesMap, recordTypeSchemas
+        )
+
</ins><span class="cx">     if isinstance(expression, CompoundExpression):
</span><span class="cx">         return ldapQueryStringFromCompoundExpression(
</span><span class="cx">             expression, fieldNameToAttributesMap, recordTypeSchemas
</span><span class="lines">@@ -243,8 +348,7 @@
</span><span class="cx"> 
</span><span class="cx">     ord(u&quot;(&quot;): u&quot;\\28&quot;,
</span><span class="cx">     ord(u&quot;)&quot;): u&quot;\\29&quot;,
</span><del>-    # Question: shouldn't we not be quoting * because that's how you specify wildcards?
-    # ord(u&quot;*&quot;): u&quot;\\2A&quot;,
</del><ins>+    ord(u&quot;*&quot;): u&quot;\\2A&quot;,
</ins><span class="cx"> 
</span><span class="cx">     ord(u&quot;&lt;&quot;): u&quot;\\3C&quot;,
</span><span class="cx">     ord(u&quot;=&quot;): u&quot;\\3D&quot;,
</span></span></pre></div>
<a id="twexttrunktwextwholdaptesttest_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/ldap/test/test_service.py (13866 => 13867)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/ldap/test/test_service.py        2014-08-11 21:31:01 UTC (rev 13866)
+++ twext/trunk/twext/who/ldap/test/test_service.py        2014-08-12 19:57:18 UTC (rev 13867)
</span><span class="lines">@@ -57,11 +57,10 @@
</span><span class="cx"> from ...test.test_xml import (
</span><span class="cx">     xmlService,
</span><span class="cx">     BaseTest as XMLBaseTest, QueryMixIn,
</span><del>-    DirectoryServiceConvenienceTestMixIn
-    as BaseDirectoryServiceConvenienceTestMixIn,
</del><ins>+    DirectoryServiceConvenienceTestMixIn,
</ins><span class="cx">     DirectoryServiceRealmTestMixIn,
</span><span class="cx">     DirectoryServiceQueryTestMixIn as BaseDirectoryServiceQueryTestMixIn,
</span><del>-    DirectoryServiceMutableTestMixIn as BaseDirectoryServiceMutableTestMixIn,
</del><ins>+    DirectoryServiceMutableTestMixIn as BaseDirectoryServiceMutableTestMixIn
</ins><span class="cx"> )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -153,21 +152,6 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class DirectoryServiceConvenienceTestMixIn(
-    BaseDirectoryServiceConvenienceTestMixIn
-):
-    def test_recordsWithRecordType_unknown(self):
-        pass
-        # service = self.service()
-
-        # self.assertRaises(
-        #     QueryNotSupportedError,
-        #     service.recordsWithRecordType, UnknownConstant.unknown
-        # )
-    test_recordsWithRecordType_unknown.todo = &quot;After this test runs, other tests fail, need to investigate&quot;
-
-
-
</del><span class="cx"> class DirectoryServiceQueryTestMixIn(BaseDirectoryServiceQueryTestMixIn):
</span><span class="cx">     def test_queryNot(self):
</span><span class="cx">         return BaseDirectoryServiceQueryTestMixIn.test_queryNot(self)
</span><span class="lines">@@ -268,6 +252,7 @@
</span><span class="cx">         self.assertFalse(connection.tls_enabled)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_connect_withUsernamePassword_invalid(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Connect with UsernamePassword credentials.
</span><span class="lines">@@ -277,7 +262,12 @@
</span><span class="cx">             u&quot;__password__&quot;
</span><span class="cx">         )
</span><span class="cx">         service = self.service(credentials=credentials)
</span><del>-        self.assertFailure(service._connect(), LDAPBindAuthError)
</del><ins>+        try:
+            yield service._connect()
+        except LDAPBindAuthError:
+            pass
+        else:
+            self.fail(&quot;Should have raised LDAPBindAuthError&quot;)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="twexttrunktwextwholdaptesttest_utilpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/ldap/test/test_util.py (13866 => 13867)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/ldap/test/test_util.py        2014-08-11 21:31:01 UTC (rev 13866)
+++ twext/trunk/twext/who/ldap/test/test_util.py        2014-08-12 19:57:18 UTC (rev 13867)
</span><span class="lines">@@ -22,7 +22,8 @@
</span><span class="cx"> 
</span><span class="cx"> from ...idirectory import QueryNotSupportedError
</span><span class="cx"> from ...expression import (
</span><del>-    CompoundExpression, Operand, MatchExpression, MatchType, MatchFlags
</del><ins>+    CompoundExpression, ExistsExpression, MatchExpression, BooleanExpression,
+    Operand, MatchType, MatchFlags
</ins><span class="cx"> )
</span><span class="cx"> from ...test.test_xml import UnknownConstant
</span><span class="cx"> from .._constants import LDAPOperand
</span><span class="lines">@@ -31,17 +32,29 @@
</span><span class="cx"> )
</span><span class="cx"> from .._util import (
</span><span class="cx">     ldapQueryStringFromQueryStrings,
</span><ins>+    ldapQueryStringFromBooleanExpression,
+    ldapQueryStringFromCompoundExpression,
+    ldapQueryStringFromExistsExpression,
</ins><span class="cx">     ldapQueryStringFromMatchExpression,
</span><del>-    ldapQueryStringFromCompoundExpression,
</del><span class="cx">     ldapQueryStringFromExpression,
</span><span class="cx"> )
</span><span class="cx"> from ...idirectory import FieldName as BaseFieldName
</span><ins>+from twisted.python.constants import Names, NamedConstant
</ins><span class="cx"> 
</span><del>-
</del><span class="cx"> TEST_FIELDNAME_MAP = dict(DEFAULT_FIELDNAME_ATTRIBUTE_MAP)
</span><span class="cx"> TEST_FIELDNAME_MAP[BaseFieldName.uid] = (u&quot;__who_uid__&quot;,)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class TestFieldName(Names):
+    isAwesome = NamedConstant()
+    isAwesome.description = u&quot;is awesome&quot;
+    isAwesome.valueType = bool
+
+    isCool = NamedConstant()
+    isCool.description = u&quot;is cool&quot;
+    isCool.valueType = bool
+
+
</ins><span class="cx"> class LDAPQueryTestCase(unittest.TestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for LDAP query generation.
</span><span class="lines">@@ -81,9 +94,7 @@
</span><span class="cx">                 c,
</span><span class="cx">                 RecordTypeSchema(
</span><span class="cx">                     relativeDN=NotImplemented,  # Don't expect this to be used
</span><del>-                    attributes=(
-                        (u&quot;recordTypeAttribute&quot;, c.name),
-                    )
</del><ins>+                    attributes=((u&quot;recordTypeAttribute&quot;, c.name),)
</ins><span class="cx">                 )
</span><span class="cx">             )
</span><span class="cx">             for c in service.recordType.iterconstants()
</span><span class="lines">@@ -122,6 +133,55 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def test_queryStringFromExistsExpression(self):
+        &quot;&quot;&quot;
+        Exists expressions produce the correct (attribute=*) string.
+        &quot;&quot;&quot;
+        service = self.service()
+
+        expression = ExistsExpression(service.fieldName.shortNames)
+        queryString = ldapQueryStringFromExistsExpression(
+            expression,
+            self.fieldNameMap(service),
+            self.recordTypeSchemas(service),
+        )
+        expected = u&quot;(shortNames=*)&quot;
+        self.assertEquals(queryString, expected)
+
+
+    def test_queryStringFromBooleanExpression(self):
+        &quot;&quot;&quot;
+        If a field is a boolean type and the fieldNameToAttributesMap
+        value for the field has an equals sign, the portion to the right
+        of the equals sign is the value that represents True.  Make sure
+        the query string we generate includes that value.
+        &quot;&quot;&quot;
+        service = self.service()
+
+        testFieldNameMap = {
+            TestFieldName.isAwesome: (&quot;awesome=totally&quot;,),
+            TestFieldName.isCool: (&quot;cool&quot;,),
+        }
+
+        expression = BooleanExpression(TestFieldName.isAwesome)
+        queryString = ldapQueryStringFromBooleanExpression(
+            expression,
+            testFieldNameMap,
+            self.recordTypeSchemas(service),
+        )
+        expected = u&quot;(awesome=totally)&quot;
+        self.assertEquals(queryString, expected)
+
+        expression = BooleanExpression(TestFieldName.isCool)
+        queryString = ldapQueryStringFromBooleanExpression(
+            expression,
+            testFieldNameMap,
+            self.recordTypeSchemas(service),
+        )
+        expected = u&quot;(cool=true)&quot;
+        self.assertEquals(queryString, expected)
+
+
</ins><span class="cx">     def test_queryStringFromMatchExpression_matchTypes(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Match expressions with each match type produces the correct
</span><span class="lines">@@ -216,7 +276,7 @@
</span><span class="cx">         expected = u&quot;({attribute}={expected})&quot;.format(
</span><span class="cx">             attribute=u&quot;fullNames&quot;,
</span><span class="cx">             expected=(
</span><del>-                u&quot;\\5Cxyzzy: a\\2Fb\\2F\\28c\\29* &quot;
</del><ins>+                u&quot;\\5Cxyzzy: a\\2Fb\\2F\\28c\\29\\2A &quot;
</ins><span class="cx">                 &quot;\\7E\\7E \\3E\\3D\\3C \\7E\\7E \\26\\7C \\00!!&quot;
</span><span class="cx">             )
</span><span class="cx">         )
</span></span></pre></div>
<a id="twexttrunktwextwhoopendirectorytesttest_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/opendirectory/test/test_service.py (13866 => 13867)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/opendirectory/test/test_service.py        2014-08-11 21:31:01 UTC (rev 13866)
+++ twext/trunk/twext/who/opendirectory/test/test_service.py        2014-08-12 19:57:18 UTC (rev 13867)
</span><span class="lines">@@ -185,7 +185,7 @@
</span><span class="cx">             u&quot;({attribute}={expected})&quot;.format(
</span><span class="cx">                 attribute=ODAttribute.fullName.value,
</span><span class="cx">                 expected=(
</span><del>-                    u&quot;\\5Cxyzzy: a\\2Fb\\2F\\28c\\29* &quot;
</del><ins>+                    u&quot;\\5Cxyzzy: a\\2Fb\\2F\\28c\\29\\2A &quot;
</ins><span class="cx">                     &quot;\\7E\\7E \\3E\\3D\\3C \\7E\\7E \\26\\7C \\00!!&quot;
</span><span class="cx">                 )
</span><span class="cx">             )
</span></span></pre>
</div>
</div>

</body>
</html>