Issue #61: Strengthen auto-generation for slug, summary, and SEO fields. - ArticlePage.save() now auto-generates slug from title when empty - ArticlePage.save() auto-populates search_description from summary - Admin form also auto-populates search_description from summary Issue #63: Replace manual TagMetadata colour assignment with deterministic hash-based auto-colour. Tags get a consistent colour from a 12-entry palette without needing a TagMetadata snippet. TagMetadata still works as an explicit override. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
|
|
import pytest
|
|
from django.template import Context
|
|
from django.test import RequestFactory
|
|
from taggit.models import Tag
|
|
from wagtail.models import Site
|
|
|
|
from apps.core.context_processors import site_settings
|
|
from apps.core.templatetags import core_tags
|
|
from apps.core.templatetags.seo_tags import article_json_ld
|
|
from apps.legal.models import LegalIndexPage, LegalPage
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_context_processor_returns_sitesettings(home_page):
|
|
rf = RequestFactory()
|
|
request = rf.get("/")
|
|
request.site = Site.find_for_request(request)
|
|
data = site_settings(request)
|
|
assert "site_settings" in data
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_get_tag_css_auto_colour():
|
|
"""Tags without metadata get a deterministic auto-assigned colour."""
|
|
tag = Tag.objects.create(name="x", slug="x")
|
|
value = core_tags.get_tag_css(tag)
|
|
assert "bg-" in value
|
|
assert "text-" in value
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_get_tag_border_css_auto_colour():
|
|
"""Tags without metadata get a deterministic auto-assigned border colour."""
|
|
tag = Tag.objects.create(name="y", slug="y")
|
|
value = core_tags.get_tag_border_css(tag)
|
|
assert "border-" in value
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_get_legal_pages_tag_callable(home_page):
|
|
legal_index = LegalIndexPage(title="Legal", slug="legal")
|
|
home_page.add_child(instance=legal_index)
|
|
legal = LegalPage(title="Privacy", slug="privacy-policy", body="<p>x</p>", last_updated="2026-01-01")
|
|
legal_index.add_child(instance=legal)
|
|
legal.save_revision().publish()
|
|
|
|
rf = RequestFactory()
|
|
request = rf.get("/")
|
|
pages = core_tags.get_legal_pages({"request": request})
|
|
assert pages.count() >= 1
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_article_json_ld_contains_headline(article_page, rf):
|
|
request = rf.get("/")
|
|
request.site = Site.objects.filter(is_default_site=True).first()
|
|
result = article_json_ld(Context({"request": request}), article_page)
|
|
assert "application/ld+json" in result
|
|
assert article_page.title in result
|