Debian Codegraph @

test/testModifyDNOperation.py

raw
1 """
2 """
3
4 # Created on 2013.06.06
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 from time import sleep
27
28 import unittest
29
30 from test.config import test_base, test_moved, test_name_attr, random_id, \
31 get_connection, add_user, drop_connection
32
33 testcase_id = ''
34
35
36 class Test(unittest.TestCase):
37 def setUp(self):
38 global testcase_id
39 testcase_id = random_id()
40 self.connection = get_connection()
41 self.delete_at_teardown = []
42
43 def tearDown(self):
44 drop_connection(self.connection, self.delete_at_teardown)
45 self.assertFalse(self.connection.bound)
46
47 def test_modify_dn_operation(self):
48 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'modify-dn-1'))
49 result = self.connection.modify_dn(self.delete_at_teardown[0][0], test_name_attr + '=' + testcase_id + 'modified-dn-1')
50 if not self.connection.strategy.sync:
51 _, result = self.connection.get_response(result)
52 else:
53 result = self.connection.result
54 self.delete_at_teardown[0] = (self.delete_at_teardown[0][0].replace('modify-dn-1', 'modified-dn-1'), self.delete_at_teardown[0][1])
55 self.assertEqual(result['description'], 'success')
56
57 def test_move_dn(self):
58 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'modify-dn-2'))
59 counter = 20
60 result = None
61 while counter > 0: # tries move operation for at maximum 20 times - partition may be busy while moving (at least on eDirectory)
62 result = self.connection.modify_dn(self.delete_at_teardown[0][0], test_name_attr + '=' + testcase_id + 'modify-dn-2', new_superior=test_moved)
63 if not self.connection.strategy.sync:
64 _, result = self.connection.get_response(result)
65 else:
66 result = self.connection.result
67 if result['description'] == 'success':
68 break
69 sleep(2)
70 counter -= 1
71 self.delete_at_teardown[0] = (self.delete_at_teardown[0][0].replace(test_base, test_moved), self.delete_at_teardown[0][1])
72 self.assertEqual('success', result['description'])
73
74 def test_modify_dn_operation_with_get_request(self):
75 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'modify-dn-3'))
76 result = self.connection.modify_dn(self.delete_at_teardown[0][0], test_name_attr + '=' + testcase_id + 'modified-dn-3')
77 if not self.connection.strategy.sync:
78 _, result, request = self.connection.get_response(result, get_request=True)
79 self.assertEqual(request['type'], 'modDNRequest')
80 else:
81 result = self.connection.result
82 self.delete_at_teardown[0] = (self.delete_at_teardown[0][0].replace('modify-dn-3', 'modified-dn-3'), self.delete_at_teardown[0][1])
83 self.assertEqual(result['description'], 'success')
84
85 def test_move_dn_with_get_request(self):
86 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'modify-dn-4'))
87 counter = 20
88 result = None
89 while counter > 0: # tries move operation for at maximum 20 times - partition may be busy while moving (at least on eDirectory)
90 result = self.connection.modify_dn(self.delete_at_teardown[0][0], test_name_attr + '=' + testcase_id + 'modify-dn-4', new_superior=test_moved)
91 if not self.connection.strategy.sync:
92 _, result, request = self.connection.get_response(result, get_request=True)
93 self.assertEqual(request['type'], 'modDNRequest')
94 else:
95 result = self.connection.result
96 if result['description'] == 'success':
97 break
98 sleep(2)
99 counter -= 1
100
101 self.delete_at_teardown[0] = (self.delete_at_teardown[0][0].replace(test_base, test_moved), self.delete_at_teardown[0][1])
102 self.assertEqual('success', result['description'])
103