| 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 test.config import random_id, get_connection, drop_connection, add_user |
| 29 |
|
| 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(check_names=True) |
| 39 |
self.delete_at_teardown = [] |
| 40 |
self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'compare-1', attributes={'givenName': 'compare'})) |
| 41 |
|
| 42 |
def tearDown(self): |
| 43 |
drop_connection(self.connection, self.delete_at_teardown) |
| 44 |
self.assertFalse(self.connection.bound) |
| 45 |
|
| 46 |
def test_compare_true(self): |
| 47 |
result = self.connection.compare(self.delete_at_teardown[0][0], 'givenName', 'compare') |
| 48 |
if not self.connection.strategy.sync: |
| 49 |
_, result = self.connection.get_response(result) |
| 50 |
else: |
| 51 |
result = self.connection.result |
| 52 |
|
| 53 |
self.assertEqual(result['description'], 'compareTrue') |
| 54 |
|
| 55 |
def test_compare_true_with_get_request(self): |
| 56 |
result = self.connection.compare(self.delete_at_teardown[0][0], 'givenName', 'compare') |
| 57 |
if not self.connection.strategy.sync: |
| 58 |
_, result, request = self.connection.get_response(result, get_request=True) |
| 59 |
self.assertEqual(request['type'], 'compareRequest') |
| 60 |
else: |
| 61 |
result = self.connection.result |
| 62 |
|
| 63 |
self.assertEqual(result['description'], 'compareTrue') |
| 64 |
|
| 65 |
|
| 66 |
def test_compare_false(self): |
| 67 |
result = self.connection.compare(self.delete_at_teardown[0][0], 'givenName', 'error') |
| 68 |
if not self.connection.strategy.sync: |
| 69 |
_, result = self.connection.get_response(result) |
| 70 |
else: |
| 71 |
result = self.connection.result |
| 72 |
|
| 73 |
self.assertEqual(result['description'], 'compareFalse') |