Add the alter_config context manager for testing
It can temporarily change an app configuration value.
This commit is contained in:
parent
6f186c3a3f
commit
c20b302458
@ -17,6 +17,8 @@
|
|||||||
"""Helper functions and fixtures for testing
|
"""Helper functions and fixtures for testing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import calsocial
|
import calsocial
|
||||||
@ -70,3 +72,22 @@ def database():
|
|||||||
yield db
|
yield db
|
||||||
|
|
||||||
db.drop_all()
|
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]
|
||||||
|
Loading…
Reference in New Issue
Block a user