Debian Codegraph @

test/testSchema.py

raw
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, ALL, 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=ALL, lazy_connection=False)
36 self.delete_at_teardown = []
37
38 def tearDown(self):
39 drop_connection(self.connection)
40 self.assertFalse(self.connection.bound)
41
42 def test_schema(self):
43 if not self.connection.strategy.pooled:
44 self.assertEqual(type(self.connection.server.schema), SchemaInfo)
45
46 def test_object_classes(self):
47 if not self.connection.strategy.pooled:
48 self.assertEqual(type(self.connection.server.schema.object_classes['inetOrgPerson']), ObjectClassInfo)
49
50 def test_attributes_types(self):
51 if self.connection.server.schema:
52 self.assertEqual(type(self.connection.server.schema.attribute_types['cn']), AttributeTypeInfo)
53
54 def test_json_definition(self):
55 if not self.connection.strategy.pooled:
56 if not self.connection.server.info:
57 self.connection.refresh_server_info()
58
59 json_info = self.connection.server.info.to_json()
60 json_schema = self.connection.server.schema.to_json()
61 info = DsaInfo.from_json(json_info)
62 schema = SchemaInfo.from_json(json_schema)
63 server1 = Server.from_definition(test_server, info, schema)
64 json_info1 = server1.info.to_json()
65 json_schema1 = server1.schema.to_json()
66 self.assertEqual(json_info, json_info1)
67 self.assertEqual(json_schema, json_schema1)