From 53d94529175dface366a935eea2c2bcc1eeab15c Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 21 Nov 2022 21:18:13 -0700 Subject: Outgoing mentions mostly work (exc. cc followers) --- tests/activities/models/test_post.py | 58 ++++++++++++++++++++++++++++++------ tests/conftest.py | 6 ++-- 2 files changed, 53 insertions(+), 11 deletions(-) (limited to 'tests') 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="

Hello @test

", author=identity, local=True, ) - assert post.safe_content == '

Hello @test

' - # Test a full username + post.mentions.add(remote_identity) + assert ( + post.safe_content_remote() + == '

Hello @test

' + ) + # Test a full username (local) post = Post.objects.create( content="

@test@example.com, welcome!

", author=identity, local=True, ) + post.mentions.add(identity) assert ( - post.safe_content - == '

@test@example.com, welcome!

' + post.safe_content_remote() + == '

@test@example.com, welcome!

' ) - # 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="

@test@example.com, welcome!

", + author=identity, + local=True, + ) + assert post.safe_content_remote() == "

@test@example.com, welcome!

" + + +@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="

Hello @test

", author=identity, local=True, ) post.mentions.add(remote_identity) - assert post.safe_content == '

Hello @test

' + assert ( + post.safe_content_local() + == '

Hello @test

' + ) + # Test a full username (local) + post = Post.objects.create( + content="

@test@example.com, welcome!

", + author=identity, + local=True, + ) + post.mentions.add(identity) + assert ( + post.safe_content_local() + == '

@test@example.com, welcome!

' + ) + # Test that they don't get touched without a mention + post = Post.objects.create( + content="

@test@example.com, welcome!

", + author=identity, + local=True, + ) + assert post.safe_content_local() == "

@test@example.com, welcome!

" 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", -- cgit v1.2.3