summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-21 21:18:13 -0700
committerAndrew Godwin2022-11-21 21:18:13 -0700
commit53d94529175dface366a935eea2c2bcc1eeab15c (patch)
tree169575fc31d532fdb31a924636fc535c55c60df4 /tests
parenta80e0f117a0271d428abd939e2896857a8da1b5c (diff)
downloadtakahe-53d94529175dface366a935eea2c2bcc1eeab15c.tar.gz
takahe-53d94529175dface366a935eea2c2bcc1eeab15c.tar.bz2
takahe-53d94529175dface366a935eea2c2bcc1eeab15c.zip
Outgoing mentions mostly work (exc. cc followers)
Diffstat (limited to 'tests')
-rw-r--r--tests/activities/models/test_post.py58
-rw-r--r--tests/conftest.py6
2 files changed, 53 insertions, 11 deletions
diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py
index fb2e7a6..6d86781 100644
--- a/tests/activities/models/test_post.py
+++ b/tests/activities/models/test_post.py
@@ -32,32 +32,72 @@ def test_fetch_post(httpx_mock: HTTPXMock):
@pytest.mark.django_db
-def test_linkify_mentions(identity, remote_identity):
+def test_linkify_mentions_remote(identity, remote_identity):
"""
- Tests that we can linkify post mentions properly
+ Tests that we can linkify post mentions properly for remote use
"""
- # Test a short username without a mention (presumed local)
+ # Test a short username (remote)
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.mentions.add(remote_identity)
+ assert (
+ post.safe_content_remote()
+ == '<p>Hello <a href="https://remote.test/@test/">@test</a></p>'
+ )
+ # Test a full username (local)
post = Post.objects.create(
content="<p>@test@example.com, welcome!</p>",
author=identity,
local=True,
)
+ post.mentions.add(identity)
assert (
- post.safe_content
- == '<p><a href="/@test@example.com/">@test@example.com</a>, welcome!</p>'
+ post.safe_content_remote()
+ == '<p><a href="https://example.com/@test/">@test@example.com</a>, welcome!</p>'
)
- # Test a short username with a mention resolving to remote
+ # Test that they don't get touched without a mention
+ post = Post.objects.create(
+ content="<p>@test@example.com, welcome!</p>",
+ author=identity,
+ local=True,
+ )
+ assert post.safe_content_remote() == "<p>@test@example.com, welcome!</p>"
+
+
+@pytest.mark.django_db
+def test_linkify_mentions_local(identity, remote_identity):
+ """
+ Tests that we can linkify post mentions properly for local use
+ """
+ # Test a short username (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>'
+ assert (
+ post.safe_content_local()
+ == '<p>Hello <a href="/@test@remote.test/">@test</a></p>'
+ )
+ # Test a full username (local)
+ post = Post.objects.create(
+ content="<p>@test@example.com, welcome!</p>",
+ author=identity,
+ local=True,
+ )
+ post.mentions.add(identity)
+ assert (
+ post.safe_content_local()
+ == '<p><a href="/@test@example.com/">@test@example.com</a>, welcome!</p>'
+ )
+ # Test that they don't get touched without a mention
+ post = Post.objects.create(
+ content="<p>@test@example.com, welcome!</p>",
+ author=identity,
+ local=True,
+ )
+ assert post.safe_content_local() == "<p>@test@example.com, welcome!</p>"
diff --git a/tests/conftest.py b/tests/conftest.py
index 24fac9a..536162c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -68,14 +68,15 @@ def identity():
"""
user = User.objects.create(email="test@example.com")
domain = Domain.objects.create(domain="example.com", local=True, public=True)
- return Identity.objects.create(
+ identity = Identity.objects.create(
actor_uri="https://example.com/test-actor/",
username="test",
domain=domain,
- user=user,
name="Test User",
local=True,
)
+ identity.users.set([user])
+ return identity
@pytest.fixture
@@ -87,6 +88,7 @@ def remote_identity():
domain = Domain.objects.create(domain="remote.test", local=False)
return Identity.objects.create(
actor_uri="https://remote.test/test-actor/",
+ profile_uri="https://remote.test/@test/",
username="test",
domain=domain,
name="Test Remote User",