Ejemplo n.º 1
0
    def test_cancel(self):
        ldap = mock.Mock()
        ldap.abandon.return_value = True

        future = Future(ldap, 0)
        self.assertEqual(True, future.cancel())
        ldap.abandon.assert_called_one_with(0)
Ejemplo n.º 2
0
    def test_result_timeout_zero(self):
        ldap = mock.Mock()
        ldap.result.return_value = 0

        future = Future(ldap, 0)
        self.assertEqual(0, future.result(0))
        ldap.result.assert_called_one_with(0, 1, 0)
Ejemplo n.º 3
0
    def test_exception(self):
        excp = ValueError('test')
        ldap = mock.Mock()
        ldap.result.side_effect = excp

        future = Future(ldap, 0)
        self.assertEqual(excp, future.exception())
Ejemplo n.º 4
0
    def test_result_timeout_zero(self):
        ldap = mock.Mock()
        ldap.result.return_value = 0

        future = Future(ldap, 0)
        self.assertEqual(0, future.result(0))
        ldap.result.assert_called_one_with(0, 1, 0)
Ejemplo n.º 5
0
    def test_cancel(self):
        ldap = mock.Mock()
        ldap.abandon.return_value = True

        future = Future(ldap, 0)
        self.assertEqual(True, future.cancel())
        ldap.abandon.assert_called_one_with(0)
Ejemplo n.º 6
0
    def test_exception(self):
        excp = ValueError('test')
        ldap = mock.Mock()
        ldap.result.side_effect = excp

        future = Future(ldap, 0)
        self.assertEqual(excp, future.exception())
Ejemplo n.º 7
0
    def test_cancelled(self):
        ldap = mock.Mock()
        ldap.abandon.return_value = True

        future = Future(ldap, 0)
        self.assertEqual(False, future.cancelled())
        self.assertEqual(True, future.cancel())
        self.assertEqual(True, future.cancelled())
Ejemplo n.º 8
0
    def test_cancelled(self):
        ldap = mock.Mock()
        ldap.abandon.return_value = True

        future = Future(ldap, 0)
        self.assertEqual(False, future.cancelled())
        self.assertEqual(True, future.cancel())
        self.assertEqual(True, future.cancelled())
Ejemplo n.º 9
0
    def test_done(self):
        ldap = mock.Mock()
        ldap.result.side_effect = [None, None, 0]

        future = Future(ldap, 0)
        self.assertEqual(False, future.done())
        self.assertEqual(False, future.done())
        self.assertEqual(True, future.done())
        self.assertEqual(True, future.done())
        ldap.result.call_count = 3
Ejemplo n.º 10
0
    def test_done(self):
        ldap = mock.Mock()
        ldap.result.side_effect = [None, None, 0]

        future = Future(ldap, 0)
        self.assertEqual(False, future.done())
        self.assertEqual(False, future.done())
        self.assertEqual(True, future.done())
        self.assertEqual(True, future.done())
        ldap.result.call_count = 3
Ejemplo n.º 11
0
    def simple_bind(self, dn, passwd):
        """Initiate an asynchronous request to authenticate with the server
        using a plaintext password.

        Returns a Future object, and raises LdapError on error.
        """
        return Future(self, dll.ldap_simple_bind(self._l, dn, passwd))
Ejemplo n.º 12
0
    def test_result_exception(self):
        excp = ValueError('test')
        ldap = mock.Mock()
        ldap.result.side_effect = excp

        future = Future(ldap, 0)
        self.assertRaises(ValueError, future.result, 0)
Ejemplo n.º 13
0
    def delete(self, dn):
        """Initiate a asynchronous delete operation from the directory tree.

        Args:
            dn: distinguished name for the entry to delete

        Returns a Future object, and raises LdapError on error.
        """
        return Future(self, dll.ldap_delete(self._l, dn))
Ejemplo n.º 14
0
    def modify(self, dn, changeset):
        """Initiate an asynchronous modify operation to the directory tree.

        Args:
            dn: distinguished name for the entry to delete
            changeset: a wldap.Changeset containing the requested modifications

        Returns a Future object, and raises LdapError on error.
        """
        return Future(self,
                      dll.ldap_modify(self._l, dn, changeset.to_api_param()))
Ejemplo n.º 15
0
    def add(self, dn, *args):
        """Initiate an asynchronous add operation to a directory tree.

        Args:
            dn: distinguished name for the entry to add
            *args: (attribute, values) pairs, where value is a sequence

        Returns a Future object, and raises LdapError on error.
        """
        changeset = Changeset()
        [changeset.add(attr, values) for attr, values in args]
        return Future(self, dll.ldap_add(self._l, dn,
                                         changeset.to_api_param()))
Ejemplo n.º 16
0
    def search(self, base, scope, filt, attr, attronly):
        """Initiate an asynchronous search operation.

        Args:
            base: distinguished name of the entry at which to start the search
            scope: LDAP_SCOPE_BASE, LDAP_SCOPE_ONELEVEL or LDAP_SCOPE_SUBTREE
            filt: the search filter
            attr: a list of attribute names to be returned
            attronly: True if both attribute types and values are to be
                returned, False if only types are required

        Returns a Future object, and raises LdapError on error.
        """
        # Convert attribute list to a C, nul-terminated string array.
        attr = self._make_attrs(attr)
        return Future(
            self, dll.ldap_search(self._l, base, scope, filt, attr, attronly))
Ejemplo n.º 17
0
    def bind(self, dn, cred, method):
        """Initiate an asynchronous operation to authenticate the client to the
        LDAP server.

        Args:
            dn: distinguished name of the entry used to bind
            cred: credentials with which to authenticate
            method: authenticatation method to use

        LDAP_AUTH_SIMPLE is the only acceptable method for the asynchronous
        version of bind(), and credentials are sent in plaintext. In the end,
        you're better off using bind_s.

        Returns a Future object, and raises LdapError on error.

        See http://msdn.microsoft.com/en-us/library/windows/desktop/aa366153(v=
        vs.85).aspx for details.
        """
        return Future(self, dll.ldap_bind(self._l, dn, cred, method))
Ejemplo n.º 18
0
 def test_running(self):
     self.assertEqual(False, Future(mock.Mock(), 0).running())
Ejemplo n.º 19
0
    def test_result_timeout(self):
        ldap = mock.Mock()
        ldap.result.return_value = None

        future = Future(ldap, 0)
        self.assertRaises(TimeoutError, future.result, 0)