- 新增 apps.core.ContactPage(SEOablePage),复用 COMMON_BLOCKS StreamField, 挂载于 HomePage 下;同步补充 HomePage.subpage_types 使后台可创建该子页面。 - 新增迁移 apps/core/migrations/0003_contactpage.py。 - 新增幂等管理命令 seed_contact_page:创建"联系我们"线索表单定义 (姓名/公司/电话/邮箱/需求描述)+ 创建/更新 slug=contact 的页面, 接入 bootstrap_deployment 部署引导流程。 - apps/home/tests.py 补充 ContactPage 相关回归测试(subpage_types 集合、 管理后台可创建性参数化用例),全仓库 pytest 65 -> 68 全部通过。 - 设计文档 §2.16 进度清单同步更新。
56 lines
2.2 KiB
Python
56 lines
2.2 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 ContactPage, 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",
|
|
"core.ContactPage",
|
|
}
|
|
|
|
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"}),
|
|
(ContactPage, {"title": "联系我们", "slug": "contact"}),
|
|
],
|
|
)
|
|
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
|