From db31dcadebf96578700b86c5b6b867b2b3fe8145 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Tue, 10 Nov 2020 16:04:07 +0100 Subject: [PATCH] Logged in user doesn't have plausible script --- articles/templates/articles/analytics.html | 2 +- articles/tests/conftest.py | 6 +++--- articles/tests/test_articles.py | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/articles/templates/articles/analytics.html b/articles/templates/articles/analytics.html index 97863ae..769a897 100644 --- a/articles/templates/articles/analytics.html +++ b/articles/templates/articles/analytics.html @@ -1,3 +1,3 @@ -{% if plausible_domain is not None %} +{% if plausible_domain is not None and not user.is_authenticated %} {% endif %} diff --git a/articles/tests/conftest.py b/articles/tests/conftest.py index 2113651..908e95a 100644 --- a/articles/tests/conftest.py +++ b/articles/tests/conftest.py @@ -6,13 +6,13 @@ from articles.models import Article, Page, User @pytest.fixture() @pytest.mark.django_db -def author(): +def author() -> User: return User.objects.create_user("gaugendre") @pytest.fixture() @pytest.mark.django_db -def published_article(author): +def published_article(author: User) -> Article: return Article.objects.create( title="Some interesting article title", status=Article.PUBLISHED, @@ -25,7 +25,7 @@ def published_article(author): @pytest.fixture() @pytest.mark.django_db -def published_page(author): +def published_page(author: User) -> Page: return Page.objects.create( title="Some interesting page title", status=Article.PUBLISHED, diff --git a/articles/tests/test_articles.py b/articles/tests/test_articles.py index 4891c07..847821f 100644 --- a/articles/tests/test_articles.py +++ b/articles/tests/test_articles.py @@ -59,3 +59,12 @@ def test_doesnt_have_plausible_if_unset(client: Client, settings): res = client.get(reverse("articles-list")) content = res.content.decode("utf-8") assert "https://plausible.augendre.info/js/plausible.js" not in content + + +@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