This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/articles/tests/test_articles.py

35 lines
1 KiB
Python
Raw Normal View History

2020-08-18 07:23:59 +02:00
import pytest
from django.test import Client
2020-08-18 08:24:40 +02:00
from model_bakery import baker
2020-08-18 07:23:59 +02:00
from articles.models import Article, Page, User
@pytest.mark.django_db
def test_can_access_list(client: Client, author: User):
2020-08-18 08:24:40 +02:00
article = baker.make(Article, author=author, status=Article.PUBLISHED)
page = baker.make(Page, author=author, status=Article.PUBLISHED)
2020-08-18 07:23:59 +02:00
res = client.get("/")
assert res.status_code == 200
content = res.content.decode("utf-8")
for art in [article, page]:
assert art.title in content
assert article.content in content
assert page.content not in content
@pytest.mark.django_db
def test_abstract_shown_on_list(client: Client, author: User):
abstract = "Some abstract"
after = "Some content after abstract"
2020-08-18 08:24:40 +02:00
baker.make(
Article,
2020-08-18 07:23:59 +02:00
status=Article.PUBLISHED,
2020-08-18 08:24:40 +02:00
author=author,
2020-08-18 07:23:59 +02:00
content=f"{abstract}\n<!--more-->\n{after}",
)
res = client.get("/")
content = res.content.decode("utf-8")
assert abstract in content
assert after not in content