Mercurial > p > roundup > code
diff test/test_redis_session.py @ 6823:fe0091279f50
Refactor session db logging and key generation for sessions/otks
While I was working on the redis sessiondb stuff, I noticed that
log_wanrning, get_logger ... was duplicated. Also there was code to
generate a unique key for otks that was duplicated.
Changes:
creating new sessions_common.py and SessionsCommon class to provide
methods:
log_warning, log_info, log_debug, get_logger, getUniqueKey
getUniqueKey method is closer to the method used to make
session keys in client.py.
sessions_common.py now report when random_.py chooses a weak
random number generator. Removed same from rest.py.
get_logger reconciles all logging under
roundup.hyperdb.backends.<name of BasicDatabase class>
some backends used to log to root logger.
have BasicDatabase in other sessions_*.py modules inherit from
SessionCommon.
change logging to use log_* methods.
In addition:
remove unused imports reported by flake8 and other formatting
changes
modify actions.py, rest.py, templating.py to use getUniqueKey
method.
add tests for new methods
test_redis_session.py
swap out ModuleNotFoundError for ImportError to prevent crash in
python2 when redis is not present.
allow injection of username:password or just password into redis
connection URL. set pytest_redis_pw envirnment variable to password
or user:password when running test.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 07 Aug 2022 01:51:11 -0400 |
| parents | 35f0952f4bc5 |
| children | 75a5946cf897 |
line wrap: on
line diff
--- a/test/test_redis_session.py Sun Aug 07 01:26:30 2022 -0400 +++ b/test/test_redis_session.py Sun Aug 07 01:51:11 2022 -0400 @@ -23,7 +23,7 @@ try: from roundup.backends.sessions_redis import Sessions, OneTimeKeys skip_redis = lambda func, *args, **kwargs: func -except ModuleNotFoundError as e: +except ImportError as e: from .pytest_patcher import mark_class skip_redis = mark_class(pytest.mark.skip( reason='Skipping redis tests: redis module not available')) @@ -37,9 +37,22 @@ def setUp(self): SessionTest.setUp(self) + import os + if 'pytest_redis_pw' in os.environ: + pw = os.environ['pytest_redis_pw'] + if ':' in pw: + # pw is user:password + pw = "%s@" % pw + else: + # pw is just password + pw = ":%s@" % pw + else: + pw = "" + # redefine the session db's as redis. self.db.config.SESSIONDB_BACKEND = "redis" - self.db.config.SESSIONDB_REDIS_URL = 'redis://localhost:6379/15?health_check_interval=2' + self.db.config.SESSIONDB_REDIS_URL = \ + 'redis://%slocalhost:6379/15?health_check_interval=2' % pw self.db.Session = None self.db.Otk = None self.sessions = self.db.getSessionManager()
