| 1 |
""" |
| 2 |
""" |
| 3 |
|
| 4 |
# Created on 2013.09.13 |
| 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 Server, OFFLINE_EDIR_9_1_4, SchemaInfo, DsaInfo |
| 29 |
from ldap3.protocol.rfc4512 import ObjectClassInfo, AttributeTypeInfo |
| 30 |
from test.config import test_server, get_connection, drop_connection |
| 31 |
|
| 32 |
|
| 33 |
class Test(unittest.TestCase): |
| 34 |
def setUp(self): |
| 35 |
self.connection = get_connection(get_info=OFFLINE_EDIR_9_1_4) |
| 36 |
|
| 37 |
def tearDown(self): |
| 38 |
drop_connection(self.connection) |
| 39 |
self.assertFalse(self.connection.bound) |
| 40 |
|
| 41 |
def test_offline_schema(self): |
| 42 |
if not self.connection.strategy.pooled: |
| 43 |
if not self.connection.server.schema: |
| 44 |
self.connection.refresh_server_info() |
| 45 |
self.assertEqual(type(self.connection.server.schema), SchemaInfo) |
| 46 |
|
| 47 |
def test_object_classes(self): |
| 48 |
if not self.connection.strategy.pooled: |
| 49 |
if not self.connection.server.info: |
| 50 |
self.connection.refresh_server_info() |
| 51 |
self.assertEqual(type(self.connection.server.schema.object_classes['inetOrgPerson']), ObjectClassInfo) |
| 52 |
|
| 53 |
def test_attributes_types(self): |
| 54 |
if not self.connection.strategy.pooled: |
| 55 |
if not self.connection.server.info: |
| 56 |
self.connection.refresh_server_info() |
| 57 |
self.assertEqual(type(self.connection.server.schema.attribute_types['cn']), AttributeTypeInfo) |
| 58 |
|
| 59 |
def test_json_definition(self): |
| 60 |
if not self.connection.strategy.pooled: |
| 61 |
if not self.connection.server.info: |
| 62 |
self.connection.refresh_server_info() |
| 63 |
json_info = self.connection.server.info.to_json() |
| 64 |
json_schema = self.connection.server.schema.to_json() |
| 65 |
info = DsaInfo.from_json(json_info) |
| 66 |
schema = SchemaInfo.from_json(json_schema) |
| 67 |
server1 = Server.from_definition(test_server, info, schema) |
| 68 |
json_info1 = server1.info.to_json() |
| 69 |
json_schema1 = server1.schema.to_json() |
| 70 |
self.assertEqual(json_info, json_info1) |
| 71 |
self.assertEqual(json_schema, json_schema1) |