summaryrefslogtreecommitdiffstats
path: root/tests/activities/models
diff options
context:
space:
mode:
authorMichael Manfre2022-11-28 23:41:36 -0500
committerGitHub2022-11-28 21:41:36 -0700
commitfb8f2d10984bcfa2585dc272b4c85d285b722792 (patch)
treefa9616f745c7e9e4b5cc5d1ca82d61512ee64f01 /tests/activities/models
parent7f838433edde6a03d1b7f71da269f9756a3f91e9 (diff)
downloadtakahe-fb8f2d10984bcfa2585dc272b4c85d285b722792.tar.gz
takahe-fb8f2d10984bcfa2585dc272b4c85d285b722792.tar.bz2
takahe-fb8f2d10984bcfa2585dc272b4c85d285b722792.zip
Hashtags
Diffstat (limited to 'tests/activities/models')
-rw-r--r--tests/activities/models/test_hashtag.py41
1 files changed, 41 insertions, 0 deletions
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('<a href="/url/with#anchor">Text</a>')
+ == '<a href="/url/with#anchor">Text</a>'
+ )
+ assert (
+ linkify("#HashTag") == '<a class="hashtag" href="/tags/hashtag/">#HashTag</a>'
+ )
+ assert (
+ linkify(
+ """A longer text #bigContent
+with #tags, linebreaks, and
+maybe a few <a href="https://awesome.sauce/about#spicy">links</a>
+#allTheTags #AllTheTags #ALLTHETAGS"""
+ )
+ == """A longer text <a class="hashtag" href="/tags/bigcontent/">#bigContent</a>
+with <a class="hashtag" href="/tags/tags/">#tags</a>, linebreaks, and
+maybe a few <a href="https://awesome.sauce/about#spicy">links</a>
+<a class="hashtag" href="/tags/allthetags/">#allTheTags</a> <a class="hashtag" href="/tags/allthetags/">#AllTheTags</a> <a class="hashtag" href="/tags/allthetags/">#ALLTHETAGS</a>"""
+ )