Extract some fixtures and use reversed urls
This commit is contained in:
parent
a3f64c573a
commit
546f8b4078
2 changed files with 38 additions and 10 deletions
|
@ -1,9 +1,36 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from articles.models import User
|
from articles.models import Article, Page, User
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def author():
|
def author():
|
||||||
return User.objects.create_user("gaugendre")
|
return User.objects.create_user("gaugendre")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def published_article(author):
|
||||||
|
return Article.objects.create(
|
||||||
|
title="Some interesting title",
|
||||||
|
status=Article.PUBLISHED,
|
||||||
|
author=author,
|
||||||
|
published_at=timezone.now(),
|
||||||
|
slug="some-slug",
|
||||||
|
content="# some markdown\n\n[a link](https://example.com)",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def published_page(author):
|
||||||
|
return Page.objects.create(
|
||||||
|
title="Some interesting title",
|
||||||
|
status=Article.PUBLISHED,
|
||||||
|
author=author,
|
||||||
|
published_at=timezone.now(),
|
||||||
|
slug="some-slug",
|
||||||
|
content="# some markdown\n\n[a link](https://example.com)",
|
||||||
|
)
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
import pytest
|
import pytest
|
||||||
from django.test import Client
|
from django.test import Client
|
||||||
|
from django.urls import reverse
|
||||||
from model_bakery import baker
|
from model_bakery import baker
|
||||||
|
|
||||||
from articles.models import Article, Page, User
|
from articles.models import Article, Page, User
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_can_access_list(client: Client, author: User):
|
def test_can_access_list(
|
||||||
article = baker.make(Article, author=author, status=Article.PUBLISHED)
|
client: Client, published_article: Article, published_page: Page
|
||||||
page = baker.make(Page, author=author, status=Article.PUBLISHED)
|
):
|
||||||
res = client.get("/")
|
res = client.get(reverse("articles-list"))
|
||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
content = res.content.decode("utf-8")
|
content = res.content.decode("utf-8")
|
||||||
for art in [article, page]:
|
for art in [published_article, published_page]:
|
||||||
assert art.title in content
|
assert art.title in content
|
||||||
assert article.content in content
|
assert published_article.get_abstract() in content
|
||||||
assert page.content not in content
|
assert published_page.get_formatted_content() not in content
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
@ -27,8 +28,8 @@ def test_abstract_shown_on_list(client: Client, author: User):
|
||||||
status=Article.PUBLISHED,
|
status=Article.PUBLISHED,
|
||||||
author=author,
|
author=author,
|
||||||
content=f"{abstract}\n<!--more-->\n{after}",
|
content=f"{abstract}\n<!--more-->\n{after}",
|
||||||
)
|
) # type: Article
|
||||||
res = client.get("/")
|
res = client.get(reverse("articles-list"))
|
||||||
content = res.content.decode("utf-8")
|
content = res.content.decode("utf-8")
|
||||||
assert abstract in content
|
assert abstract in content
|
||||||
assert after not in content
|
assert after not in content
|
||||||
|
|
Reference in a new issue