Automation testing implementation for a digital textbook downloader, addressing the lack of testing, CI, and pyproject configuration.
Raw Developer Origin & Technical Request
GitHub Issue
Sep 10, 2026
## 背景
项目目前**没有任何测试、CI 配置或 pyproject**。核心逻辑集中在 `pep_core.py`(约 700 行),其中大部分逻辑可以**离线测试**——仓库自带 360KB 真实目录数据 `pep_catalog.json`,而 `PepCatalog.fetch_and_decrypt_all()` 优先读取本地缓存,不依赖网络,非常适合低成本引入自动化测试。
## 分层测试计划
| 层 | 测试对象 | 测试方式 |
|---|---|---|
| 纯函数 | `normalize_xd`、`sort_xd_key` / `sort_xk_key` / `sort_nj_key`、`map_book_xd`、`sanitize_filename` | 表驱动测试,零 mock |
| 目录检索 | `PepCatalog.filter_books`、`PepCatalog.get_structure` | monkeypatch `LOCAL_CACHE` 指向仓库自带的 `pep_catalog.json` |
| 解密链路 | JS 密文正则提取 → AES-128-CBC → PKCS7 unpad → JSON 解析 | 自造密文 round-trip + mock `urlopen`。**最值得测**——网站前端一改版,最先崩的就是这段 |
| 下载器 | `PepDownloader.download_book` 的 `skip_if_exists` 快路径(预置 >50KB 假 PDF,浏览器尚未启动即 return) | 离线可测 |
| WebUI | `/api/structure`、`/api/books`、`/api/status` | FastAPI TestClient |
| 不做单测 | `_solve_slider` 滑块破解、Playwright 抓页循环 | 真实 WAF 对抗行为,留给手动/集成测试 |
## 审读代码时顺带发现的两个小问题
1. **`cli.py` 交互模式空值崩溃**:`b.get("nj", "通用").strip()`——当 `nj` 键存在但值为 `null` 时,`.get()` 返回 `None`,调用 `.strip()` 会抛 `AttributeError`。命令行参数模式写的是 `or "通用"` 没有这个坑,交互模式建议对齐写法。
2. **`download_all.py` 的 `is_match_xd` 无法单测**:该函数嵌在 `run_download_all()` 函数体内,建议提升为模块级函数(学段匹配逻辑本身也值得表驱动测试)。
## 建议技术栈
- `pytest`(dev 依赖)
- `httpx`(FastAPI `TestClient` 需要)
- 可选:GitHub Actions workflow,push 时运行 pytest
## 收益
- 网站改版导致解密/正则失效时,CI 能第一时间报警,而不是等用户报障;
- 排序/筛选规范(学段、学科、年级顺序)固化成回归测试,后续重构有安全网;
- 修复上面两个小 bug 时可以顺手补上对应回归用例。
Developer Debate & Comments
No active discussions extracted for this entry yet.
Frequently Asked Questions
Market intelligence mapped to Automation testing implementation for a digital textbook downloader, addressing the lack of testing, CI, and pyproject configuration..
How is Automation testing implementation for a digital textbook downloader, addressing the lack of testing, CI, and pyproject configuration. positioned in the market?
What are the foundational technologies related to Automation testing implementation for a digital textbook downloader, addressing the lack of testing, CI, and pyproject configuration.?
Engagement Signals
Cross-Market Term Frequency
Quantifies the cross-market adoption of foundational terms like Playwright and pyproject by tracking occurrence frequency across active SaaS architectures and enterprise developer debates.
SaaS Metrics