2020-08-18 07:23:59 +02:00
|
|
|
import pytest
|
|
|
|
from django.test import Client
|
2020-08-18 08:36:45 +02:00
|
|
|
from django.urls import reverse
|
2020-08-18 08:24:40 +02:00
|
|
|
from model_bakery import baker
|
2020-08-18 07:23:59 +02:00
|
|
|
|
|
|
|
from articles.models import Article, Page, User
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
2020-08-18 08:36:45 +02:00
|
|
|
def test_can_access_list(
|
|
|
|
client: Client, published_article: Article, published_page: Page
|
|
|
|
):
|
|
|
|
res = client.get(reverse("articles-list"))
|
2020-08-18 07:23:59 +02:00
|
|
|
assert res.status_code == 200
|
|
|
|
content = res.content.decode("utf-8")
|
2020-08-18 08:36:45 +02:00
|
|
|
for art in [published_article, published_page]:
|
2020-08-18 07:23:59 +02:00
|
|
|
assert art.title in content
|
2020-08-18 08:36:45 +02:00
|
|
|
assert published_article.get_abstract() in content
|
|
|
|
assert published_page.get_formatted_content() not in content
|
2020-08-18 07:23:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
def test_abstract_shown_on_list(client: Client, author: User):
|
|
|
|
abstract = "Some abstract"
|
|
|
|
after = "Some content after abstract"
|
2020-08-18 08:24:40 +02:00
|
|
|
baker.make(
|
|
|
|
Article,
|
2020-08-18 07:23:59 +02:00
|
|
|
status=Article.PUBLISHED,
|
2020-08-18 08:24:40 +02:00
|
|
|
author=author,
|
2020-08-18 07:23:59 +02:00
|
|
|
content=f"{abstract}\n<!--more-->\n{after}",
|
2020-08-18 08:36:45 +02:00
|
|
|
) # type: Article
|
|
|
|
res = client.get(reverse("articles-list"))
|
2020-08-18 07:23:59 +02:00
|
|
|
content = res.content.decode("utf-8")
|
|
|
|
assert abstract in content
|
|
|
|
assert after not in content
|
2020-08-18 08:36:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
def test_access_article_by_slug(client: Client, published_article: Article):
|
|
|
|
res = client.get(reverse("article-detail", kwargs={"slug": published_article.slug}))
|
|
|
|
assert res.status_code == 200
|
|
|
|
content = res.content.decode("utf-8")
|
|
|
|
assert published_article.title in content
|
|
|
|
assert published_article.get_formatted_content() in content
|
2020-11-10 15:44:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
def test_has_plausible_if_set(client: Client, settings):
|
|
|
|
settings.PLAUSIBLE_DOMAIN = "gabnotes.org"
|
|
|
|
res = client.get(reverse("articles-list"))
|
|
|
|
content = res.content.decode("utf-8")
|
|
|
|
assert "https://plausible.augendre.info/js/plausible.js" in content
|
|
|
|
assert 'data-domain="gabnotes.org"' in content
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
def test_doesnt_have_plausible_if_unset(client: Client, settings):
|
|
|
|
settings.PLAUSIBLE_DOMAIN = None
|
|
|
|
res = client.get(reverse("articles-list"))
|
|
|
|
content = res.content.decode("utf-8")
|
|
|
|
assert "https://plausible.augendre.info/js/plausible.js" not in content
|
2020-11-10 16:04:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
def test_logged_in_user_doesnt_have_plausible(client: Client, author: User, settings):
|
|
|
|
client.force_login(author)
|
|
|
|
settings.PLAUSIBLE_DOMAIN = "gabnotes.org"
|
|
|
|
res = client.get(reverse("articles-list"))
|
|
|
|
content = res.content.decode("utf-8")
|
|
|
|
assert "https://plausible.augendre.info/js/plausible.js" not in content
|