Commit 2d61a116 authored by Lorenz Steinert's avatar Lorenz Steinert

added basic testcases for the FsrLdap class

parent 8b3c1bba
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import unittest
import ldap3 as ldap
from esme import FsrLdap
class FsrLdapTest(unittest.TestCase):
def setUp(self):
self.test_ldap_server = 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', 'test2', 'test3']})
conn.strategy.add_entry('cn=extern,ou=group,'+self.test_ldap_server.base,
{'memberUid': ['test4', 'test5', 'test6']})
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.strategy.add_entry('uid=test3,ou=people,'+self.test_ldap_server.base,
{'displayName': 'test3, testing'})
conn.strategy.add_entry('uid=test4,ou=people,'+self.test_ldap_server.base,
{'displayName': 'test4, testing'})
conn.strategy.add_entry('uid=test5,ou=people,'+self.test_ldap_server.base,
{'displayName': 'test5, testing'})
conn.strategy.add_entry('uid=test6,ou=people,'+self.test_ldap_server.base,
{'displayName': 'test6, 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"
def test_get_fsr_ldap(self):
self.assertEqual(self.test_ldap_server.get_fsr_ldap(self.sharedir, testing=True),
['testing test1', 'testing test2', 'testing test3'])
def test_get_fsr_ldap_no_server(self):
self.test_ldap_server.server = ""
self.assertEqual(self.test_ldap_server.get_fsr_ldap(self.sharedir, testing=True),
[])
def test_get_fsr_extern_ldap_no_server(self):
self.test_ldap_server.server = ""
self.assertEqual(self.test_ldap_server.get_fsr_extern_ldap(self.sharedir, testing=True),
[])
def test_get_fsr_extern_ldap(self):
self.assertEqual(self.test_ldap_server.get_fsr_extern_ldap(self.sharedir, testing=True),
['testing test4', 'testing test5', 'testing test6'])
def tearDown(self):
os.remove("/tmp/python3-esme-testing/fsr")
os.remove("/tmp/python3-esme-testing/fsr_extern")
os.rmdir("/tmp/python3-esme-testing")
if __name__ == "__main__":
unittest.main()
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