Revert "Refactor tests and add tag in default fixtures"
This reverts commit 719a7ec85b
.
This commit is contained in:
parent
13b45b757d
commit
dd2f44b83f
2 changed files with 15 additions and 26 deletions
|
@ -5,7 +5,7 @@ import pytest
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from articles.models import Article, Tag, User
|
from articles.models import Article, User
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
@ -16,14 +16,8 @@ def author() -> User:
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def tag() -> Tag:
|
def published_article(author: User) -> Article:
|
||||||
return Tag.objects.create(name="This is a new tag", slug="this-new-tag")
|
return Article.objects.create(
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def published_article(author: User, tag: Tag) -> Article:
|
|
||||||
article = Article.objects.create(
|
|
||||||
title="Some interesting article title",
|
title="Some interesting article title",
|
||||||
status=Article.PUBLISHED,
|
status=Article.PUBLISHED,
|
||||||
author=author,
|
author=author,
|
||||||
|
@ -37,8 +31,6 @@ def published_article(author: User, tag: Tag) -> Article:
|
||||||
"[1]: https://example.com/image.png"
|
"[1]: https://example.com/image.png"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
article.tags.set([tag])
|
|
||||||
return article
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
|
@ -18,7 +18,10 @@ def test_unauthenticated_render_redirects(published_article: Article, client: Cl
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_render_article_same_content(published_article: Article, client: Client):
|
def test_render_article_same_content(published_article: Article, client: Client):
|
||||||
client.force_login(published_article.author)
|
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(
|
standard_res = client.get(
|
||||||
reverse("article-detail", kwargs={"slug": published_article.slug})
|
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):
|
def test_render_article_change_content(published_article: Article, client: Client):
|
||||||
client.force_login(published_article.author)
|
client.force_login(published_article.author)
|
||||||
preview_content = "This is a different content **with strong emphasis**"
|
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
|
assert api_res.status_code == 200
|
||||||
api_content = api_res.content.decode("utf-8") # type: str
|
api_content = api_res.content.decode("utf-8") # type: str
|
||||||
html_preview_content = format_article_content(preview_content)
|
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)
|
client.force_login(published_article.author)
|
||||||
original_content = published_article.content
|
original_content = published_article.content
|
||||||
preview_content = "This is a different content **with strong emphasis**"
|
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
|
assert api_res.status_code == 200
|
||||||
published_article.refresh_from_db()
|
published_article.refresh_from_db()
|
||||||
assert published_article.content == original_content
|
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))
|
|
||||||
),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
Reference in a new issue