From e769aed10e1899e739dcb149bc931fcd6b8bf55d Mon Sep 17 00:00:00 2001 From: kakwa Date: Wed, 20 May 2015 14:46:29 +0200 Subject: [PATCH] adding unit tests for exception while loading module --- tests/test_LdapCherry.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_LdapCherry.py b/tests/test_LdapCherry.py index b0235ac..81260ee 100644 --- a/tests/test_LdapCherry.py +++ b/tests/test_LdapCherry.py @@ -44,6 +44,9 @@ def loadconf(configfile, instance): cherrypy.config.update(configfile) instance.reload(app.config) +class BadModule(): + pass + class TestError(object): def testNominal(self): @@ -51,6 +54,30 @@ class TestError(object): loadconf('./tests/cfg/ldapcherry.ini', app) return True + def testMissingBackendModule(self): + app = LdapCherry() + loadconf('./tests/cfg/ldapcherry.ini', app) + cfg = {'backends': {'ldap.module': 'dontexists'}} + try: + app._init_backends(cfg) + except BackendModuleLoadingFail: + return + else: + raise AssertionError("expected an exception") + + def testInitgBackendModuleFail(self): + app = LdapCherry() + loadconf('./tests/cfg/ldapcherry.ini', app) + cfg = {'backends': {'ldap.module': 'ldapcherry.backend'}} + try: + app._init_backends(cfg) + except BackendModuleInitFail: + return + else: + raise AssertionError("expected an exception") + + + def testLog(self): app = LdapCherry() cfg = { 'global' : {}}