Debian Codegraph @

test/testLDIF-content.py

raw
1 """
2 """
3
4 # Created on 2013.12.10
5 #
6 # Author: Giovanni Cannata
7 #
8 # Copyright 2013 - 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 test_base, test_name_attr, get_connection, random_id, add_user, \
29 drop_connection
30
31 testcase_id = ''
32
33
34 class Test(unittest.TestCase):
35 def setUp(self):
36 global testcase_id
37 testcase_id = random_id()
38 self.connection = get_connection()
39 self.delete_at_teardown = []
40 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'ldif-content-1'))
41 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'ldif-content-2'))
42
43 def tearDown(self):
44 drop_connection(self.connection, self.delete_at_teardown)
45 self.assertFalse(self.connection.bound)
46
47 def test_single_search_result_to_ldif(self):
48 result = self.connection.search(search_base=test_base, search_filter='(' + test_name_attr + '=' + testcase_id + 'ldif-content-1)', attributes=[test_name_attr, 'givenName', 'objectClass', 'sn'])
49 if not self.connection.strategy.sync:
50 response, result = self.connection.get_response(result)
51 else:
52 response = self.connection.response
53
54 l = self.connection.response_to_ldif(response).lower()
55 self.assertTrue('version: 1' in l)
56 self.assertTrue('dn: ' + test_name_attr.lower() + '=' + testcase_id.lower() + 'ldif-content-1,' + test_base.lower() in l)
57 self.assertTrue('objectclass: inetorgperson' in l)
58 self.assertTrue('objectclass: top' in l)
59 self.assertTrue(test_name_attr.lower() + ': ' + testcase_id.lower() + 'ldif-content-1' in l)
60 self.assertTrue('sn: ldif-content-1' in l)
61 self.assertTrue('total number of entries: 1' in l)
62
63 def test_multiple_search_result_to_ldif(self):
64 result = self.connection.search(search_base=test_base, search_filter='(' + test_name_attr + '=' + testcase_id + 'ldif-content-*)', attributes=[test_name_attr, 'givenName', 'sn', 'objectClass'])
65 if not self.connection.strategy.sync:
66 response, result = self.connection.get_response(result)
67 else:
68 response = self.connection.response
69
70 l = self.connection.response_to_ldif(response).lower()
71
72 self.assertTrue('version: 1' in l)
73 self.assertTrue('dn: ' + test_name_attr.lower() + '=' + testcase_id.lower() + 'ldif-content-1,' + test_base.lower() in l)
74 self.assertTrue('objectclass: inetorgperson' in l)
75 self.assertTrue('objectclass: top' in l)
76 self.assertTrue(test_name_attr.lower() + ': ' + testcase_id + 'ldif-content-1' in l)
77 self.assertTrue('sn: ldif-content-1' in l)
78 self.assertTrue('dn: ' + test_name_attr.lower() + '=' + testcase_id.lower() + 'ldif-content-1,' + test_base.lower() in l)
79 self.assertTrue(test_name_attr.lower() + ': ' + testcase_id.lower() + 'ldif-content-2' in l)
80 self.assertTrue('sn: ldif-content-2' in l)
81 self.assertTrue('# total number of entries: 2' in l)