From abfaf85a43239f079953e3a5ea9d85d43879da41 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 16 May 2020 11:57:19 +0200 Subject: [PATCH] tests: verify hooks by propagating exceptions --- tests/conftest.py | 24 ++++++++++++++++++++++++ tests/settings.py | 3 +++ 2 files changed, 27 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 5822a2f..0c0505a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import copy +import time import pytest import django_webtest @@ -130,3 +131,26 @@ def pdf_file(): yield fd.read() +@pytest.fixture(autouse=True) +def redis_client(monkeypatch): + from authentic2_cut.apps import AppConfig + + class RedisClientMock(object): + def __init__(self): + self.contents = {} + self.timeouts = {} + + def expire(self, key, delta): + if delta: + self.timeouts[key] = time.time() + delta + elif key in self.expire: + del self.timeouts[key] + + def incr(self, key): + self.contents.setdefault(key, 0) + self.contents[key] += 1 + + redis_client = RedisClientMock() + monkeypatch.setattr(AppConfig, 'redis_client', redis_client) + yield redis_client + diff --git a/tests/settings.py b/tests/settings.py index 3c81321..3ffb3e4 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -17,3 +17,6 @@ if 'postgres' in DATABASES['default']['ENGINE']: LANGUAGE_CODE = 'en' A2_FC_CLIENT_ID = '' A2_FC_CLIENT_SECRET = '' + +# test hook handlers +A2_HOOKS_PROPAGATE_EXCEPTIONS = True