[Refactor] Move test fixtures to conftest.py

…so they get automatically loaded
This commit is contained in:
2018-07-25 20:02:28 +02:00
parent 1e1e085ba4
commit bc67e692e0
6 changed files with 66 additions and 40 deletions

View File

@@ -14,13 +14,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Helper functions and fixtures for testing
"""Helper functions for testing
"""
from contextlib import contextmanager
import pytest
import calsocial
from calsocial.models import db
@@ -34,22 +32,6 @@ def configure_app():
calsocial.app.config['WTF_CSRF_ENABLED'] = False
@pytest.fixture
def client():
"""Fixture that provides a Flask test client
"""
configure_app()
client = calsocial.app.test_client()
with calsocial.app.app_context():
db.create_all()
yield client
with calsocial.app.app_context():
db.drop_all()
def login(client, username, password, no_redirect=False):
"""Login with the specified username and password
"""
@@ -59,21 +41,6 @@ def login(client, username, password, no_redirect=False):
follow_redirects=not no_redirect)
@pytest.fixture
def database():
"""Fixture to provide all database tables in an active application context
"""
configure_app()
with calsocial.app.app_context():
db.create_all()
yield db
db.drop_all()
@contextmanager
def alter_config(app, **kwargs):
saved = {}