Files
match-guide-track-default/tests/test_db_smoke.py
chenfuqiang 7c1f40b0e6
All checks were successful
技能自动化发布 / release (push) Successful in 6s
feat: 申报赛道推荐助手首版 v1.0.1(match-guide-track-default)
2026-09-13 15:50:33 +08:00

43 lines
1.4 KiB
Python
Raw Permalink 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 = {"teacher_profiles", "guide_tracks", "match_reports"}
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()