Files
fast_api_template/src/backend/app/tests/conftest.py
T

36 lines
947 B
Python
Raw Normal View History

2024-02-25 19:39:33 +01:00
from collections.abc import Generator
import pytest
2020-04-20 20:31:29 +02:00
from fastapi.testclient import TestClient
2024-02-29 15:42:55 -05:00
from sqlmodel import Session
from app.core.config import settings
from app.db.engine import engine
2020-04-20 20:31:29 +02:00
from app.main import app
2020-01-19 13:25:17 +01:00
from app.tests.utils.user import authentication_token_from_email
2020-04-20 20:31:29 +02:00
from app.tests.utils.utils import get_superuser_token_headers
@pytest.fixture(scope="session")
2020-04-20 20:31:29 +02:00
def db() -> Generator:
with Session(engine) as session:
yield session
@pytest.fixture(scope="module")
2020-04-20 20:31:29 +02:00
def client() -> Generator:
with TestClient(app) as c:
yield c
@pytest.fixture(scope="module")
2024-02-25 19:39:33 +01:00
def superuser_token_headers(client: TestClient) -> dict[str, str]:
2020-04-20 20:31:29 +02:00
return get_superuser_token_headers(client)
2020-01-19 13:25:17 +01:00
@pytest.fixture(scope="module")
2024-02-25 19:39:33 +01:00
def normal_user_token_headers(client: TestClient, db: Session) -> dict[str, str]:
2020-04-20 20:31:29 +02:00
return authentication_token_from_email(
client=client, email=settings.EMAIL_TEST_USER, db=db
)