kin: BATON-FIX-012-debugger

This commit is contained in:
Gros Frumos 2026-03-21 09:26:57 +02:00
parent e21bcb1eb4
commit 2f6a84f08b
3 changed files with 53 additions and 32 deletions

View file

@ -29,6 +29,14 @@ import pytest
from backend import config, db
# Valid UUID v4 constants — db-layer tests bypass Pydantic but use canonical UUIDs
_UUID_DB_1 = "d0000001-0000-4000-8000-000000000001"
_UUID_DB_2 = "d0000002-0000-4000-8000-000000000002"
_UUID_DB_3 = "d0000003-0000-4000-8000-000000000003"
_UUID_DB_4 = "d0000004-0000-4000-8000-000000000004"
_UUID_DB_5 = "d0000005-0000-4000-8000-000000000005"
_UUID_DB_6 = "d0000006-0000-4000-8000-000000000006"
def _tmpdb():
"""Return a fresh temp-file path and set config.DB_PATH."""
@ -128,10 +136,10 @@ async def test_register_user_returns_id():
path = _tmpdb()
try:
await db.init_db()
result = await db.register_user(uuid="uuid-001", name="Alice")
result = await db.register_user(uuid=_UUID_DB_1, name="Alice")
assert isinstance(result["user_id"], int)
assert result["user_id"] > 0
assert result["uuid"] == "uuid-001"
assert result["uuid"] == _UUID_DB_1
finally:
_cleanup(path)
@ -142,8 +150,8 @@ async def test_register_user_idempotent():
path = _tmpdb()
try:
await db.init_db()
r1 = await db.register_user(uuid="uuid-002", name="Bob")
r2 = await db.register_user(uuid="uuid-002", name="Bob")
r1 = await db.register_user(uuid=_UUID_DB_2, name="Bob")
r2 = await db.register_user(uuid=_UUID_DB_2, name="Bob")
assert r1["user_id"] == r2["user_id"]
finally:
_cleanup(path)
@ -159,8 +167,8 @@ async def test_get_user_name_returns_name():
path = _tmpdb()
try:
await db.init_db()
await db.register_user(uuid="uuid-003", name="Charlie")
name = await db.get_user_name("uuid-003")
await db.register_user(uuid=_UUID_DB_3, name="Charlie")
name = await db.get_user_name(_UUID_DB_3)
assert name == "Charlie"
finally:
_cleanup(path)
@ -188,9 +196,9 @@ async def test_save_signal_returns_id():
path = _tmpdb()
try:
await db.init_db()
await db.register_user(uuid="uuid-004", name="Dana")
await db.register_user(uuid=_UUID_DB_4, name="Dana")
signal_id = await db.save_signal(
user_uuid="uuid-004",
user_uuid=_UUID_DB_4,
timestamp=1742478000000,
lat=55.7558,
lon=37.6173,
@ -208,9 +216,9 @@ async def test_save_signal_without_geo():
path = _tmpdb()
try:
await db.init_db()
await db.register_user(uuid="uuid-005", name="Eve")
await db.register_user(uuid=_UUID_DB_5, name="Eve")
signal_id = await db.save_signal(
user_uuid="uuid-005",
user_uuid=_UUID_DB_5,
timestamp=1742478000000,
lat=None,
lon=None,
@ -239,9 +247,9 @@ async def test_save_signal_increments_id():
path = _tmpdb()
try:
await db.init_db()
await db.register_user(uuid="uuid-006", name="Frank")
id1 = await db.save_signal("uuid-006", 1742478000001, None, None, None)
id2 = await db.save_signal("uuid-006", 1742478000002, None, None, None)
await db.register_user(uuid=_UUID_DB_6, name="Frank")
id1 = await db.save_signal(_UUID_DB_6, 1742478000001, None, None, None)
id2 = await db.save_signal(_UUID_DB_6, 1742478000002, None, None, None)
assert id2 > id1
finally:
_cleanup(path)