| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2014.02.02 |
| 5 |
# |
| 6 |
# Author: Giovanni Cannata |
| 7 |
# |
| 8 |
# Copyright 2014 - 2020 Giovanni Cannata |
| 9 |
# |
| 10 |
# This file is part of ldap3. |
| 11 |
# |
| 12 |
# ldap3 is free software: you can redistribute it and/or modify |
| 13 |
# it under the terms of the GNU Lesser General Public License as published |
| 14 |
# by the Free Software Foundation, either version 3 of the License, or |
| 15 |
# (at your option) any later version. |
| 16 |
# |
| 17 |
# ldap3 is distributed in the hope that it will be useful, |
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
# GNU Lesser General Public License for more details. |
| 21 |
# |
| 22 |
# You should have received a copy of the GNU Lesser General Public License |
| 23 |
# along with ldap3 in the COPYING and COPYING.LESSER files. |
| 24 |
# If not, see <http://www.gnu.org/licenses/>. |
| 25 |
|
| 26 |
import unittest |
| 27 |
|
| 28 |
from test.config import get_connection, drop_connection |
| 29 |
|
| 30 |
|
| 31 |
class Test(unittest.TestCase): |
| 32 |
def setUp(self): |
| 33 |
self.connection = get_connection(bind=False) |
| 34 |
|
| 35 |
def tearDown(self): |
| 36 |
drop_connection(self.connection) |
| 37 |
self.assertFalse(self.connection.bound) |
| 38 |
|
| 39 |
def test_open_connection(self): |
| 40 |
self.connection.open() |
| 41 |
self.assertEqual(self.connection.closed, False) |
| 42 |
self.connection.unbind() |
| 43 |
if self.connection.strategy.pooled: |
| 44 |
self.connection.strategy.terminate() |
| 45 |
self.assertEqual(self.connection.closed, True) |
| 46 |
self.assertEqual(self.connection.bound, False) |
| 47 |
|
| 48 |
def test_bind_connection(self): |
| 49 |
self.connection.open() |
| 50 |
self.assertEqual(self.connection.closed, False) |
| 51 |
self.connection.bind() |
| 52 |
self.assertEqual(self.connection.bound, True) |
| 53 |
self.connection.unbind() |
| 54 |
if self.connection.strategy.pooled: |
| 55 |
self.connection.strategy.terminate() |
| 56 |
self.assertEqual(self.connection.closed, True) |
| 57 |
self.assertEqual(self.connection.bound, False) |
| 58 |
|
| 59 |
def test_connection_in_context(self): |
| 60 |
with self.connection: |
| 61 |
self.assertEqual(self.connection.closed, False) |
| 62 |
self.assertEqual(self.connection.bound, True) |
| 63 |
|
| 64 |
if self.connection.strategy.pooled: |
| 65 |
self.connection.strategy.terminate() |
| 66 |
|
| 67 |
self.assertEqual(self.connection.closed, True) |
| 68 |
self.assertEqual(self.connection.bound, False) |
| 69 |
|
| 70 |
def test_connection_in_context_with_as(self): |
| 71 |
with self.connection as c: |
| 72 |
self.assertEqual(c.closed, False) |
| 73 |
self.assertEqual(c.bound, True) |
| 74 |
|
| 75 |
if self.connection.strategy.pooled: |
| 76 |
self.connection.strategy.terminate() |
| 77 |
|
| 78 |
self.assertEqual(self.connection.closed, True) |
| 79 |
self.assertEqual(self.connection.bound, False) |