From dd2f44b83f6573446bc76bd64f083103db9bac25 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 6 Mar 2021 15:06:41 +0100 Subject: [PATCH] Revert "Refactor tests and add tag in default fixtures" This reverts commit 719a7ec85b45ee4ef707ecb42961549210c15e43. --- articles/tests/conftest.py | 14 +++----------- articles/tests/test_api_views.py | 27 ++++++++++++--------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/articles/tests/conftest.py b/articles/tests/conftest.py index a99e497..c995265 100644 --- a/articles/tests/conftest.py +++ b/articles/tests/conftest.py @@ -5,7 +5,7 @@ import pytest from django.core.management import call_command from django.utils import timezone -from articles.models import Article, Tag, User +from articles.models import Article, User @pytest.fixture() @@ -16,14 +16,8 @@ def author() -> User: @pytest.fixture() @pytest.mark.django_db -def tag() -> Tag: - return Tag.objects.create(name="This is a new tag", slug="this-new-tag") - - -@pytest.fixture() -@pytest.mark.django_db -def published_article(author: User, tag: Tag) -> Article: - article = Article.objects.create( +def published_article(author: User) -> Article: + return Article.objects.create( title="Some interesting article title", status=Article.PUBLISHED, author=author, @@ -37,8 +31,6 @@ def published_article(author: User, tag: Tag) -> Article: "[1]: https://example.com/image.png" ), ) - article.tags.set([tag]) - return article @pytest.fixture() diff --git a/articles/tests/test_api_views.py b/articles/tests/test_api_views.py index 6bb9239..9311000 100644 --- a/articles/tests/test_api_views.py +++ b/articles/tests/test_api_views.py @@ -18,7 +18,10 @@ def test_unauthenticated_render_redirects(published_article: Article, client: Cl @pytest.mark.django_db def test_render_article_same_content(published_article: Article, client: Client): client.force_login(published_article.author) - api_res = post_article(client, published_article, published_article.content) + api_res = client.post( + reverse("api-render-article", kwargs={"article_pk": published_article.pk}), + data={"content": published_article.content}, + ) standard_res = client.get( reverse("article-detail", kwargs={"slug": published_article.slug}) ) @@ -39,7 +42,10 @@ def test_render_article_same_content(published_article: Article, client: Client) def test_render_article_change_content(published_article: Article, client: Client): client.force_login(published_article.author) preview_content = "This is a different content **with strong emphasis**" - api_res = post_article(client, published_article, preview_content) + api_res = client.post( + reverse("api-render-article", kwargs={"article_pk": published_article.pk}), + data={"content": preview_content}, + ) assert api_res.status_code == 200 api_content = api_res.content.decode("utf-8") # type: str html_preview_content = format_article_content(preview_content) @@ -51,19 +57,10 @@ def test_render_article_doesnt_save(published_article, client: Client): client.force_login(published_article.author) original_content = published_article.content preview_content = "This is a different content **with strong emphasis**" - api_res = post_article(client, published_article, preview_content) + api_res = client.post( + reverse("api-render-article", kwargs={"article_pk": published_article.pk}), + data={"content": preview_content}, + ) assert api_res.status_code == 200 published_article.refresh_from_db() assert published_article.content == original_content - - -def post_article(client: Client, article: Article, content: str): - return client.post( - reverse("api-render-article", kwargs={"article_pk": article.pk}), - data={ - "content": content, - "tag_ids": ",".join( - map(str, article.tags.all().values_list("pk", flat=True)) - ), - }, - )