2022-05-15 21:20:05 +02:00
|
|
|
from typing import Generator
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
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()
|
|
|
|
def test_client(test_app: Flask) -> FlaskClient:
|
|
|
|
return test_app.test_client()
|