2022-05-15 21:20:05 +02:00
|
|
|
from typing import Generator
|
|
|
|
|
|
|
|
import pytest
|
2023-01-06 22:35:47 +01:00
|
|
|
from apiflask import APIFlask
|
2022-05-15 21:20:05 +02:00
|
|
|
from flask import Flask
|
|
|
|
from flask.testing import FlaskClient
|
2023-01-04 22:51:58 +01:00
|
|
|
from flask.ctx import AppContext
|
2022-05-15 21:20:05 +02:00
|
|
|
|
2023-01-04 22:51:58 +01:00
|
|
|
from ..app import create_app
|
|
|
|
from ..app.dependencies import db
|
2022-05-15 21:20:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
2023-01-04 22:51:58 +01:00
|
|
|
def test_app() -> Generator[Flask, None, None]:
|
|
|
|
yield create_app("testing")
|
2022-05-15 21:20:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
2023-01-04 22:51:58 +01:00
|
|
|
def test_app_ctx_with_db(test_app) -> Generator[AppContext, None, None]:
|
|
|
|
with test_app.app_context() as ctx:
|
|
|
|
db.create_all()
|
|
|
|
yield ctx
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
2023-01-06 22:35:47 +01:00
|
|
|
def test_client() -> FlaskClient:
|
|
|
|
app = create_app("testing")
|
|
|
|
with app.app_context():
|
|
|
|
db.create_all()
|
|
|
|
return app.test_client()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def test_app_with_context() -> Generator[APIFlask, None, None]:
|
|
|
|
app = create_app("testing")
|
|
|
|
with app.app_context():
|
|
|
|
db.create_all()
|
|
|
|
yield app
|