diff --git a/tests/helpers.py b/tests/helpers.py index 474fba7..971a4bd 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -17,6 +17,8 @@ """Helper functions and fixtures for testing """ +from contextlib import contextmanager + import pytest import calsocial @@ -70,3 +72,22 @@ def database(): yield db db.drop_all() + + +@contextmanager +def alter_config(app, **kwargs): + saved = {} + + for key, value in kwargs.items(): + if key in app.config: + saved[key] = app.config[key] + + app.config[key] = value + + yield + + for key, value in kwargs.items(): + if key in saved: + app.config[key] = saved[key] + else: + del app.config[key]