Fix eager evaluation in get_css_classes and auto-slug test
- Replace dict.get() with eager default in TagMetadata.get_css_classes() with explicit if/else to avoid unnecessary MD5 hash + DB access - Fix test_article_save_auto_generates_slug_from_title to actually test auto-generation by passing slug="" instead of the expected result Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -274,7 +274,10 @@ class TagMetadata(models.Model):
|
|||||||
"border": "border-zinc-600/20 dark:border-zinc-400/20",
|
"border": "border-zinc-600/20 dark:border-zinc-400/20",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return mapping.get(self.colour, get_auto_tag_colour_css(self.tag.name))
|
css = mapping.get(self.colour)
|
||||||
|
if css is not None:
|
||||||
|
return css
|
||||||
|
return get_auto_tag_colour_css(self.tag.name)
|
||||||
|
|
||||||
|
|
||||||
class ArticlePageAdminForm(WagtailAdminPageForm):
|
class ArticlePageAdminForm(WagtailAdminPageForm):
|
||||||
|
|||||||
@@ -164,13 +164,13 @@ def test_article_save_auto_generates_slug_from_title(home_page):
|
|||||||
author = AuthorFactory()
|
author = AuthorFactory()
|
||||||
article = ArticlePage(
|
article = ArticlePage(
|
||||||
title="My Great Article",
|
title="My Great Article",
|
||||||
slug="my-great-article",
|
slug="",
|
||||||
author=author,
|
author=author,
|
||||||
summary="summary",
|
summary="summary",
|
||||||
body=[("rich_text", "<p>body</p>")],
|
body=[("rich_text", "<p>body</p>")],
|
||||||
)
|
)
|
||||||
index.add_child(instance=article)
|
index.add_child(instance=article)
|
||||||
article.save()
|
article.refresh_from_db()
|
||||||
assert article.slug == "my-great-article"
|
assert article.slug == "my-great-article"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user