From bfd1969ab3558d39e5a4d45f2b71fe8f27850226 Mon Sep 17 00:00:00 2001 From: kakwa Date: Mon, 18 May 2015 23:59:54 +0200 Subject: [PATCH] fix log_level + unit tests * python logging doesn't support the 7 log levels of syslog, compensate it * adding unit test on log level --- ldapcherry/__init__.py | 6 +++--- tests/test_LdapCherry.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index e38ee2d..c12c08a 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -185,7 +185,7 @@ class LdapCherry(object): if level == 'debug': return logging.DEBUG elif level == 'notice': - return logging.NOTICE + return logging.INFO elif level == 'info': return logging.INFO elif level == 'warning' or level == 'warn': @@ -195,9 +195,9 @@ class LdapCherry(object): elif level == 'critical' or level == 'crit': return logging.CRITICAL elif level == 'alert': - return logging.ALERT + return logging.CRITICAL elif level == 'emergency' or level == 'emerg': - return logging.EMERGENCY + return logging.CRITICAL else: return logging.INFO diff --git a/tests/test_LdapCherry.py b/tests/test_LdapCherry.py index 47d0d63..857ca24 100644 --- a/tests/test_LdapCherry.py +++ b/tests/test_LdapCherry.py @@ -13,6 +13,7 @@ from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError import cherrypy from cherrypy.process import plugins, servers from cherrypy import Application +import logging # monkey patching cherrypy to disable config interpolation def new_as_dict(self, raw=True, vars=None): @@ -49,3 +50,16 @@ class TestError(object): loadconf('./tests/cfg/ldapcherry.ini', app) return True + def testLogger(self): + app = LdapCherry() + loadconf('./tests/cfg/ldapcherry.ini', app) + assert app._get_loglevel('debug') is logging.DEBUG and \ + app._get_loglevel('notice') is logging.INFO and \ + app._get_loglevel('info') is logging.INFO and \ + app._get_loglevel('warning') is logging.WARNING and \ + app._get_loglevel('err') is logging.ERROR and \ + app._get_loglevel('critical') is logging.CRITICAL and \ + app._get_loglevel('alert') is logging.CRITICAL and \ + app._get_loglevel('emergency') is logging.CRITICAL and \ + app._get_loglevel('notalevel') is logging.INFO +