Add Docker-executed pytest suite with >90% coverage
This commit is contained in:
42
apps/blog/tests/test_models.py
Normal file
42
apps/blog/tests/test_models.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import pytest
|
||||
from django.db import IntegrityError
|
||||
from taggit.models import Tag
|
||||
|
||||
from apps.blog.models import ArticleIndexPage, ArticlePage, HomePage, TagMetadata
|
||||
from apps.blog.tests.factories import AuthorFactory
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_home_page_creation(home_page):
|
||||
assert HomePage.objects.count() == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_article_index_parent_restriction():
|
||||
assert ArticleIndexPage.parent_page_types == ["blog.HomePage"]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_article_compute_read_time_excludes_code(home_page):
|
||||
index = ArticleIndexPage(title="Articles", slug="articles")
|
||||
home_page.add_child(instance=index)
|
||||
author = AuthorFactory()
|
||||
article = ArticlePage(
|
||||
title="A",
|
||||
slug="a",
|
||||
author=author,
|
||||
summary="s",
|
||||
body=[("rich_text", "<p>one two three</p>"), ("code", {"language": "python", "raw_code": "x y z"})],
|
||||
)
|
||||
index.add_child(instance=article)
|
||||
article.save()
|
||||
assert article.read_time_mins == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_tag_metadata_css_and_uniqueness():
|
||||
tag = Tag.objects.create(name="llms", slug="llms")
|
||||
meta = TagMetadata.objects.create(tag=tag, colour="cyan")
|
||||
assert meta.get_css_classes()["bg"].startswith("bg-cyan")
|
||||
with pytest.raises(IntegrityError):
|
||||
TagMetadata.objects.create(tag=tag, colour="pink")
|
||||
Reference in New Issue
Block a user