[Refactor] Move test fixtures to conftest.py
…so they get automatically loaded
This commit is contained in:
parent
1e1e085ba4
commit
bc67e692e0
62
tests/conftest.py
Normal file
62
tests/conftest.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# Calendar.social
|
||||||
|
# Copyright (C) 2018 Gergely Polonkai
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
"""
|
||||||
|
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from helpers import configure_app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def client():
|
||||||
|
"""Fixture that provides a Flask test client
|
||||||
|
"""
|
||||||
|
|
||||||
|
from calsocial import app
|
||||||
|
from calsocial.models import db
|
||||||
|
|
||||||
|
configure_app()
|
||||||
|
client = app.test_client()
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
|
yield client
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
db.drop_all()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def database():
|
||||||
|
"""Fixture to provide all database tables in an active application context
|
||||||
|
"""
|
||||||
|
|
||||||
|
from calsocial import app
|
||||||
|
from calsocial.models import db
|
||||||
|
|
||||||
|
configure_app()
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
|
yield db
|
||||||
|
|
||||||
|
db.drop_all()
|
@ -14,13 +14,11 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# 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
|
from contextlib import contextmanager
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import calsocial
|
import calsocial
|
||||||
from calsocial.models import db
|
from calsocial.models import db
|
||||||
|
|
||||||
@ -34,22 +32,6 @@ def configure_app():
|
|||||||
calsocial.app.config['WTF_CSRF_ENABLED'] = False
|
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):
|
def login(client, username, password, no_redirect=False):
|
||||||
"""Login with the specified username and password
|
"""Login with the specified username and password
|
||||||
"""
|
"""
|
||||||
@ -59,21 +41,6 @@ def login(client, username, password, no_redirect=False):
|
|||||||
follow_redirects=not no_redirect)
|
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
|
@contextmanager
|
||||||
def alter_config(app, **kwargs):
|
def alter_config(app, **kwargs):
|
||||||
saved = {}
|
saved = {}
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
"""General tests for Calendar.social
|
"""General tests for Calendar.social
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from helpers import client
|
|
||||||
|
|
||||||
|
|
||||||
def test_index_no_login(client):
|
def test_index_no_login(client):
|
||||||
"""Test the main page without logging in
|
"""Test the main page without logging in
|
||||||
"""
|
"""
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
import calsocial
|
import calsocial
|
||||||
from calsocial.models import db, Notification, NotificationAction, Profile, User, UserFollow
|
from calsocial.models import db, Notification, NotificationAction, Profile, User, UserFollow
|
||||||
|
|
||||||
from helpers import client, database, login
|
from helpers import login
|
||||||
|
|
||||||
|
|
||||||
def test_profile_follow(database):
|
def test_profile_follow(database):
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
import calsocial
|
import calsocial
|
||||||
from calsocial.models import db, User
|
from calsocial.models import db, User
|
||||||
|
|
||||||
from helpers import client, login
|
from helpers import login
|
||||||
|
|
||||||
|
|
||||||
def test_login_invalid_user(client):
|
def test_login_invalid_user(client):
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
import calsocial
|
import calsocial
|
||||||
from calsocial.models import db, User
|
from calsocial.models import db, User
|
||||||
|
|
||||||
from helpers import alter_config, client
|
from helpers import alter_config
|
||||||
|
|
||||||
|
|
||||||
def test_register_page(client):
|
def test_register_page(client):
|
||||||
|
Loading…
Reference in New Issue
Block a user