from control_plane.db import Database, row_to_dict def test_schema_created_and_roundtrips(tmp_path): db = Database(db_path=tmp_path / "gateway.db") db.execute( "INSERT INTO accounts (id, email, created_at, registration_token_hash, " "account_token_hash, box_limit, route_limit_per_box) " "VALUES ('acc1', 'a@example.com', '2026-01-01T00:00:00', 'h1', 'h2', 5, 5)" ) row = db.query_one("SELECT * FROM accounts WHERE id = ?", ("acc1",)) assert row["email"] == "a@example.com" all_rows = db.query_all("SELECT id FROM accounts") assert [r["id"] for r in all_rows] == ["acc1"] def test_row_to_dict_converts_row(tmp_path): db = Database(db_path=tmp_path / "gateway.db") db.execute( "INSERT INTO accounts (id, email, created_at, registration_token_hash, " "account_token_hash, box_limit, route_limit_per_box) " "VALUES ('acc1', 'a@example.com', '2026-01-01T00:00:00', 'h1', 'h2', 5, 5)" ) row = db.query_one("SELECT * FROM accounts WHERE id = ?", ("acc1",)) as_dict = row_to_dict(row) assert as_dict["id"] == "acc1" assert as_dict["email"] == "a@example.com" def test_row_to_dict_none(): assert row_to_dict(None) is None