mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Merge pull request #1929 from bookwyrm-social/link-federation
Use correct model type for federated links
This commit is contained in:
commit
542957364c
4 changed files with 11 additions and 3 deletions
|
@ -227,7 +227,7 @@ def set_related_field(
|
||||||
model_field = getattr(model, related_field_name)
|
model_field = getattr(model, related_field_name)
|
||||||
if hasattr(model_field, "activitypub_field"):
|
if hasattr(model_field, "activitypub_field"):
|
||||||
setattr(activity, getattr(model_field, "activitypub_field"), instance.remote_id)
|
setattr(activity, getattr(model_field, "activitypub_field"), instance.remote_id)
|
||||||
item = activity.to_model()
|
item = activity.to_model(model=model)
|
||||||
|
|
||||||
# if the related field isn't serialized (attachments on Status), then
|
# if the related field isn't serialized (attachments on Status), then
|
||||||
# we have to set it post-creation
|
# we have to set it post-creation
|
||||||
|
@ -298,6 +298,7 @@ class Link(ActivityObject):
|
||||||
mediaType: str = None
|
mediaType: str = None
|
||||||
id: str = None
|
id: str = None
|
||||||
attributedTo: str = None
|
attributedTo: str = None
|
||||||
|
availability: str = None
|
||||||
type: str = "Link"
|
type: str = "Link"
|
||||||
|
|
||||||
def serialize(self, **kwargs):
|
def serialize(self, **kwargs):
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
""" testing models """
|
""" testing models """
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
|
||||||
from imagekit.models import ImageSpecField
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,15 @@ class LinkViews(TestCase):
|
||||||
activity = json.loads(mock.call_args[1]["args"][1])
|
activity = json.loads(mock.call_args[1]["args"][1])
|
||||||
self.assertEqual(activity["type"], "Update")
|
self.assertEqual(activity["type"], "Update")
|
||||||
self.assertEqual(activity["object"]["type"], "Edition")
|
self.assertEqual(activity["object"]["type"], "Edition")
|
||||||
|
self.assertIsInstance(activity["object"]["fileLinks"], list)
|
||||||
|
self.assertEqual(
|
||||||
|
activity["object"]["fileLinks"][0]["href"], "https://www.example.com"
|
||||||
|
)
|
||||||
|
self.assertEqual(activity["object"]["fileLinks"][0]["mediaType"], "HTML")
|
||||||
|
self.assertEqual(
|
||||||
|
activity["object"]["fileLinks"][0]["attributedTo"],
|
||||||
|
self.local_user.remote_id,
|
||||||
|
)
|
||||||
|
|
||||||
link = models.FileLink.objects.get()
|
link = models.FileLink.objects.get()
|
||||||
self.assertEqual(link.name, "www.example.com")
|
self.assertEqual(link.name, "www.example.com")
|
||||||
|
|
|
@ -6,7 +6,6 @@ from unittest.mock import patch
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from bookwyrm import models, views
|
from bookwyrm import models, views
|
||||||
from bookwyrm.activitypub.base_activity import set_related_field
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
|
|
Loading…
Reference in a new issue