2023-02-17 18:24:42 +00:00
|
|
|
""" tests functionality specifically for the Note ActivityPub dataclass"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
from bookwyrm import activitypub
|
|
|
|
from bookwyrm import models
|
|
|
|
|
|
|
|
|
|
|
|
class Note(TestCase):
|
|
|
|
"""the model-linked ActivityPub dataclass for Note-based types"""
|
|
|
|
|
2023-11-30 05:56:16 +00:00
|
|
|
@classmethod
|
2024-03-17 23:52:20 +00:00
|
|
|
def setUpTestData(cls):
|
2023-02-17 18:24:42 +00:00
|
|
|
"""create a shared user"""
|
2024-03-17 22:46:30 +00:00
|
|
|
with (
|
|
|
|
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
|
|
|
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
|
|
|
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
|
|
|
):
|
2024-03-17 23:52:20 +00:00
|
|
|
cls.user = models.User.objects.create_user(
|
2023-02-17 18:24:42 +00:00
|
|
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
|
|
|
)
|
2024-03-17 23:52:20 +00:00
|
|
|
cls.user.remote_id = "https://test-instance.org/user/critic"
|
|
|
|
cls.user.save(broadcast=False, update_fields=["remote_id"])
|
2023-02-17 18:24:42 +00:00
|
|
|
|
2024-03-17 23:52:20 +00:00
|
|
|
cls.book = models.Edition.objects.create(
|
2023-02-17 18:24:42 +00:00
|
|
|
title="Test Edition", remote_id="http://book.com/book"
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_to_model_hashtag_postprocess_content(self):
|
|
|
|
"""test that hashtag links are post-processed and link to local URLs"""
|
|
|
|
update_data = activitypub.Comment(
|
|
|
|
id="https://test-instance.org/user/critic/comment/42",
|
|
|
|
attributedTo=self.user.remote_id,
|
|
|
|
inReplyToBook=self.book.remote_id,
|
|
|
|
content="<p>This is interesting "
|
2023-02-17 23:18:32 +00:00
|
|
|
+ '<a href="https://test-instance.org/hashtag/2" data-mention="hashtag">'
|
2023-02-21 16:17:53 +00:00
|
|
|
+ "#bookclub</a></p>",
|
2023-02-17 18:24:42 +00:00
|
|
|
published="2023-02-17T23:12:59.398030+00:00",
|
|
|
|
to=[],
|
|
|
|
cc=[],
|
|
|
|
tag=[
|
|
|
|
{
|
|
|
|
"type": "Edition",
|
|
|
|
"name": "gerald j. books",
|
|
|
|
"href": "http://book.com/book",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "Hashtag",
|
|
|
|
"name": "#BookClub",
|
|
|
|
"href": "https://test-instance.org/hashtag/2",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
instance = update_data.to_model(model=models.Status)
|
|
|
|
self.assertIsNotNone(instance)
|
|
|
|
hashtag = models.Hashtag.objects.filter(name="#BookClub").first()
|
|
|
|
self.assertIsNotNone(hashtag)
|
|
|
|
self.assertEqual(
|
|
|
|
instance.content,
|
2023-02-17 23:18:32 +00:00
|
|
|
"<p>This is interesting "
|
|
|
|
+ f'<a href="{hashtag.remote_id}" data-mention="hashtag">'
|
2023-02-21 16:17:53 +00:00
|
|
|
+ "#bookclub</a></p>",
|
2023-02-17 18:24:42 +00:00
|
|
|
)
|