Files
verify-promotion-metric-def…/tests/test_db_smoke.py
chenfuqiang 04026d0372
All checks were successful
技能自动化发布 / release (push) Successful in 7s
feat: 职称评审核验助手首版 v1.0.1(verify-promotion-metric-default)
2026-09-13 16:05:20 +08:00

43 lines
1.4 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 -*-
"""init_db:幂等创建元数据表与本技能业务表。"""
from __future__ import annotations
import unittest
from _support import IsolatedDataRoot
_BUSINESS_TABLES = {"threshold_rules", "verify_cases"}
class TestDbSmoke(unittest.TestCase):
def test_init_db_idempotent_metadata_only(self) -> None:
with IsolatedDataRoot():
from db.connection import get_conn, init_db
from db.display_metadata import METADATA_TABLES, iter_user_tables
init_db()
init_db()
conn = get_conn()
try:
cur = conn.cursor()
cur.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"
)
tables = {str(row[0]) for row in cur.fetchall()}
self.assertIn("_jiangchang_tables", tables)
self.assertIn("_jiangchang_columns", tables)
self.assertNotIn("task_logs", tables)
self.assertEqual(
sorted(iter_user_tables(cur)),
sorted(_BUSINESS_TABLES),
)
leftover = tables - METADATA_TABLES - _BUSINESS_TABLES
self.assertEqual(leftover, set())
finally:
conn.close()
if __name__ == "__main__":
unittest.main()