160 lines
4.6 KiB
Python
160 lines
4.6 KiB
Python
import pytest
|
|
from taggit.models import Tag
|
|
|
|
from apps.blog.models import ArticleIndexPage, ArticlePage
|
|
from apps.blog.tests.factories import AuthorFactory
|
|
from apps.comments.models import Comment
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_homepage_render(client, home_page):
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_article_index_pagination_and_tag_filter(client, home_page):
|
|
index = ArticleIndexPage(title="Articles", slug="articles")
|
|
home_page.add_child(instance=index)
|
|
author = AuthorFactory()
|
|
for n in range(14):
|
|
article = ArticlePage(
|
|
title=f"A{n}",
|
|
slug=f"a{n}",
|
|
author=author,
|
|
summary="summary",
|
|
body=[("rich_text", "<p>body</p>")],
|
|
)
|
|
index.add_child(instance=article)
|
|
article.save_revision().publish()
|
|
|
|
resp = client.get("/articles/?page=2")
|
|
assert resp.status_code == 200
|
|
assert resp.context["articles"].number == 2
|
|
assert "Pagination" in resp.content.decode()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_article_page_related_context(client, home_page):
|
|
index = ArticleIndexPage(title="Articles", slug="articles")
|
|
home_page.add_child(instance=index)
|
|
author = AuthorFactory()
|
|
main = ArticlePage(
|
|
title="Main",
|
|
slug="main",
|
|
author=author,
|
|
summary="summary",
|
|
body=[("rich_text", "<p>body</p>")],
|
|
)
|
|
index.add_child(instance=main)
|
|
main.save_revision().publish()
|
|
|
|
related = ArticlePage(
|
|
title="Related",
|
|
slug="related",
|
|
author=author,
|
|
summary="summary",
|
|
body=[("rich_text", "<p>body</p>")],
|
|
)
|
|
index.add_child(instance=related)
|
|
related.save_revision().publish()
|
|
|
|
resp = client.get("/articles/main/")
|
|
assert resp.status_code == 200
|
|
assert "related_articles" in resp.context
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_newsletter_forms_render_in_nav_and_footer(client, home_page):
|
|
resp = client.get("/")
|
|
html = resp.content.decode()
|
|
assert resp.status_code == 200
|
|
assert 'name="source" value="nav"' in html
|
|
assert 'name="source" value="footer"' in html
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_article_page_renders_share_links_and_newsletter_form(client, home_page):
|
|
index = ArticleIndexPage(title="Articles", slug="articles")
|
|
home_page.add_child(instance=index)
|
|
author = AuthorFactory()
|
|
article = ArticlePage(
|
|
title="Main",
|
|
slug="main",
|
|
author=author,
|
|
summary="summary",
|
|
body=[("rich_text", "<p>body</p>")],
|
|
)
|
|
index.add_child(instance=article)
|
|
article.save_revision().publish()
|
|
|
|
resp = client.get("/articles/main/")
|
|
html = resp.content.decode()
|
|
assert resp.status_code == 200
|
|
assert "Share on X" in html
|
|
assert "Share on LinkedIn" in html
|
|
assert 'data-copy-link' in html
|
|
assert 'name="source" value="article"' in html
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_article_page_renders_approved_comments_and_reply_form(client, home_page):
|
|
index = ArticleIndexPage(title="Articles", slug="articles")
|
|
home_page.add_child(instance=index)
|
|
author = AuthorFactory()
|
|
article = ArticlePage(
|
|
title="Main",
|
|
slug="main",
|
|
author=author,
|
|
summary="summary",
|
|
body=[("rich_text", "<p>body</p>")],
|
|
)
|
|
index.add_child(instance=article)
|
|
article.save_revision().publish()
|
|
comment = Comment.objects.create(
|
|
article=article,
|
|
author_name="A",
|
|
author_email="a@example.com",
|
|
body="Top level",
|
|
is_approved=True,
|
|
)
|
|
Comment.objects.create(
|
|
article=article,
|
|
parent=comment,
|
|
author_name="B",
|
|
author_email="b@example.com",
|
|
body="Reply",
|
|
is_approved=True,
|
|
)
|
|
|
|
resp = client.get("/articles/main/")
|
|
html = resp.content.decode()
|
|
assert resp.status_code == 200
|
|
assert "Top level" in html
|
|
assert "Reply" in html
|
|
assert f'name="parent_id" value="{comment.id}"' in html
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_article_index_renders_tag_filter_controls(client, home_page):
|
|
index = ArticleIndexPage(title="Articles", slug="articles")
|
|
home_page.add_child(instance=index)
|
|
author = AuthorFactory()
|
|
article = ArticlePage(
|
|
title="Main",
|
|
slug="main",
|
|
author=author,
|
|
summary="summary",
|
|
body=[("rich_text", "<p>body</p>")],
|
|
)
|
|
index.add_child(instance=article)
|
|
article.save_revision().publish()
|
|
tag = Tag.objects.create(name="TagOne", slug="tag-one")
|
|
article.tags.add(tag)
|
|
article.save_revision().publish()
|
|
|
|
resp = client.get("/articles/")
|
|
html = resp.content.decode()
|
|
assert resp.status_code == 200
|
|
assert "/articles/?tag=tag-one" in html
|