diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/activities/models/test_hashtag.py | 41 | ||||
-rw-r--r-- | tests/activities/templatetags/test_activity_tags.py | 12 |
2 files changed, 52 insertions, 1 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>""" + ) 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") + == '<a class="hashtag" href="/tags/takahe/">#Takahe</a>' + ) |