From 1ffbb2e860e6eb00bc9323bee8266ee77df7c812 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 29 Jan 2023 18:13:21 -0700 Subject: [PATCH] Fix hashtag extraction on post edit --- activities/models/post.py | 2 +- tests/activities/models/test_post.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/activities/models/post.py b/activities/models/post.py index 88e53af..b3e22a0 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -507,7 +507,7 @@ class Post(StatorModel): ): with transaction.atomic(): # Strip all HTML and apply linebreaks filter - parser = FediverseHtmlParser(linebreaks_filter(content)) + parser = FediverseHtmlParser(linebreaks_filter(content), find_hashtags=True) self.content = parser.html self.hashtags = sorted(parser.hashtags) or None self.summary = summary or None diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py index e37e42d..0b9578b 100644 --- a/tests/activities/models/test_post.py +++ b/tests/activities/models/test_post.py @@ -42,6 +42,20 @@ def test_fetch_post(httpx_mock: HTTPXMock, config_system): assert Post.by_object_uri("https://example.com/test-post").id == post.id +@pytest.mark.django_db +def test_post_create_edit(identity: Identity, config_system): + """ + Tests that creating/editing a post works, and extracts mentions and hashtags. + """ + post = Post.create_local(author=identity, content="Hello #world I am @test") + assert post.hashtags == ["world"] + assert list(post.mentions.all()) == [identity] + + post.edit_local(content="Now I like #hashtags") + assert post.hashtags == ["hashtags"] + assert list(post.mentions.all()) == [] + + @pytest.mark.django_db def test_linkify_mentions_remote( identity, identity2, remote_identity, remote_identity2