73 lines
3.0 KiB
Python
73 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from app import repository
|
|
from app.domain import Account, Payment, Teacher
|
|
|
|
|
|
def assert_equal(name: str, actual, expected) -> None:
|
|
if actual != expected:
|
|
raise AssertionError(f"{name}: got {actual!r}, expected {expected!r}")
|
|
|
|
|
|
def main() -> None:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
repository.SQLITE_DB_PATH = Path(temp_dir) / "xsk_test.db"
|
|
repository.initialize_runtime_database()
|
|
|
|
student = repository.create_student_profile(
|
|
Account("", "甲", [Payment("2026-07-01", 10)], 0, "正常", 2020, "")
|
|
)
|
|
assert_equal("新增学生", student["account"]["student"], "甲")
|
|
|
|
teacher = repository.create_teacher(Teacher("", "王老师", "", ["英语"], "在岗", ""))
|
|
assert_equal("新增教师", teacher["teacher"]["name"], "王老师")
|
|
|
|
record = repository.register_class_record_lines(
|
|
line="2026.07.06-星期一-10:00-11:00-甲-1小时0分-王老师-英语"
|
|
)
|
|
assert_equal("登记上课", record["registered"], 1)
|
|
|
|
repository.register_payment_lines(line="甲-2026-07-02:2")
|
|
students = repository.students_payload()
|
|
assert_equal("学生数量", students["count"], 1)
|
|
assert_equal("余额重算", students["students"][0]["remaining"], 11)
|
|
|
|
queried = repository.query_public_records("甲7月英语")
|
|
assert_equal("查询记录", queried["total_records"], 1)
|
|
record_id = queried["records"][0]["record_id"]
|
|
|
|
correction = repository.submit_public_correction_tasks([{"record_id": record_id, "time": "11:00-12:00"}])
|
|
approved = repository.approve_admin_task(int(correction["items"][0]["id"]))
|
|
assert_equal("批准纠错", approved["task"]["status"], "approved")
|
|
assert_equal("纠错生效", repository.query_public_records("甲7月英语")["records"][0]["time"], "11:00-12:00")
|
|
|
|
supplement = repository.supplement_course_summary(
|
|
repository.query_public_records("甲7月英语")["records"][0]["record_id"],
|
|
"课堂表现很好",
|
|
)
|
|
assert_equal("补充小结", supplement["status"], "saved")
|
|
summaries = repository.query_course_summaries(q="课堂表现")
|
|
assert_equal("小结查询", summaries["count"], 1)
|
|
summary_id = summaries["items"][0]["id"]
|
|
repository.update_course_summary_body(summary_id, "更新后的课堂表现")
|
|
assert_equal("小结正文更新", repository.query_course_summaries(q="更新后")["count"], 1)
|
|
|
|
latest = repository.list_operation_logs()["items"][0]
|
|
rollback = repository.rollback_operation_log(str(latest["id"]))
|
|
assert_equal("撤回模式", rollback["rollback_mode"], "sqlite_snapshot")
|
|
assert_equal("撤回日志", repository.list_operation_logs()["items"][0]["operation"], "撤回操作")
|
|
|
|
print("db smoke test passed")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|