open-law/tests/conftest.py

57 lines
1014 B
Python
Raw Normal View History

2023-04-20 13:10:16 +00:00
import pytest
from flask import Flask
from flask.testing import FlaskClient
from app import create_app, db
from app import models as m
2023-04-20 13:42:47 +00:00
from tests.utils import create
2023-04-20 13:10:16 +00:00
@pytest.fixture()
def app():
app = create_app("testing")
app.config.update(
{
"TESTING": True,
}
)
yield app
@pytest.fixture()
def client(app: Flask):
with app.test_client() as client:
app_ctx = app.app_context()
app_ctx.push()
db.drop_all()
db.create_all()
2023-04-20 13:42:47 +00:00
create()
2023-04-20 13:10:16 +00:00
yield client
db.session.remove()
db.drop_all()
app_ctx.pop()
@pytest.fixture()
def runner(app, client):
from app import commands
commands.init(app)
yield app.test_cli_runner()
@pytest.fixture
def populate(client: FlaskClient):
NUM_TEST_USERS = 100
for i in range(NUM_TEST_USERS):
m.User(
username=f"user{i+1}",
password="password",
).save(False)
db.session.commit()
yield client