fix: expose page SEO fields and invalidate shared page cache
This commit is contained in:
@@ -67,6 +67,48 @@ def test_form_block_api_representation_expands_fields():
|
||||
assert result["form"]["fields"][1]["choices"] == ["产品咨询", "合作洽谈"]
|
||||
|
||||
|
||||
def test_page_api_exposes_seo_fields(home_page):
|
||||
from wagtail.models import Site
|
||||
from wagtail.images import get_image_model
|
||||
from wagtail.images.tests.utils import get_test_image_file
|
||||
|
||||
site = Site.objects.get(is_default_site=True)
|
||||
site.root_page = home_page
|
||||
site.save()
|
||||
image = get_image_model().objects.create(title="Share", file=get_test_image_file())
|
||||
page = SimpleContentPage(
|
||||
title="SEO test", slug="seo-test", seo_title_override="SEO title",
|
||||
seo_description_override="SEO description", canonical_url="https://example.com/seo-test",
|
||||
schema_json={"@context": "https://schema.org", "@type": "WebPage"},
|
||||
og_image=image, seo_title="Standard title", search_description="Standard description",
|
||||
)
|
||||
home_page.add_child(instance=page)
|
||||
response = APIClient().get(
|
||||
f"/api/v2/pages/{page.pk}/?fields=seo_title,search_description,seo_title_override,seo_description_override,og_image,canonical_url,schema_json"
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.data["seo_title_override"] == "SEO title"
|
||||
assert response.data["seo_description_override"] == "SEO description"
|
||||
assert response.data["canonical_url"] == "https://example.com/seo-test"
|
||||
assert response.data["schema_json"]["@type"] == "WebPage"
|
||||
assert response.data["og_image"]["title"] == "Share"
|
||||
assert response.data["og_image"]["url"].startswith("http://testserver/media/")
|
||||
assert response.data["meta"]["seo_title"] == "Standard title"
|
||||
assert response.data["meta"]["search_description"] == "Standard description"
|
||||
|
||||
|
||||
def test_seo_image_serializer_returns_absolute_url():
|
||||
from types import SimpleNamespace
|
||||
from rest_framework.test import APIRequestFactory
|
||||
from apps.core.serializers import SEOImageSerializer
|
||||
|
||||
image = SimpleNamespace(file=SimpleNamespace(url="/media/share.png"), title="Share")
|
||||
request = APIRequestFactory().get("/api/v2/pages/")
|
||||
assert SEOImageSerializer(image, context={"request": request}).data == {
|
||||
"url": "http://testserver/media/share.png", "title": "Share",
|
||||
}
|
||||
|
||||
|
||||
def test_form_block_api_representation_handles_empty_form():
|
||||
block = FormBlock()
|
||||
result = block.get_api_representation({"form": None})
|
||||
@@ -358,6 +400,7 @@ def test_notify_frontend_revalidate_posts_webhook_when_configured(
|
||||
assert calls[0]["url"] == "https://frontend.example.com/api/revalidate"
|
||||
assert calls[0]["headers"] == {"Authorization": "Bearer test-secret"}
|
||||
assert f"page:{home_page.id}" in calls[0]["json"]["tags"]
|
||||
assert "wagtail-pages" in calls[0]["json"]["tags"]
|
||||
|
||||
|
||||
def test_notify_frontend_revalidate_swallows_request_exception(
|
||||
|
||||
Reference in New Issue
Block a user