sql first refactor
This commit is contained in:
28
backend/tests/test_db_json_fetch_json.py
Normal file
28
backend/tests/test_db_json_fetch_json.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Smoke: fetch_json toleruje dict z asyncpg (bez reálné DB)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from app.db_json import fetch_json
|
||||
|
||||
|
||||
def test_fetch_json_returns_dict() -> None:
|
||||
async def _run() -> None:
|
||||
conn = AsyncMock()
|
||||
conn.fetchval = AsyncMock(return_value={"a": 1})
|
||||
out = await fetch_json(conn, "select ems.fn_x()", 1)
|
||||
assert out == {"a": 1}
|
||||
|
||||
asyncio.run(_run())
|
||||
|
||||
|
||||
def test_fetch_json_parses_str() -> None:
|
||||
async def _run() -> None:
|
||||
conn = AsyncMock()
|
||||
conn.fetchval = AsyncMock(return_value='{"b": 2}')
|
||||
out = await fetch_json(conn, "select 1")
|
||||
assert out == {"b": 2}
|
||||
|
||||
asyncio.run(_run())
|
||||
Reference in New Issue
Block a user