Add the alter_config context manager for testing

It can temporarily change an app configuration value.
This commit is contained in:
Gergely Polonkai 2018-07-23 13:21:29 +02:00
parent 6f186c3a3f
commit c20b302458
1 changed files with 21 additions and 0 deletions

View File

@ -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]