Add tests for ldap.add_ext.

This commit is contained in:
Raphaël Barrois 2016-03-10 11:51:43 +01:00
parent 3e2d88996c
commit 97cb08db0d
2 changed files with 79 additions and 0 deletions

78
Tests/t_edit.py Normal file
View File

@ -0,0 +1,78 @@
from __future__ import unicode_literals
import sys
if sys.version_info[0] <= 2:
PY2 = True
text_type = unicode
else:
PY2 = False
text_type = str
import ldap, unittest
import slapd
from ldap.ldapobject import LDAPObject
server = None
class EditionTests(unittest.TestCase):
def setUp(self):
global server
if server is None:
server = slapd.Slapd()
server.start()
base = server.get_dn_suffix()
# insert some Foo* objects via ldapadd
server.ldapadd("\n".join([
"dn: cn=Foo1,"+base,
"objectClass: organizationalRole",
"cn: Foo1",
"",
"dn: cn=Foo2,"+base,
"objectClass: organizationalRole",
"cn: Foo2",
"",
"dn: cn=Foo3,"+base,
"objectClass: organizationalRole",
"cn: Foo3",
"",
"dn: ou=Container,"+base,
"objectClass: organizationalUnit",
"ou: Container",
"",
"dn: cn=Foo4,ou=Container,"+base,
"objectClass: organizationalRole",
"cn: Foo4",
"",
])+"\n")
l = LDAPObject(server.get_url(), bytes_mode=False)
l.protocol_version = 3
l.set_option(ldap.OPT_REFERRALS,0)
l.simple_bind_s(server.get_root_dn(),
server.get_root_password())
self.ldap = l
self.server = server
def test_add_object(self):
base = self.server.get_dn_suffix()
dn = "cn=Added,ou=Container," + base
self.ldap.add_ext_s(dn, [
("objectClass", [b'organizationalRole']),
("cn", [b'Added']),
])
# Lookup the object
result = self.ldap.search_s(base, ldap.SCOPE_SUBTREE, '(cn=Added)', ['*'])
self.assertEqual(result, [
("cn=Added,ou=Container," + base,
{'cn': [b'Added'], 'objectClass': [b'organizationalRole']}),
])
if __name__ == '__main__':
unittest.main()

View File

@ -6,6 +6,7 @@ changedir={toxinidir}/Tests
commands =
{envpython} {toxinidir}/Tests/t_ldapurl.py
{envpython} {toxinidir}/Tests/t_cext.py
{envpython} {toxinidir}/Tests/t_edit.py
{envpython} {toxinidir}/Tests/t_search.py
{envpython} {toxinidir}/Tests/t_ldif.py
{envpython} {toxinidir}/Tests/Lib/ldap/schema/test_tokenizer.py