[CalendarServer-changes] [14085] twext/trunk/twext/who/ldap/test/test_service.py

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 17 10:22:48 PDT 2014


Revision: 14085
          http://trac.calendarserver.org//changeset/14085
Author:   sagen at apple.com
Date:     2014-10-17 10:22:48 -0700 (Fri, 17 Oct 2014)
Log Message:
-----------
Allow mockldap to work with ldap.async

Modified Paths:
--------------
    twext/trunk/twext/who/ldap/test/test_service.py

Modified: twext/trunk/twext/who/ldap/test/test_service.py
===================================================================
--- twext/trunk/twext/who/ldap/test/test_service.py	2014-10-16 16:12:30 UTC (rev 14084)
+++ twext/trunk/twext/who/ldap/test/test_service.py	2014-10-17 17:22:48 UTC (rev 14085)
@@ -25,20 +25,34 @@
 import ldap
 
 
-# FIXME:
-MOCKLDAP_SUPPORTS_LDAP_ASYNC = False
+try:
+    from mockldap import MockLdap
+    from mockldap.filter import (
+        Test as MockLDAPFilterTest,
+        UnsupportedOp as MockLDAPUnsupportedOp,
+    )
+    from mockldap.ldapobject import LDAPObject
 
+    # Allow ldap.async to work with mockldap:
 
-if MOCKLDAP_SUPPORTS_LDAP_ASYNC:
-    try:
-        from mockldap import MockLdap
-        from mockldap.filter import (
-            Test as MockLDAPFilterTest,
-            UnsupportedOp as MockLDAPUnsupportedOp,
-        )
-    except ImportError:
-        MockLdap = None
-else:
+    def search_ext(
+        self, base, scope, filterstr='(objectClass=*)',
+        attrlist=None, attrsonly=0, serverctrls=None, clientctrls=None,
+        timeout=-1, sizelimit=0
+    ):
+        value = self._search_s(base, scope, filterstr, attrlist, attrsonly)
+        if sizelimit:
+            value = value[:sizelimit]
+        return self._add_async_result(value)
+
+
+    def result3(self, msgid, all=1, timeout=None):
+        return ldap.RES_SEARCH_RESULT, self._pop_async_result(msgid), None, None
+
+    LDAPObject.search_ext = search_ext
+    LDAPObject.result3 = result3
+
+except ImportError:
     MockLdap = None
 
 from twext.python.types import MappingProxyType
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141017/35a754ed/attachment.html>


More information about the calendarserver-changes mailing list