Files
Zhengen 147107501b 补充测试覆盖率 + 新增部署引导命令 bootstrap_deployment
- 新增 apps/blog、apps/solutions、apps/home、apps/api 测试文件,覆盖标签/排序/
  草稿过滤、HomePage.subpage_types 回归测试、page_preview 预览接口
- apps/core/tests.py 新增健康检查端点、发布 webhook 信号、bootstrap_deployment
  命令的测试用例,pytest 用例数从 40 增至 65,全部通过
- 修复 apps/api/urls.py 中 PagePreviewAPIViewSet.get_object() 未捕获
  DoesNotExist 导致 500 而非文档承诺 404 的 bug
- 新增 apps/core/management/commands/bootstrap_deployment.py:部署时按环境变量
  幂等创建首个超级管理员账号并联动初始化 RBAC 权限组,.env.example 补充对应
  环境变量说明
- 新增 OpenSearch + 中文分词本地 PoC 脚手架(docker-compose.opensearch.yml +
  docker/opensearch/Dockerfile),调研结论详见设计文档 §2.10
- 更新设计文档 §2.16 Phase 1 进度清单
2026-08-11 14:47:10 +08:00

54 lines
2.1 KiB
Python

"""apps.home 单元测试:HomePage 页面树结构。
test_home_page_subpage_types_allows_all_top_level_sections 是一条回归测试:
此前 HomePage.subpage_types 曾经只包含 blog.BlogIndexPage,导致 products/cases/
solutions 的 IndexPage 无法通过 Wagtail 管理后台"添加子页面"界面创建(subpage_types/
parent_page_types 只影响后台创建校验,不影响 ORM add_child(),问题一度被脚本化测试掩盖)。
"""
import pytest
from apps.blog.models import BlogIndexPage
from apps.cases.models import CaseStudyIndexPage
from apps.core.models import SimpleContentPage
from apps.home.models import HomePage
from apps.products.models import ProductIndexPage
from apps.solutions.models import SolutionIndexPage
pytestmark = pytest.mark.django_db
def test_home_page_subpage_types_allows_all_top_level_sections():
expected_types = {
"blog.BlogIndexPage",
"products.ProductIndexPage",
"solutions.SolutionIndexPage",
"cases.CaseStudyIndexPage",
"core.SimpleContentPage",
}
assert expected_types.issubset(set(HomePage.subpage_types))
@pytest.mark.parametrize(
"index_model,kwargs",
[
(BlogIndexPage, {"title": "博客", "slug": "blog"}),
(ProductIndexPage, {"title": "产品", "slug": "products"}),
(SolutionIndexPage, {"title": "解决方案", "slug": "solutions"}),
(CaseStudyIndexPage, {"title": "案例", "slug": "cases"}),
(SimpleContentPage, {"title": "隐私政策", "slug": "privacy-policy"}),
],
)
def test_each_top_level_section_can_be_created_under_home_in_admin(
home_page, index_model, kwargs
):
"""`can_create_at` 是 Wagtail 管理后台"添加子页面"按钮实际使用的判断(综合
parent.subpage_types 与 child.parent_page_types 两个方向),此前的 bug 正是
仅靠 ORM `add_child()` 无法暴露的——它只影响管理后台,不影响直接调用 ORM。"""
assert index_model.can_create_at(home_page) is True
child = index_model(**kwargs)
home_page.add_child(instance=child)
assert index_model.objects.child_of(home_page).count() == 1