2024-02-25 19:39:33 +01:00
|
|
|
from collections.abc import Generator
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
2020-04-20 19:03:13 +02:00
|
|
|
|
2019-02-09 19:42:36 +04:00
|
|
|
import pytest
|
2020-04-20 20:31:29 +02:00
|
|
|
from fastapi.testclient import TestClient
|
2024-03-01 12:26:05 -05:00
|
|
|
from sqlmodel import Session, delete
|
2019-02-09 19:42:36 +04:00
|
|
|
|
2020-04-16 23:56:10 -06:00
|
|
|
from app.core.config import settings
|
2024-03-02 05:01:59 -05:00
|
|
|
from app.core.db import engine, init_db
|
2020-04-20 20:31:29 +02:00
|
|
|
from app.main import app
|
2024-03-01 12:26:05 -05:00
|
|
|
from app.models import Item, User
|
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
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
2020-04-20 19:03:13 +02:00
|
|
|
|
|
|
|
|
2024-03-01 12:26:05 -05:00
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
2024-03-10 14:47:21 -05:00
|
|
|
def db() -> Generator[Session, None, None]:
|
2023-11-25 00:08:22 +01:00
|
|
|
with Session(engine) as session:
|
2024-03-01 12:26:05 -05:00
|
|
|
init_db(session)
|
2023-11-25 00:08:22 +01:00
|
|
|
yield session
|
2024-03-01 12:26:05 -05:00
|
|
|
statement = delete(Item)
|
|
|
|
session.execute(statement)
|
|
|
|
statement = delete(User)
|
|
|
|
session.execute(statement)
|
|
|
|
session.commit()
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
2024-03-10 14:47:21 -05:00
|
|
|
def client() -> Generator[TestClient, None, None]:
|
2020-04-20 20:31:29 +02:00
|
|
|
with TestClient(app) as c:
|
|
|
|
yield c
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
)
|