Reduce test setup

This commit is contained in:
Gabriel Augendre 2020-08-18 08:24:40 +02:00
parent c2b1ac3193
commit a3f64c573a
2 changed files with 13 additions and 22 deletions

View file

@ -87,3 +87,10 @@ class Page(Article):
class Meta: class Meta:
ordering = ["position", "-published_at"] ordering = ["position", "-published_at"]
# class Comment(models.Model):
# username = models.CharField(max_length=255)
# email = models.EmailField(blank=True, null=True)
# content = models.TextField()
# article = models.ForeignKey(Article, on_delete=models.CASCADE)

View file

@ -1,28 +1,14 @@
import pytest import pytest
from django.test import Client from django.test import Client
from django.utils import timezone 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(client: Client, author: User):
article = Article.objects.create( article = baker.make(Article, author=author, status=Article.PUBLISHED)
author=author, page = baker.make(Page, author=author, status=Article.PUBLISHED)
title="Sample published",
status=Article.PUBLISHED,
published_at=timezone.now(),
slug="sample-published",
content="Some content lorem ipsum",
)
page = Page.objects.create(
author=author,
title="Sample page published",
status=Article.PUBLISHED,
published_at=timezone.now(),
slug="sample-page-published",
content="Some page content lorem ipsum",
)
res = client.get("/") res = client.get("/")
assert res.status_code == 200 assert res.status_code == 200
content = res.content.decode("utf-8") content = res.content.decode("utf-8")
@ -36,12 +22,10 @@ def test_can_access_list(client: Client, author: User):
def test_abstract_shown_on_list(client: Client, author: User): def test_abstract_shown_on_list(client: Client, author: User):
abstract = "Some abstract" abstract = "Some abstract"
after = "Some content after abstract" after = "Some content after abstract"
article = Article.objects.create( baker.make(
author=author, Article,
title="Sample published",
status=Article.PUBLISHED, status=Article.PUBLISHED,
published_at=timezone.now(), author=author,
slug="sample-published",
content=f"{abstract}\n<!--more-->\n{after}", content=f"{abstract}\n<!--more-->\n{after}",
) )
res = client.get("/") res = client.get("/")