新增完善测试模板
This commit is contained in:
41
tests/test_db_smoke.py
Normal file
41
tests/test_db_smoke.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""publish_logs 表:init 幂等、写入与查询(全程隔离数据目录)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from _support import IsolatedDataRoot
|
||||
|
||||
|
||||
class TestDbSmoke(unittest.TestCase):
|
||||
def test_init_db_idempotent_and_crud_smoke(self) -> None:
|
||||
with IsolatedDataRoot():
|
||||
from db.connection import init_db
|
||||
from db import publish_logs_repository as plr
|
||||
|
||||
init_db()
|
||||
init_db()
|
||||
|
||||
new_id = plr.save_publish_log(
|
||||
account_id="acc-1",
|
||||
article_id=42,
|
||||
article_title="t",
|
||||
status="ok",
|
||||
error_msg=None,
|
||||
)
|
||||
self.assertIsInstance(new_id, int)
|
||||
self.assertGreater(new_id, 0)
|
||||
|
||||
rows = plr.list_publish_logs(limit=10)
|
||||
self.assertTrue(any(r[0] == new_id for r in rows))
|
||||
|
||||
row = plr.get_publish_log_by_id(new_id)
|
||||
self.assertIsNotNone(row)
|
||||
self.assertEqual(int(row[0]), new_id)
|
||||
|
||||
missing = plr.get_publish_log_by_id(999_999)
|
||||
self.assertIsNone(missing)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user