formating

parent 219c13d0
......@@ -9,6 +9,7 @@ import configparser
import ldap3 as ldap
import esme
class FsrLdapTest(unittest.TestCase):
"""test the functions with ldap"""
......@@ -77,25 +78,31 @@ class FsrLdapTest(unittest.TestCase):
def test_get_protokollant_ldap(self):
"""test the get_protokollant_ldap function"""
esme.current_user = lambda: 'test1'
self.assertEqual(self.ldap_server._get_protokollant_ldap(), 'testing test1')
self.assertEqual(self.info, ['Fetching Protokollant from LDAP ...', 'Done'])
self.assertEqual(self.ldap_server._get_protokollant_ldap(),
'testing test1')
self.assertEqual(self.info, ['Fetching Protokollant from LDAP ...',
'Done'])
self.assertEqual(self.warning, [])
def test_get_fallback_fsr(self):
"""test the get_fallback_fsr function"""
sharedir = "/tmp/python3-esme-testing"
self.assertEqual(self.ldap_server._get_fallback_fsr(sharedir), ['testing test1'])
self.assertEqual(self.ldap_server._get_fallback_fsr(sharedir),
['testing test1'])
os.remove("/tmp/python3-esme-testing/fsr")
self.assertEqual(self.ldap_server._get_fallback_fsr(sharedir), esme.Error.NO_FILE)
self.assertEqual(self.ldap_server._get_fallback_fsr(sharedir),
esme.Error.NO_FILE)
self.assertEqual(self.info, [])
self.assertEqual(self.warning, [])
def test_get_fallback_fsr_extern(self):
"""test the get_fallback_fsr_extern function"""
sharedir = "/tmp/python3-esme-testing"
self.assertEqual(self.ldap_server._get_fallback_fsr_extern(sharedir), ['testing test2'])
self.assertEqual(self.ldap_server._get_fallback_fsr_extern(sharedir),
['testing test2'])
os.remove("/tmp/python3-esme-testing/fsr_extern")
self.assertEqual(self.ldap_server._get_fallback_fsr_extern(sharedir), esme.Error.NO_FILE)
self.assertEqual(self.ldap_server._get_fallback_fsr_extern(sharedir),
esme.Error.NO_FILE)
self.assertEqual(self.info, [])
self.assertEqual(self.warning, [])
......@@ -105,8 +112,10 @@ class FsrLdapTest(unittest.TestCase):
esme.input = lambda x: 'testinput'
self.assertEqual(self.ldap_server._get_fallback_protokollant(self.ldap_server.config),
"testinput")
self.assertEqual(self.ldap_server._get_fallback_protokollant(config), "testinput")
self.assertEqual(self.ldap_server._get_fallback_protokollant(), "testinput")
self.assertEqual(self.ldap_server._get_fallback_protokollant(config),
"testinput")
self.assertEqual(self.ldap_server._get_fallback_protokollant(),
"testinput")
esme.input = lambda x: ''
self.assertEqual(self.ldap_server._get_fallback_protokollant(self.ldap_server.config),
......@@ -148,7 +157,8 @@ class FsrLdapTest(unittest.TestCase):
self.assertEqual(self.ldap_server._get_fsr_ldap()[0],
esme.Error.LDAP_FAIL)
self.assertEqual(self.info, ['Fetching FSR from LDAP ...'])
self.assertEqual(self.warning, ["Couldn't Connect to ldap. Using fallback File."])
self.assertEqual(self.warning,
["Couldn't Connect to ldap. Using fallback File."])
def test_get_fsr_extern_ldap_ldap_exception(self):
"""test the get_fsr_extern_ldap function with a LDAPException"""
......@@ -156,7 +166,8 @@ class FsrLdapTest(unittest.TestCase):
self.assertEqual(self.ldap_server._get_fsr_extern_ldap()[0],
esme.Error.LDAP_FAIL)
self.assertEqual(self.info, ['Fetching EFSR from LDAP ...'])
self.assertEqual(self.warning, ["Couldn't Connect to ldap. Using fallback File."])
self.assertEqual(self.warning,
["Couldn't Connect to ldap. Using fallback File."])
def test_get_protokollant_ldap_ldap_exception(self):
"""test the get_protokollant_ldap function with a LDAPException"""
......@@ -165,7 +176,8 @@ class FsrLdapTest(unittest.TestCase):
self.assertEqual(self.ldap_server._get_protokollant_ldap(),
esme.Error.LDAP_FAIL)
self.assertEqual(self.info, ['Fetching Protokollant from LDAP ...'])
self.assertEqual(self.warning, ["Couldn't Connect to ldap. Using fallback default."])
self.assertEqual(self.warning,
["Couldn't Connect to ldap. Using fallback default."])
def tearDown(self):
"""cleanup after the tests"""
......@@ -241,23 +253,29 @@ class GetFuncTest(unittest.TestCase):
def test_get_config(self):
"""test the get_config function"""
self.assertEqual(esme.get_config("", "/tmp/python3-esme-testing/etc/proto.ini"),
self.assertEqual(esme.get_config("",
"/tmp/python3-esme-testing/etc/proto.ini"),
self.config)
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"),
self.config)
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"), self.config)
os.remove("/tmp/python3-esme-testing/etc/proto.ini")
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"), self.config1)
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc", default=True),
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"),
self.config1)
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc",
default=True),
self.config1)
os.remove("/tmp/python3-esme-testing/etc/proto.ini.default")
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"),
esme.Error.NO_DEFAULT_FILE)
esme.Error.NO_DEFAULT_FILE)
self.assertEqual(self.info, [])
self.assertEqual(self.warning, ['No non default ini file found using default file.',
'No ini file found. Using hardcoded defaults.'])
self.assertEqual(self.warning,
['No non default ini file found using default file.',
'No ini file found. Using hardcoded defaults.'])
def test_get_share(self):
"""test the get_share function"""
self.assertEqual(esme.get_share("", self.config), '/tmp/python3-esme-testing/share')
self.assertEqual(esme.get_share("", self.config),
'/tmp/python3-esme-testing/share')
self.assertEqual(os.path.abspath(esme.get_share("/tmp/python3-esme-testing/share")),
'/tmp/python3-esme-testing/share')
self.assertEqual(os.path.abspath(esme.get_share("", self.config,
......@@ -268,7 +286,8 @@ class GetFuncTest(unittest.TestCase):
def test_get_path(self):
"""test the get_path function"""
self.assertEqual(esme.get_path("", self.config), '/tmp/python3-esme-testing')
self.assertEqual(esme.get_path("", self.config),
'/tmp/python3-esme-testing')
self.assertEqual(os.path.abspath(esme.get_path("/tmp/python3-esme-testing/etc/test")),
'/tmp/python3-esme-testing')
self.assertEqual(os.path.abspath(esme.get_path("", self.config,
......@@ -281,21 +300,28 @@ class GetFuncTest(unittest.TestCase):
"""test the get_ldap_server function"""
self.assertEqual(esme.get_ldap_server(self.config), 'test_server')
self.assertEqual(esme.get_ldap_server(server='testing'), 'testing')
self.assertEqual(esme.get_ldap_server(self.config, 'testing'), 'testing')
self.assertEqual(esme.get_ldap_server(), 'rincewind.fs.physik.uni-kl.de')
self.assertEqual(esme.get_ldap_server(self.config, 'testing'),
'testing')
self.assertEqual(esme.get_ldap_server(),
'rincewind.fs.physik.uni-kl.de')
self.assertEqual(self.info, [])
self.assertEqual(self.warning,
['No LDAP Server supplied. Triing to use "rincwind.fs.physik.uni-kl.de".'])
['No LDAP Server supplied. '
+ 'Triing to use "rincwind.fs.physik.uni-kl.de".'])
def test_get_ldap_base(self):
"""test the get_ldap_base function"""
self.assertEqual(esme.get_ldap_base(self.config), 'dc=test,dc=de')
self.assertEqual(esme.get_ldap_base(base='dc=testing,dc=de'), 'dc=testing,dc=de')
self.assertEqual(esme.get_ldap_base(self.config, 'dc=testing,dc=de'), 'dc=testing,dc=de')
self.assertEqual(esme.get_ldap_base(), 'dc=fs,dc=physik,dc=uni-kl,dc=de')
self.assertEqual(esme.get_ldap_base(base='dc=testing,dc=de'),
'dc=testing,dc=de')
self.assertEqual(esme.get_ldap_base(self.config, 'dc=testing,dc=de'),
'dc=testing,dc=de')
self.assertEqual(esme.get_ldap_base(),
'dc=fs,dc=physik,dc=uni-kl,dc=de')
self.assertEqual(self.info, [])
self.assertEqual(self.warning, ['No LDAP search base supplied. ' \
+ 'Triing to use "dc=fs,dc=physik,dc=uni-kl,dc=de".'])
self.assertEqual(self.warning,
['No LDAP search base supplied. '
+ 'Triing to use "dc=fs,dc=physik,dc=uni-kl,dc=de".'])
def test_get_server_timeout(self):
"""test the get_server_timeout function"""
......@@ -320,10 +346,13 @@ class GetFuncTest(unittest.TestCase):
time.localtime = lambda: (2001, 1, 1)
esme.input = lambda x: ''
self.assertEqual(esme.get_date(), ('01.01.2001', '2001', '01', '01'))
self.assertEqual(esme.get_date(True), ('01.01.2000', '2000', '01', '01'))
self.assertEqual(esme.get_date(True),
('01.01.2000', '2000', '01', '01'))
esme.input = lambda x: '01.01.2002'
self.assertEqual(esme.get_date(), ('01.01.2002', '2002', '01', '01'))
self.assertEqual(esme.get_date(True), ('01.01.2002', '2002', '01', '01'))
self.assertEqual(esme.get_date(),
('01.01.2002', '2002', '01', '01'))
self.assertEqual(esme.get_date(True),
('01.01.2002', '2002', '01', '01'))
self.assertEqual(self.info, [])
self.assertEqual(self.warning, [])
......@@ -346,5 +375,6 @@ class GetFuncTest(unittest.TestCase):
os.rmdir("/tmp/python3-esme-testing/share")
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