Skip to content

Commit

Permalink
Fix tests after mentions change
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed May 13, 2023
1 parent f5a3971 commit f4bbe78
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
29 changes: 14 additions & 15 deletions tests/activities/models/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_linkify_mentions_remote(
post.mentions.add(remote_identity)
assert (
post.safe_content_remote()
== '<p>Hello <a href="https://remote.test/@test/" class="mention">@test</a></p>'
== '<p>Hello <span class="h-card"><a href="https://remote.test/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span></p>'
)
# Test a full username (local)
post = Post.objects.create(
Expand All @@ -112,7 +112,7 @@ def test_linkify_mentions_remote(
post.mentions.add(identity)
assert (
post.safe_content_remote()
== '<p><a href="https://example.com/@test/" class="mention">@test</a>, welcome!</p>'
== '<p><span class="h-card"><a href="https://example.com/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span>, welcome!</p>'
)
# Test that they don't get touched without a mention
post = Post.objects.create(
Expand All @@ -131,7 +131,7 @@ def test_linkify_mentions_remote(
post.mentions.add(remote_identity)
assert (
post.safe_content_remote()
== '<p>Hey <a href="https://remote.test/@test/" class="mention">@TeSt</a></p>'
== '<p>Hey <span class="h-card"><a href="https://remote.test/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>TeSt</span></a></span></p>'
)

# Test trailing dot (remote)
Expand All @@ -143,7 +143,7 @@ def test_linkify_mentions_remote(
post.mentions.add(remote_identity)
assert (
post.safe_content_remote()
== '<p>Hey <a href="https://remote.test/@test/" class="mention">@test</a>.</p>'
== '<p>Hey <span class="h-card"><a href="https://remote.test/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span>.</p>'
)

# Test that collapsing only applies to the first unique, short username
Expand All @@ -154,15 +154,15 @@ def test_linkify_mentions_remote(
)
post.mentions.set([remote_identity, remote_identity2])
assert post.safe_content_remote() == (
'<p>Hey <a href="https://remote.test/@test/" class="mention">@TeSt</a> '
'and <a href="https://remote2.test/@test/" class="mention">@[email protected]</a></p>'
'<p>Hey <span class="h-card"><a href="https://remote.test/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>TeSt</span></a></span> '
'and <span class="h-card"><a href="https://remote2.test/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>[email protected]</span></a></span></p>'
)

post.content = "<p>Hey @TeSt, @[email protected] and @test</p>"
assert post.safe_content_remote() == (
'<p>Hey <a href="https://remote2.test/@test/" class="mention">@TeSt</a>, '
'<a href="https://remote.test/@test/" class="mention">@[email protected]</a> '
'and <a href="https://remote2.test/@test/" class="mention">@test</a></p>'
'<p>Hey <span class="h-card"><a href="https://remote2.test/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>TeSt</span></a></span>, '
'<span class="h-card"><a href="https://remote.test/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>[email protected]</span></a></span> '
'and <span class="h-card"><a href="https://remote2.test/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span></p>'
)


Expand All @@ -180,7 +180,7 @@ def test_linkify_mentions_local(config_system, identity, identity2, remote_ident
post.mentions.add(remote_identity)
assert (
post.safe_content_local()
== '<p>Hello <a href="/@[email protected]/" class="mention">@test</a></p>'
== '<p>Hello <span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span></p>'
)
# Test a full username (local)
post = Post.objects.create(
Expand All @@ -191,9 +191,9 @@ def test_linkify_mentions_local(config_system, identity, identity2, remote_ident
post.mentions.add(identity)
post.mentions.add(identity2)
assert post.safe_content_local() == (
'<p><a href="/@[email protected]/" class="mention">@test</a>, welcome!'
' <a href="/@[email protected]/" class="mention">@[email protected]</a>'
' <a href="/@[email protected]/" class="mention">@test</a></p>'
'<p><span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span>, welcome!'
' <span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>[email protected]</span></a></span>'
' <span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span></p>'
)
# Test a full username (remote) with no <p>
post = Post.objects.create(
Expand All @@ -204,7 +204,7 @@ def test_linkify_mentions_local(config_system, identity, identity2, remote_ident
post.mentions.add(remote_identity)
assert (
post.safe_content_local()
== '<a href="/@[email protected]/" class="mention">@test</a> hello!'
== '<span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span> hello!'
)
# Test that they don't get touched without a mention
post = Post.objects.create(
Expand All @@ -217,7 +217,6 @@ def test_linkify_mentions_local(config_system, identity, identity2, remote_ident

@pytest.mark.django_db
def test_post_transitions(identity, stator):

# Create post
post = Post.objects.create(
content="<p>Hello!</p>",
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_mention_format(api_client, identity, remote_identity):
).json()
assert (
response["content"]
== '<p>Hello, <a href="https://example.com/@test/" class="mention">@test</a>!</p>'
== '<p>Hello, <span class="h-card"><a href="https://example.com/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span>!</p>'
)
assert response["visibility"] == "unlisted"

Expand All @@ -88,7 +88,7 @@ def test_mention_format(api_client, identity, remote_identity):
).json()
assert (
response["text"]
== '<p>Hey <a href="https://example.com/@test/" class="mention">@test</a></p>'
== '<p>Hey <span class="h-card"><a href="https://example.com/@test/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span></p>'
)


Expand Down
8 changes: 5 additions & 3 deletions tests/core/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def test_parser(identity):
find_emojis=True,
)
assert (
parser.html == '<p><a href="/@[email protected]/" class="mention">@test</a></p>'
parser.html
== '<p><span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span></p>'
)
assert parser.plain_text == "@[email protected]"
assert parser.mentions == {"[email protected]"}
Expand All @@ -93,7 +94,8 @@ def test_parser(identity):
find_emojis=True,
)
assert (
parser.html == '<p><a href="/@[email protected]/" class="mention">@TeSt</a></p>'
parser.html
== '<p><span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>TeSt</span></a></span></p>'
)
assert parser.plain_text == "@[email protected]"
assert parser.mentions == {"[email protected]"}
Expand Down Expand Up @@ -135,6 +137,6 @@ def test_parser_same_name_mentions(remote_identity, remote_identity2):
)
assert (
parser.html
== '<a href="/@[email protected]/" class="mention">@test</a> <a href="/@[email protected]/" class="mention">@test</a>'
== '<span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span> <span class="h-card"><a href="/@[email protected]/" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>test</span></a></span>'
)
assert parser.plain_text == "@test @test"

0 comments on commit f4bbe78

Please sign in to comment.