import pytest
from typing import Generator, Dict
from sqlmodel import Session, SQLModel, create_engine
from sqlmodel.pool import StaticPool
from fastapi.testclient import TestClient
from app.models import *
from app.main import app
from app.api.deps import get_db


@pytest.fixture(name="session")
def session_fixture() -> Generator:
    engine = create_engine(
        "sqlite://",
        echo=False,
        connect_args={"check_same_thread": False},
        poolclass=StaticPool,
    )
    SQLModel.metadata.create_all(engine)
    with Session(engine) as session:
        yield session


@pytest.fixture(name="client")
def client_fixture(session: Session):
    def get_db_override():
        return session

    app.dependency_overrides[get_db] = get_db_override
    client = TestClient(app)
    yield client
    app.dependency_overrides.clear()


@pytest.fixture(scope="module")
def random_product() -> Dict[str, str]:
    return {
        "id": 1,
        "name": "<NAME>",
        "price": 80,
    }

sqlmodel.create_engine fastapi.testclient.TestClient app.main.app.dependency_overrides.clear pytest.fixture sqlmodel.Session sqlmodel.SQLModel.metadata.create_all
[((267, 297), 'pytest.fixture', 'pytest.fixture', ([], {'name': '"""session"""'}), "(name='session')\n", (281, 297), False, 'import pytest\n'), ((593, 622), 'pytest.fixture', 'pytest.fixture', ([], {'name': '"""client"""'}), "(name='client')\n", (607, 622), False, 'import pytest\n'), ((853, 883), 'pytest.fixture', 'pytest.fixture', ([], {'scope': '"""module"""'}), "(scope='module')\n", (867, 883), False, 'import pytest\n'), ((347, 455), 'sqlmodel.create_engine', 'create_engine', (['"""sqlite://"""'], {'echo': '(False)', 'connect_args': "{'check_same_thread': False}", 'poolclass': 'StaticPool'}), "('sqlite://', echo=False, connect_args={'check_same_thread': \n    False}, poolclass=StaticPool)\n", (360, 455), False, 'from sqlmodel import Session, SQLModel, create_engine\n'), ((494, 530), 'sqlmodel.SQLModel.metadata.create_all', 'SQLModel.metadata.create_all', (['engine'], {}), '(engine)\n', (522, 530), False, 'from sqlmodel import Session, SQLModel, create_engine\n'), ((780, 795), 'fastapi.testclient.TestClient', 'TestClient', (['app'], {}), '(app)\n', (790, 795), False, 'from fastapi.testclient import TestClient\n'), ((817, 849), 'app.main.app.dependency_overrides.clear', 'app.dependency_overrides.clear', ([], {}), '()\n', (847, 849), False, 'from app.main import app\n'), ((540, 555), 'sqlmodel.Session', 'Session', (['engine'], {}), '(engine)\n', (547, 555), False, 'from sqlmodel import Session, SQLModel, create_engine\n')]