def test_search(self): """Test searching for objects """ self.assertEqual(LDAP_CONN.search( QA, search_filter=eq(QA.string, u"Max Blank"))[0].dn, 'cn=Max Blank,ou=users,dc=company,dc=com' )
def test_filters(self): """Test search filters """ users = LDAP_CONN.search( PosixUser, search_filter=eq(PosixUser.firstname, u"ĄĆĘ")) self.assertNotEqual(users, []) users = LDAP_CONN.search( PosixUser, search_filter=present(PosixUser.firstname)) self.assertNotEqual(users, []) users = LDAP_CONN.search( PosixUser, search_filter=startswith(PosixUser.fullname, u"Max")) self.assertNotEqual(users, []) users = LDAP_CONN.search( PosixUser, search_filter=endswith(PosixUser.fullname, u"Blank")) self.assertNotEqual(users, []) users = LDAP_CONN.search( PosixUser, search_filter=contains(PosixUser.fullname, u"x Bl")) self.assertNotEqual(users, []) users = LDAP_CONN.search( PosixUser, search_filter=opor( contains(PosixUser.fullname, u"ank"), endswith(PosixUser.fullname, u"dict"), ) ) self.assertNotEqual(users, []) users = LDAP_CONN.search( PosixUser, search_filter=opnot(eq(PosixUser.fullname, u"NotFound"))) self.assertNotEqual(users, [])
def test_objectlist(self): """Test objectlist methods """ users = LDAP_CONN.search(PosixUser) user = users.by_dn("cn=Max Blank,ou=users,dc=company,dc=com") self.assertEqual(user.dn, "cn=Max Blank,ou=users,dc=company,dc=com") user = users.with_attr('shell')[0] self.assertEqual(user.dn, "cn=Max Blank,ou=users,dc=company,dc=com") user = users.by_dn("cn=InvalidDN,dc=company,dc=com") self.assertEqual(user, None) s = users.pickle() self.assertNotEqual(s, None)
from pumpkin.resource import LDAPResource from pumpkin.directory import Directory from pumpkin.models import PosixGroup, PosixUser from conn import LDAP_CONN for I in range(10): print('Simple search') for pg in LDAP_CONN.search(PosixUser): print(pg.dn) print('\tcn: %s' % pg.fullname) print('\tgid: %s' % pg.gid) print('\tuid: %s' % pg.uid) print('') """ print('OC info for: PosixGroup') (must, may) = LDAP_CONN.get_schema_attrs(PosixGroup) print('MUST : %s' % must) print('MAY: %s' % may) """