| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2016.08.09 |
| 5 |
# |
| 6 |
# Author: Giovanni Cannata |
| 7 |
# |
| 8 |
# Copyright 2016 - 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 ldap3 import ALL |
| 29 |
from ldap3 import ObjectDef, Reader |
| 30 |
from test.config import test_base, get_connection, drop_connection, random_id, add_user |
| 31 |
|
| 32 |
testcase_id = '' |
| 33 |
|
| 34 |
|
| 35 |
class Test(unittest.TestCase): |
| 36 |
def setUp(self): |
| 37 |
global testcase_id |
| 38 |
testcase_id = random_id() |
| 39 |
self.connection = get_connection(get_info=ALL, check_names=True) |
| 40 |
self.delete_at_teardown = [] |
| 41 |
|
| 42 |
def tearDown(self): |
| 43 |
drop_connection(self.connection, self.delete_at_teardown) |
| 44 |
self.assertFalse(self.connection.bound) |
| 45 |
|
| 46 |
def test_create_objectdef_from_schema(self): |
| 47 |
o = ObjectDef(['inetorgPerson', 'person'], self.connection) |
| 48 |
self.assertEqual(o.cn.name, 'cn') |
| 49 |
|
| 50 |
def test_search_object(self): |
| 51 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'abstract-1')) |
| 52 |
o = ObjectDef(['inetorgPerson', 'person'], self.connection) |
| 53 |
r = Reader(self.connection, o, test_base, '(cn=' + testcase_id + 'abstract-1)') |
| 54 |
r.search(attributes='cn') # AD returns operationError for reading some atributes |
| 55 |
self.assertEqual(len(r), 1) |
| 56 |
self.assertEqual(r.entries[0].cn, testcase_id + 'abstract-1') |