flaschengeist/tests/conftest.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.1 KiB
Python
Raw Permalink Normal View History

import os
import tempfile
import pytest
from flaschengeist import database
from flaschengeist.app import create_app, install_all
# read in SQL for populating test data
with open(os.path.join(os.path.dirname(__file__), "data.sql"), "r") as f:
_data_sql = []
__sql_command = ""
for line in f.readlines():
if not line.startswith("--"):
line = line.strip("\n")
__sql_command += line.strip("\n")
if __sql_command.endswith(";"):
_data_sql.append(__sql_command)
__sql_command = ""
@pytest.fixture
def app():
db_fd, db_path = tempfile.mkstemp()
2021-11-18 11:54:37 +00:00
app = create_app(
{
"TESTING": True,
"DATABASE": {"file_path": f"/{db_path}"},
"LOGGING": {"level": "DEBUG"},
}
)
with app.app_context():
install_all()
engine = database.db.engine
with engine.connect() as connection:
for statement in _data_sql:
connection.execute(statement)
yield app
os.close(db_fd)
# os.unlink(db_path)
print(db_path)
@pytest.fixture
def client(app):
return app.test_client()