Commit 09f0e401 authored by Lorenz Steinert's avatar Lorenz Steinert

testing

parent 35342fd8
......@@ -14,54 +14,58 @@ class FsrLdapTest(unittest.TestCase):
def setUp(self):
"""setup for the tests"""
print(ldap.Server('test_server'))
self.test_ldap_server = esme.FsrLdap('test_server', 'dc=test,dc=de')
conn = ldap.Connection(self.test_ldap_server.server, client_strategy=ldap.MOCK_SYNC)
conn.strategy.add_entry('ou=people,'+self.test_ldap_server.base, {})
conn.strategy.add_entry('ou=group,'+self.test_ldap_server.base, {})
conn.strategy.add_entry('cn=intern,ou=group,'+self.test_ldap_server.base,
{'memberUid': 'test1'})
conn.strategy.add_entry('cn=extern,ou=group,'+self.test_ldap_server.base,
{'memberUid': 'test2'})
conn.strategy.add_entry('uid=test1,ou=people,'+self.test_ldap_server.base,
{'displayName': 'test1, testing'})
conn.strategy.add_entry('uid=test2,ou=people,'+self.test_ldap_server.base,
{'displayName': 'test2, testing'})
#conn = ldap.Connection(self.test_ldap_server.server, client_strategy=ldap.MOCK_SYNC)
#conn.strategy.add_entry('ou=people,'+self.test_ldap_server.base, {})
#conn.strategy.add_entry('ou=group,'+self.test_ldap_server.base, {})
#conn.strategy.add_entry('cn=intern,ou=group,'+self.test_ldap_server.base,
# {'memberUid': 'test1'})
#conn.strategy.add_entry('cn=extern,ou=group,'+self.test_ldap_server.base,
# {'memberUid': 'test2'})
#conn.strategy.add_entry('uid=test1,ou=people,'+self.test_ldap_server.base,
# {'displayName': 'test1, testing'})
#conn.strategy.add_entry('uid=test2,ou=people,'+self.test_ldap_server.base,
# {'displayName': 'test2, testing'})
os.mkdir("/tmp/python3-esme-testing")
open("/tmp/python3-esme-testing/fsr", 'a').close()
open("/tmp/python3-esme-testing/fsr_extern", 'a').close()
self.sharedir = "/tmp/python3-esme-testing"
self.conn = ldap.Connection(self.test_ldap_server, client_strategy=ldap.MOCK_SYNC)
def con(self, *arg):
return self.conn
def test_get_fsr_ldap(self):
"""test the get_fsr_ldap function"""
ldap.Connection = lambda x: ldap.Connection(self.test_ldap_server, client_strategy=ldap.MOCK_SYNC)
self.assertEqual(self.test_ldap_server.get_fsr_ldap(self.sharedir, testing=True),
ldap.Connection = self.con
self.assertEqual(self.test_ldap_server.get_fsr_ldap(self.sharedir),
['testing test1'])
def test_get_fsr_extern_ldap(self):
"""test the get_fsr_extern_ldap function"""
ldap.Connection = lambda x: ldap.Connection(self.test_ldap_server, client_strategy=ldap.MOCK_SYNC)
self.assertEqual(self.test_ldap_server.get_fsr_extern_ldap(self.sharedir, testing=True),
ldap.Connection = self.con
self.assertEqual(self.test_ldap_server.get_fsr_extern_ldap(self.sharedir),
['testing test2'])
def test_get_protokollant_ldap(self):
ldap.Connection = lambda x: ldap.Connection(self.test_ldap_server, client_strategy=ldap.MOCK_SYNC)
ldap.Connection = self.con
esme.current_user = lambda: 'testing test1'
self.assertEqual(self.test_ldap_server.get_protokollant_ldap({'PROTOKOLL': {'Protokollant': 'testing test3'}}), 'testing test1')
def test_get_fsr_ldap_no_server(self):
"""test the get_fsr_ldap function without ldap connection"""
ldap.Connection = lambda x: ldap.Connection('', client_strategy=ldap.MOCK_SYNC)
self.assertEqual(self.test_ldap_server.get_fsr_ldap(self.sharedir, testing=True),
ldap.Connection = self.con_non
self.assertEqual(self.test_ldap_server.get_fsr_ldap(self.sharedir),
[])
def test_get_fsr_extern_ldap_no_server(self):
"""test the get_fst_extern_ldap function without ldap connection"""
ldap.Connection = lambda x: ldap.Connection('', client_strategy=ldap.MOCK_SYNC)
self.assertEqual(self.test_ldap_server.get_fsr_extern_ldap(self.sharedir, testing=True),
ldap.Connection = self.con_non
self.assertEqual(self.test_ldap_server.get_fsr_extern_ldap(self.sharedir),
[])
def test_get_protokollant_ldap_no_server(self):
ldap.Connection = lambda x: ldap.Connection('', client_strategy=ldap.MOCK_SYNC)
ldap.Connection = self.con_non
esme.current_user = lambda: 'testing test1'
self.assertEqual(self.test_ldap_server.get_protokollant_ldap({'PROTOKOLL': {'Protokollant': 'testing test3'}}), 'testing test3')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment