fix some tests

This commit is contained in:
dni ⚡
2024-10-10 09:08:10 +02:00
parent f06b29dd82
commit 382154b04a
6 changed files with 114 additions and 103 deletions
+32 -17
View File
@@ -8,48 +8,63 @@ from lnbits.db import (
model_to_dict,
update_query,
)
from tests.helpers import DbTestModel, DbTestModel2
from tests.helpers import DbTestModel, DbTestModel2, DbTestModel3
test_data = DbTestModel2(
test_data = DbTestModel3(
id=1,
label="test",
description="mydesc",
child=DbTestModel(id=2, name="myname", value="myvalue"),
child=DbTestModel2(
id=2,
label="test",
description="mydesc",
child=DbTestModel(id=3, name="myname", value="myvalue"),
),
active=True,
)
@pytest.mark.asyncio
async def test_helpers_insert_query():
q = insert_query("test_helpers_query", test_data)
assert (
q == "INSERT INTO test_helpers_query (id, label, description, child) "
"VALUES (:id, :label, :description, :child)"
assert q == (
"INSERT INTO test_helpers_query (id, child, active) "
"VALUES (:id, :child, :active)"
)
@pytest.mark.asyncio
async def test_helpers_update_query():
q = update_query("test_helpers_query", test_data)
assert (
q == "UPDATE test_helpers_query "
"SET id = :id, label = :label, description = :description, child = :child "
"WHERE id = :id"
assert q == (
"UPDATE test_helpers_query "
"SET id = :id, child = :child, active = :active WHERE id = :id"
)
child_dict = json.dumps({"id": 2, "name": "myname", "value": "myvalue"})
test_dict = {"id": 1, "label": "test", "description": "mydesc", "child": child_dict}
child_json = json.dumps(
{
"id": 2,
"label": "test",
"description": "mydesc",
"child": {"id": 3, "name": "myname", "value": "myvalue"},
}
)
test_dict = {"id": 1, "child": child_json, "active": True}
@pytest.mark.asyncio
async def test_helpers_model_to_dict():
d = model_to_dict(test_data)
assert d.get("id") == test_data.id
assert d.get("active") == test_data.active
assert d.get("child") == child_json
assert d == test_dict
@pytest.mark.asyncio
async def test_helpers_dict_to_model():
m = dict_to_model(test_dict, DbTestModel2)
m = dict_to_model(test_dict, DbTestModel3)
assert m == test_data
assert type(m) is DbTestModel2
assert type(m.child) is DbTestModel
assert type(m) is DbTestModel3
assert m.active is True
assert type(m.child) is DbTestModel2
assert type(m.child.child) is DbTestModel