2020-04-20 20:31:29 +02:00
|
|
|
from typing import Dict, Generator
|
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
|
2020-04-20 19:03:13 +02:00
|
|
|
from sqlalchemy.orm import Session
|
2019-02-09 19:42:36 +04:00
|
|
|
|
2020-04-16 23:56:10 -06:00
|
|
|
from app.core.config import settings
|
2023-11-25 00:08:22 +01:00
|
|
|
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
|
2020-04-20 19:03:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2020-04-20 20:31:29 +02:00
|
|
|
def db() -> Generator:
|
2023-11-25 00:08:22 +01:00
|
|
|
with Session(engine) as session:
|
|
|
|
|
yield session
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
2020-04-20 20:31:29 +02:00
|
|
|
def client() -> Generator:
|
|
|
|
|
with TestClient(app) as c:
|
|
|
|
|
yield c
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
2020-04-20 20:31:29 +02:00
|
|
|
def superuser_token_headers(client: TestClient) -> Dict[str, str]:
|
|
|
|
|
return get_superuser_token_headers(client)
|
2020-01-19 13:25:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
2020-04-20 20:31:29 +02:00
|
|
|
def normal_user_token_headers(client: TestClient, db: Session) -> Dict[str, str]:
|
|
|
|
|
return authentication_token_from_email(
|
|
|
|
|
client=client, email=settings.EMAIL_TEST_USER, db=db
|
|
|
|
|
)
|