summaryrefslogtreecommitdiffstats
path: root/tests/activities/models
diff options
context:
space:
mode:
authorMichael Manfre2022-12-05 23:44:26 -0500
committerGitHub2022-12-05 21:44:26 -0700
commit64cea557bebdb0a5b4f17362d8e66845b0a77113 (patch)
tree7f5ff24cfa18f3aebf8c8ef91b79465363953be1 /tests/activities/models
parent5b82c76defd8016df137087e5ce55b44cf017399 (diff)
downloadtakahe-64cea557bebdb0a5b4f17362d8e66845b0a77113.tar.gz
takahe-64cea557bebdb0a5b4f17362d8e66845b0a77113.tar.bz2
takahe-64cea557bebdb0a5b4f17362d8e66845b0a77113.zip
Collapse linkify mentions (#123)
Diffstat (limited to 'tests/activities/models')
-rw-r--r--tests/activities/models/test_post.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py
index 06d26ed..a5f2f79 100644
--- a/tests/activities/models/test_post.py
+++ b/tests/activities/models/test_post.py
@@ -32,7 +32,9 @@ def test_fetch_post(httpx_mock: HTTPXMock, config_system):
@pytest.mark.django_db
-def test_linkify_mentions_remote(identity, remote_identity):
+def test_linkify_mentions_remote(
+ identity, identity2, remote_identity, remote_identity2
+):
"""
Tests that we can linkify post mentions properly for remote use
"""
@@ -77,9 +79,28 @@ def test_linkify_mentions_remote(identity, remote_identity):
== '<p>Hey <a href="https://remote.test/@test/">@test</a></p>'
)
+ # Test that collapsing only applies to the first unique, short username
+ post = Post.objects.create(
+ content="<p>Hey @TeSt@remote.test and @test@remote2.test</p>",
+ author=identity,
+ local=True,
+ )
+ post.mentions.set([remote_identity, remote_identity2])
+ assert post.safe_content_remote() == (
+ '<p>Hey <a href="https://remote.test/@test/">@test</a> '
+ 'and <a href="https://remote2.test/@test/">@test@remote2.test</a></p>'
+ )
+
+ post.content = "<p>Hey @TeSt, @Test@remote.test and @test</p>"
+ assert post.safe_content_remote() == (
+ '<p>Hey <a href="https://remote2.test/@test/">@test</a>, '
+ '<a href="https://remote.test/@test/">@test@remote.test</a> '
+ 'and <a href="https://remote2.test/@test/">@test</a></p>'
+ )
+
@pytest.mark.django_db
-def test_linkify_mentions_local(identity, remote_identity):
+def test_linkify_mentions_local(identity, identity2, remote_identity):
"""
Tests that we can linkify post mentions properly for local use
"""
@@ -96,14 +117,16 @@ def test_linkify_mentions_local(identity, remote_identity):
)
# Test a full username (local)
post = Post.objects.create(
- content="<p>@test@example.com, welcome!</p>",
+ content="<p>@test@example.com, welcome! @test@example2.com @test@example.com</p>",
author=identity,
local=True,
)
post.mentions.add(identity)
- assert (
- post.safe_content_local()
- == '<p><a href="/@test@example.com/">@test</a>, welcome!</p>'
+ post.mentions.add(identity2)
+ assert post.safe_content_local() == (
+ '<p><a href="/@test@example.com/">@test</a>, welcome!'
+ ' <a href="/@test@example2.com/">@test@example2.com</a>'
+ ' <a href="/@test@example.com/">@test</a></p>'
)
# Test a full username (remote) with no <p>
post = Post.objects.create(