Files
skill-template/tests/test_db_smoke.py
2026-05-03 17:52:52 +08:00

42 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- 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()