Debian Codegraph @

test/testModifyOperation.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 import unittest
27
28 from ldap3 import MODIFY_REPLACE, MODIFY_ADD, MODIFY_DELETE
29 from test.config import random_id, get_connection, add_user, \
30 drop_connection
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()
40 self.delete_at_teardown = []
41 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'modify-1', attributes={'givenName': 'givenname-1'}))
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_replace(self):
48 result = self.connection.modify(self.delete_at_teardown[0][0], {'givenName': (MODIFY_REPLACE, ['givenname-1-replaced']), 'sn': (MODIFY_REPLACE, ['sn-replaced'])})
49 if not self.connection.strategy.sync:
50 _, result = self.connection.get_response(result)
51 else:
52 result = self.connection.result
53 self.assertEqual(result['description'], 'success')
54
55 def test_modify_replace_with_get_request(self):
56 result = self.connection.modify(self.delete_at_teardown[0][0], {'givenName': (MODIFY_REPLACE, ['givenname-1-replaced']), 'sn': (MODIFY_REPLACE, ['sn-replaced'])})
57 if not self.connection.strategy.sync:
58 _, result, request = self.connection.get_response(result, get_request=True)
59 self.assertEqual(request['type'], 'modifyRequest')
60 else:
61 result = self.connection.result
62 self.assertEqual(result['description'], 'success')
63
64 def test_modify_add(self):
65 result = self.connection.modify(self.delete_at_teardown[0][0], {'businessCategory': (MODIFY_ADD, ['businessCategory-2-added'])})
66 if not self.connection.strategy.sync:
67 _, result = self.connection.get_response(result)
68 else:
69 result = self.connection.result
70 self.assertEqual(result['description'], 'success')
71
72 def test_modify_delete_attribute_value(self):
73 result = self.connection.modify(self.delete_at_teardown[0][0], {'businessCategory': (MODIFY_ADD, ['businessCategory-3-added', 'businessCategory-4-added'])})
74 if not self.connection.strategy.sync:
75 _, result = self.connection.get_response(result)
76 else:
77 result = self.connection.result
78 self.assertEqual(result['description'], 'success')
79
80 result = self.connection.modify(self.delete_at_teardown[0][0], {'businessCategory': (MODIFY_DELETE, ['businessCategory-3-added'])})
81 if not self.connection.strategy.sync:
82 _, result = self.connection.get_response(result)
83 else:
84 result = self.connection.result
85 self.assertEqual(result['description'], 'success')
86
87 def test_modify_delete_attribute(self):
88 result = self.connection.modify(self.delete_at_teardown[0][0], {'businessCategory': (MODIFY_ADD, ['businessCategory-5-added', 'businessCategory-6-added'])})
89 if not self.connection.strategy.sync:
90 _, result = self.connection.get_response(result)
91 else:
92 result = self.connection.result
93 self.assertEqual(result['description'], 'success')
94
95 result = self.connection.modify(self.delete_at_teardown[0][0], {'businessCategory': (MODIFY_DELETE, [])})
96 if not self.connection.strategy.sync:
97 _, result = self.connection.get_response(result)
98 else:
99 result = self.connection.result
100 self.assertEqual(result['description'], 'success')
101
102 def test_delete_add_same_attribute(self):
103 result = self.connection.modify(self.delete_at_teardown[0][0], {'businessCategory': (MODIFY_ADD, ['businessCategory-7-added', 'businessCategory-8-added', 'businessCategory-9-added'])})
104 if not self.connection.strategy.sync:
105 _, result = self.connection.get_response(result)
106 else:
107 result = self.connection.result
108 self.assertEqual(result['description'], 'success')
109
110 result = self.connection.modify(self.delete_at_teardown[0][0], {'businessCategory': [(MODIFY_DELETE, ['businessCategory-8-added']), (MODIFY_ADD, ['business-Category-10-added'])]})
111
112 if not self.connection.strategy.sync:
113 _, result = self.connection.get_response(result)
114 else:
115 result = self.connection.result
116 self.assertEqual(result['description'], 'success')