def test_get_children(self): """Test calling get_children() method """ unit = Unit(LDAP_CONN, "ou=users,dc=company,dc=com") self.assertEqual( [u'cn=hook_user,ou=users,dc=company,dc=com', u'cn=Max Blank,ou=users,dc=company,dc=com', u'cn=test_binary,ou=users,dc=company,dc=com', u'cn=test_datetime,ou=users,dc=company,dc=com', u'cn=test_dict,ou=users,dc=company,dc=com'], [c.dn for c in unit.get_children()] )
def test_rename_with_children(self): """Test renaming object with children """ unit = Unit(LDAP_CONN, "ou=rename,dc=company,dc=com") unit.name = u"after_rename" unit.save() old = LDAP_CONN.get(Unit, search_filter=eq(Unit.name, "rename"), basedn=unit.dn) self.assertEqual(None, old) self.assertEqual(unit.dn, u"ou=after_rename,dc=company,dc=com") l1_2 = LDAP_CONN.get(Unit, search_filter=eq(Unit.name, 'l1_2'), basedn=unit.dn) self.assertEqual(l1_2.dn, u'ou=l1_2,ou=l1,ou=after_rename,dc=company,dc=com') self.assertEqual(l1_2.name, u'l1_2')
def test_recursive_delete(self): """Test recursive delete on object """ for i in range(1, 10): ou = Unit(LDAP_CONN) if i > 1: parent = u"ou=unit1,%s" % LDAP_CONN.get_basedn() for j in range(2, i): parent = u"ou=unit%d,%s" % (j, parent) ou.set_parent(parent) ou.name = u"unit%d" % i ou.save() ou = Unit(LDAP_CONN, "ou=unit1,%s" % LDAP_CONN.get_basedn()) ou.delete(recursive=True)
def test_rename_with_children_unicode(self): """Test renaming object with children when unicode characters are used as part of object dn. """ unit = Unit(LDAP_CONN, "ou=rename_ąźć,dc=company,dc=com") unit.name = u"renamed_łóźććżą" unit.save() old = LDAP_CONN.get(Unit, search_filter=eq(Unit.name, "rename_ąźć"), basedn=unit.dn) self.assertEqual(None, old) self.assertEqual(unit.dn, u"ou=renamed_łóźććżą,dc=company,dc=com") l1_1 = LDAP_CONN.get(Unit, search_filter=eq(Unit.name, 'l1_1'), basedn=unit.dn) self.assertEqual(l1_1.dn, u'ou=l1_1,ou=l1,ou=renamed_łóźććżą,dc=company,dc=com') self.assertEqual(l1_1.name, u'l1_1') self.assertEqual(l1_1.description, u'l1_1 unit')
def test_posixgroup(self): """Test PosixGroup methods """ ou = Unit(LDAP_CONN) ou.name = u"posix_group" ou.save() pu = PosixUser(LDAP_CONN) pu.set_parent(ou.dn) pu.uid = 8361 pu.gid = 8245 pu.login = u"login" pu.surname = u"Surname" pu.fullname = u"Fullname" pu.home = u"/home" pu.save() pg = PosixGroup(LDAP_CONN) pg.set_parent(ou.dn) pg.name = u"group" pg.gid = 45921 pg.save() self.assertFalse(pg.ismember(pu.uid)) pg.add_member(pu.uid) pg.save() pg.update() pu.update() self.assertEqual(pu.gid, pg.gid) self.assertRaises(ValueError, pg.remove_member, 1) pg.remove_member(pu.uid) pg.save() pg.update() self.assertFalse(pg.ismember(pu.uid)) ou.delete(recursive=True)
def test_unicode_dn_(self): """Test handling objects with unicode characters in dn. """ # test adding new object ou = Unit(LDAP_CONN) ou.name = u'ąźćżłóśę' ou.save() self.assertEqual(ou.dn, u'ou=ąźćżłóśę,%s' % BASEDN) # test renaming ou.name = u'ŁĘĆŹ' ou.save() self.assertEqual(ou.dn, u'ou=ŁĘĆŹ,%s' % BASEDN) # test moving ou.set_parent('ou=users,%s' % BASEDN) ou.save() self.assertEqual(ou.dn, u'ou=ŁĘĆŹ,ou=users,%s' % BASEDN) # test deleting ou.delete()