summaryrefslogtreecommitdiffstats
path: root/tests/activities/models
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-21 20:25:00 -0700
committerAndrew Godwin2022-11-21 20:25:00 -0700
commita80e0f117a0271d428abd939e2896857a8da1b5c (patch)
treeec52ed0a24744207dca44af43a205d7c5f593c55 /tests/activities/models
parent0d1e09fbcdb1a1db93d9561c9323c7ef105e71ca (diff)
downloadtakahe-a80e0f117a0271d428abd939e2896857a8da1b5c.tar.gz
takahe-a80e0f117a0271d428abd939e2896857a8da1b5c.tar.bz2
takahe-a80e0f117a0271d428abd939e2896857a8da1b5c.zip
Mentionify tests and some fixtures
Diffstat (limited to 'tests/activities/models')
-rw-r--r--tests/activities/models/test_post.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py
index 5c7fca2..fb2e7a6 100644
--- a/tests/activities/models/test_post.py
+++ b/tests/activities/models/test_post.py
@@ -29,3 +29,35 @@ def test_fetch_post(httpx_mock: HTTPXMock):
assert post.author.actor_uri == "https://example.com/test-actor"
# Fetch again with a DB hit
assert Post.by_object_uri("https://example.com/test-post").id == post.id
+
+
+@pytest.mark.django_db
+def test_linkify_mentions(identity, remote_identity):
+ """
+ Tests that we can linkify post mentions properly
+ """
+ # Test a short username without a mention (presumed local)
+ post = Post.objects.create(
+ content="<p>Hello @test</p>",
+ author=identity,
+ local=True,
+ )
+ assert post.safe_content == '<p>Hello <a href="/@test/">@test</a></p>'
+ # Test a full username
+ post = Post.objects.create(
+ content="<p>@test@example.com, welcome!</p>",
+ author=identity,
+ local=True,
+ )
+ assert (
+ post.safe_content
+ == '<p><a href="/@test@example.com/">@test@example.com</a>, welcome!</p>'
+ )
+ # Test a short username with a mention resolving to remote
+ post = Post.objects.create(
+ content="<p>Hello @test</p>",
+ author=identity,
+ local=True,
+ )
+ post.mentions.add(remote_identity)
+ assert post.safe_content == '<p>Hello <a href="/@test@remote.test/">@test</a></p>'