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 ++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'tests/activities/models') 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!

" -- cgit v1.2.3