diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..bd2b38a --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +import pytest +import pytest_asyncio +from typing import Generator +from fastapi.testclient import TestClient + +from app.main import app +from app.database import Base +from app.database import async_engine +from app.database import async_session +from app.database import engine +from app.database import SessionLocal + +from sqlalchemy import orm + + +_Session = orm.scoped_session(SessionLocal) + +@pytest.fixture +def db(): + Base.metadata.create_all(bind=engine) + with _Session() as db_session: + try: + yield db_session + finally: + db_session.close() + Base.metadata.drop_all(bind=engine) + + +@pytest.fixture +def client(db) -> Generator: + with TestClient(app) as c: + yield c diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..dd3ad30 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +from fastapi.testclient import TestClient +from sqlalchemy.orm import Session + + + +def test_index__html(client: TestClient): + response = client.get("/") + assert response.status_code == 200 + # assert response.headers["content-type"].startswith("text/html")