feat(api+testing): select member by email

- Reorganized folder structure so routes live in the same folder
- Set up pytest fixtures for future use
This commit is contained in:
2024-03-01 20:14:20 -05:00
parent b64030617c
commit 49c83fa287
10 changed files with 72 additions and 14 deletions

28
backend/tests/conftest.py Normal file
View File

@@ -0,0 +1,28 @@
import os
import pytest
from fastapi.testclient import TestClient
from psycopg_pool import AsyncConnectionPool
from src.neo_neo_todo.main import app
@pytest.fixture
async def client():
yield TestClient(app)
@pytest.fixture
async def db_pool():
try:
postgres_db_url = os.environ["TODO_DB_DATABASE_URL"]
except KeyError:
raise KeyError("Can't find postgres DB URL")
pool = AsyncConnectionPool(postgres_db_url, open=False)
await pool.open()
yield pool
await pool.close()

View File

@@ -1,12 +1,7 @@
import pytest
from httpx import AsyncClient
from src.neo_neo_todo.main import app
from fastapi.testclient import TestClient
@pytest.mark.anyio
async def test_ping():
async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.get("/control/ping")
async def test_ping(client: TestClient):
response = client.get("/control/ping")
assert response.status_code == 200
assert response.json() == {"ping": "pong"}

View File

@@ -0,0 +1,7 @@
from src.neo_neo_todo.models.member import select_member_by_email
async def test_model_member(db_pool):
member = await select_member_by_email(db_pool, "member@todo.test")
assert member is not None
assert member.email == "member@todo.test"