Added tests.

This commit is contained in:
retoor 2025-07-24 04:12:13 +02:00
parent 74bcd5ec71
commit 088035224c

8
ads.py
View File

@ -177,6 +177,8 @@ class AsyncDataSet:
args: Dict[str, Any],
where: Optional[Dict[str, Any]] = None,
) -> str | None:
if not args:
raise ValueError("Nothing to update. Empty dict given.")
args['updated_at'] = str(datetime.now())
affected = await self.update(table, args, where)
if affected:
@ -357,6 +359,7 @@ class TestAsyncDataSet(unittest.IsolatedAsyncioTestCase):
async def test_update(self):
await self.connector.insert("people", {"name": "John Doe", "age": 30})
await asyncio.sleep(2)
await self.connector.update("people", {"age": 31}, {"name": "John Doe"})
rec = await self.connector.get("people", {"name": "John Doe"})
self.assertEqual(rec["age"], 31)
@ -514,12 +517,13 @@ class TestAsyncDataSet(unittest.IsolatedAsyncioTestCase):
self.assertEqual(count, 5)
async def test_column_type_preservation(self):
data = {"name": "Test", "number": 42, "float": 3.14, "bool": True}
data = {"name": "Test", "number": 42, "float": 3.14, "bool": True,"bytes":b"data"}
await self.connector.insert("types", data)
rec = await self.connector.get("types", {"name": "Test"})
self.assertIsInstance(rec["number"], int)
self.assertIsInstance(rec["float"], float)
self.assertIsInstance(rec["bool"], int) # SQLite stores bool as int
self.assertIsInstance(rec["bytes"], bytes) # SQLite stores bool as int
self.assertEqual(rec["bool"], 1)
async def test_empty_update(self):
@ -540,5 +544,7 @@ class TestAsyncDataSet(unittest.IsolatedAsyncioTestCase):
with self.assertRaises(aiosqlite.OperationalError):
await self.connector.insert("invalid table name", {"name": "John"})
if __name__ == "__main__":
unittest.main()