From cdfff32f9af75730ca560833744433f1dc07067f Mon Sep 17 00:00:00 2001
From: Michael Manfre
Date: Tue, 22 Nov 2022 21:52:40 -0500
Subject: Content warning name customisation

Allows the name of Content Warning to be customized (e.g. to "Content Summary").

Fixes #28.---
 tests/activities/views/test_posts.py     | 24 ++++++++++++++++++++++++
 tests/activities/views/test_timelines.py | 18 ++++++++++++++++++
 tests/conftest.py                        |  9 +++++++--
 3 files changed, 49 insertions(+), 2 deletions(-)
 create mode 100644 tests/activities/views/test_posts.py
 create mode 100644 tests/activities/views/test_timelines.py

(limited to 'tests')

diff --git a/tests/activities/views/test_posts.py b/tests/activities/views/test_posts.py
new file mode 100644
index 0000000..b04c30f
--- /dev/null
+++ b/tests/activities/views/test_posts.py
@@ -0,0 +1,24 @@
+import re
+
+import mock
+import pytest
+
+from activities.views.posts import Compose
+
+
+@pytest.mark.django_db
+def test_content_warning_text(identity, user, rf, config_system):
+    request = rf.get("/compose/")
+    request.user = user
+    request.identity = identity
+
+    config_system.content_warning_text = "Content Summary"
+    with mock.patch("core.models.Config.load_system", return_value=config_system):
+        view = Compose.as_view()
+        resp = view(request)
+        assert resp.status_code == 200
+        content = str(resp.rendered_content)
+        assert 'placeholder="Content Summary"' in content
+        assert re.search(
+            r"<label.*>\s*Content Summary\s*</label>", content, flags=re.MULTILINE
+        )
diff --git a/tests/activities/views/test_timelines.py b/tests/activities/views/test_timelines.py
new file mode 100644
index 0000000..6c8b355
--- /dev/null
+++ b/tests/activities/views/test_timelines.py
@@ -0,0 +1,18 @@
+import mock
+import pytest
+
+from activities.views.timelines import Home
+
+
+@pytest.mark.django_db
+def test_content_warning_text(identity, user, rf, config_system):
+    request = rf.get("/")
+    request.user = user
+    request.identity = identity
+
+    config_system.content_warning_text = "Content Summary"
+    with mock.patch("core.models.Config.load_system", return_value=config_system):
+        view = Home.as_view()
+        resp = view(request)
+        assert resp.status_code == 200
+        assert 'placeholder="Content Summary"' in str(resp.rendered_content)
diff --git a/tests/conftest.py b/tests/conftest.py
index 536162c..69e8e7a 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -62,11 +62,16 @@ def config_system(keypair):
 
 @pytest.fixture
 @pytest.mark.django_db
-def identity():
+def user() -> User:
+    return User.objects.create(email="test@example.com")
+
+
+@pytest.fixture
+@pytest.mark.django_db
+def identity(user):
     """
     Creates a basic test identity with a user and domain.
     """
-    user = User.objects.create(email="test@example.com")
     domain = Domain.objects.create(domain="example.com", local=True, public=True)
     identity = Identity.objects.create(
         actor_uri="https://example.com/test-actor/",
-- 
cgit v1.2.3