Add end-to-end test framework
This commit is contained in:
11
app/tests/test_homepage.py
Normal file
11
app/tests/test_homepage.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import pytest
|
||||
from app import app
|
||||
from utils import client, recreate_db
|
||||
|
||||
def test_homepage_ok(client):
|
||||
"""Start with a blank database."""
|
||||
|
||||
assert app.config["TESTING"]
|
||||
|
||||
rv = client.get("/")
|
||||
assert b"No packages available" in rv.data
|
||||
29
app/tests/utils.py
Normal file
29
app/tests/utils.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import pytest
|
||||
from app import app
|
||||
from app.models import db, User
|
||||
from app.default_data import populate
|
||||
|
||||
def clear_data(session):
|
||||
meta = db.metadata
|
||||
for table in reversed(meta.sorted_tables):
|
||||
session.execute(f'ALTER TABLE "{table.name}" DISABLE TRIGGER ALL;')
|
||||
session.execute(table.delete())
|
||||
session.execute(f'ALTER TABLE "{table.name}" ENABLE TRIGGER ALL;')
|
||||
#session.execute(table.delete())
|
||||
|
||||
def recreate_db():
|
||||
clear_data(db.session)
|
||||
populate(db.session)
|
||||
db.session.commit()
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
app.config["TESTING"] = True
|
||||
|
||||
recreate_db()
|
||||
assert User.query.count() == 1
|
||||
|
||||
with app.test_client() as client:
|
||||
yield client
|
||||
|
||||
app.config["TESTING"] = False
|
||||
Reference in New Issue
Block a user