|
|
|
@ -1,13 +1,15 @@
|
|
|
|
|
import pytest |
|
|
|
|
from django.http import HttpResponse |
|
|
|
|
from django.test import Client |
|
|
|
|
from django.urls import reverse |
|
|
|
|
from model_bakery import baker |
|
|
|
|
from pytest_django.fixtures import SettingsWrapper |
|
|
|
|
|
|
|
|
|
from articles.models import Article, User |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_can_access_list(client: Client, published_article: Article): |
|
|
|
|
def test_can_access_list(client: Client, published_article: Article) -> None: |
|
|
|
|
res = client.get(reverse("articles-list")) |
|
|
|
|
assert res.status_code == 200 |
|
|
|
|
content = res.content.decode("utf-8") |
|
|
|
@ -16,7 +18,7 @@ def test_can_access_list(client: Client, published_article: Article):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_only_title_shown_on_list(client: Client, author: User): |
|
|
|
|
def test_only_title_shown_on_list(client: Client, author: User) -> None: |
|
|
|
|
title = "This is a very long title mouahahaha" |
|
|
|
|
abstract = "Some abstract" |
|
|
|
|
after = "Some content after abstract" |
|
|
|
@ -35,16 +37,16 @@ def test_only_title_shown_on_list(client: Client, author: User):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_access_article_by_slug(client: Client, published_article: Article): |
|
|
|
|
def test_access_article_by_slug(client: Client, published_article: Article) -> None: |
|
|
|
|
_test_access_article_by_slug(client, published_article) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_access_article_by_slug(client: Client, item: Article): |
|
|
|
|
def _test_access_article_by_slug(client: Client, item: Article) -> None: |
|
|
|
|
res = client.get(reverse("article-detail", kwargs={"slug": item.slug})) |
|
|
|
|
_assert_article_is_rendered(item, res) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _assert_article_is_rendered(item: Article, res): |
|
|
|
|
def _assert_article_is_rendered(item: Article, res: HttpResponse) -> None: |
|
|
|
|
assert res.status_code == 200 |
|
|
|
|
content = res.content.decode("utf-8") |
|
|
|
|
assert item.title in content |
|
|
|
@ -55,7 +57,7 @@ def _assert_article_is_rendered(item: Article, res):
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_anonymous_cant_access_draft_detail( |
|
|
|
|
client: Client, unpublished_article: Article |
|
|
|
|
): |
|
|
|
|
) -> None: |
|
|
|
|
res = client.get( |
|
|
|
|
reverse("article-detail", kwargs={"slug": unpublished_article.slug}) |
|
|
|
|
) |
|
|
|
@ -65,7 +67,7 @@ def test_anonymous_cant_access_draft_detail(
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_anonymous_can_access_draft_detail_with_key( |
|
|
|
|
client: Client, unpublished_article: Article |
|
|
|
|
): |
|
|
|
|
) -> None: |
|
|
|
|
res = client.get( |
|
|
|
|
reverse("article-detail", kwargs={"slug": unpublished_article.slug}) |
|
|
|
|
+ f"?draft_key={unpublished_article.draft_key}" |
|
|
|
@ -76,7 +78,7 @@ def test_anonymous_can_access_draft_detail_with_key(
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_user_can_access_draft_detail( |
|
|
|
|
client: Client, author: User, unpublished_article: Article |
|
|
|
|
): |
|
|
|
|
) -> None: |
|
|
|
|
client.force_login(author) |
|
|
|
|
_test_access_article_by_slug(client, unpublished_article) |
|
|
|
|
|
|
|
|
@ -84,7 +86,7 @@ def test_user_can_access_draft_detail(
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_anonymous_cant_access_drafts_list( |
|
|
|
|
client: Client, unpublished_article: Article |
|
|
|
|
): |
|
|
|
|
) -> None: |
|
|
|
|
res = client.get(reverse("drafts-list")) |
|
|
|
|
assert res.status_code == 302 |
|
|
|
|
|
|
|
|
@ -92,7 +94,7 @@ def test_anonymous_cant_access_drafts_list(
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_user_can_access_drafts_list( |
|
|
|
|
client: Client, author: User, unpublished_article: Article |
|
|
|
|
): |
|
|
|
|
) -> None: |
|
|
|
|
client.force_login(author) |
|
|
|
|
res = client.get(reverse("drafts-list")) |
|
|
|
|
assert res.status_code == 200 |
|
|
|
@ -101,7 +103,7 @@ def test_user_can_access_drafts_list(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_has_goatcounter_if_set(client: Client, settings): |
|
|
|
|
def test_has_goatcounter_if_set(client: Client, settings: SettingsWrapper) -> None: |
|
|
|
|
settings.GOATCOUNTER_DOMAIN = "gc.gabnotes.org" |
|
|
|
|
res = client.get(reverse("articles-list")) |
|
|
|
|
content = res.content.decode("utf-8") |
|
|
|
@ -110,7 +112,9 @@ def test_has_goatcounter_if_set(client: Client, settings):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_doesnt_have_goatcounter_if_unset(client: Client, settings): |
|
|
|
|
def test_doesnt_have_goatcounter_if_unset( |
|
|
|
|
client: Client, settings: SettingsWrapper |
|
|
|
|
) -> None: |
|
|
|
|
settings.GOATCOUNTER_DOMAIN = None |
|
|
|
|
res = client.get(reverse("articles-list")) |
|
|
|
|
content = res.content.decode("utf-8") |
|
|
|
@ -119,7 +123,9 @@ def test_doesnt_have_goatcounter_if_unset(client: Client, settings):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_logged_in_user_doesnt_have_goatcounter(client: Client, author: User, settings): |
|
|
|
|
def test_logged_in_user_doesnt_have_goatcounter( |
|
|
|
|
client: Client, author: User, settings: SettingsWrapper |
|
|
|
|
) -> None: |
|
|
|
|
client.force_login(author) |
|
|
|
|
settings.GOATCOUNTER_DOMAIN = "gc.gabnotes.org" |
|
|
|
|
res = client.get(reverse("articles-list")) |
|
|
|
@ -129,7 +135,7 @@ def test_logged_in_user_doesnt_have_goatcounter(client: Client, author: User, se
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db() |
|
|
|
|
def test_image_is_lazy(client: Client, published_article: Article): |
|
|
|
|
def test_image_is_lazy(client: Client, published_article: Article) -> None: |
|
|
|
|
res = client.get(reverse("article-detail", kwargs={"slug": published_article.slug})) |
|
|
|
|
assert res.status_code == 200 |
|
|
|
|
content = res.content.decode("utf-8") |
|
|
|
|