From fb8f2d10984bcfa2585dc272b4c85d285b722792 Mon Sep 17 00:00:00 2001
From: Michael Manfre
Date: Mon, 28 Nov 2022 23:41:36 -0500
Subject: Hashtags
---
tests/activities/models/test_hashtag.py | 41 ++++++++++++++++++++++
.../activities/templatetags/test_activity_tags.py | 12 ++++++-
2 files changed, 52 insertions(+), 1 deletion(-)
create mode 100644 tests/activities/models/test_hashtag.py
(limited to 'tests/activities')
diff --git a/tests/activities/models/test_hashtag.py b/tests/activities/models/test_hashtag.py
new file mode 100644
index 0000000..32742d6
--- /dev/null
+++ b/tests/activities/models/test_hashtag.py
@@ -0,0 +1,41 @@
+from activities.models import Hashtag
+
+
+def test_hashtag_from_content():
+ assert Hashtag.hashtags_from_content("#hashtag") == ["hashtag"]
+ assert Hashtag.hashtags_from_content("a#hashtag") == []
+ assert Hashtag.hashtags_from_content("Text #with #hashtag in it") == [
+ "hashtag",
+ "with",
+ ]
+ assert Hashtag.hashtags_from_content("#hashtag.") == ["hashtag"]
+ assert Hashtag.hashtags_from_content("More text\n#one # two ##three #hashtag;") == [
+ "hashtag",
+ "one",
+ "three",
+ ]
+
+
+def test_linkify_hashtag():
+ linkify = Hashtag.linkify_hashtags
+
+ assert linkify("# hashtag") == "# hashtag"
+ assert (
+ linkify('Text')
+ == 'Text'
+ )
+ assert (
+ linkify("#HashTag") == '#HashTag'
+ )
+ assert (
+ linkify(
+ """A longer text #bigContent
+with #tags, linebreaks, and
+maybe a few links
+#allTheTags #AllTheTags #ALLTHETAGS"""
+ )
+ == """A longer text #bigContent
+with #tags, linebreaks, and
+maybe a few links
+#allTheTags #AllTheTags #ALLTHETAGS"""
+ )
diff --git a/tests/activities/templatetags/test_activity_tags.py b/tests/activities/templatetags/test_activity_tags.py
index 987c008..85d8cdf 100644
--- a/tests/activities/templatetags/test_activity_tags.py
+++ b/tests/activities/templatetags/test_activity_tags.py
@@ -2,7 +2,7 @@ from datetime import timedelta
from django.utils import timezone
-from activities.templatetags.activity_tags import timedeltashort
+from activities.templatetags.activity_tags import linkify_hashtags, timedeltashort
def test_timedeltashort_regress():
@@ -19,3 +19,13 @@ def test_timedeltashort_regress():
assert timedeltashort(value - timedelta(days=364)) == "364d"
assert timedeltashort(value - timedelta(days=365)) == "1y"
assert timedeltashort(value - timedelta(days=366)) == "1y"
+
+
+def test_linkify_hashtags_regres():
+ assert linkify_hashtags(None) == ""
+ assert linkify_hashtags("") == ""
+
+ assert (
+ linkify_hashtags("#Takahe")
+ == '#Takahe'
+ )
--
cgit v1.2.3