mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-16 12:15:46 +00:00
tests set_related_field
This commit is contained in:
parent
ef2a07884f
commit
6b9db97ab8
1 changed files with 29 additions and 2 deletions
|
@ -11,7 +11,7 @@ import responses
|
|||
|
||||
from bookwyrm import activitypub
|
||||
from bookwyrm.activitypub.base_activity import ActivityObject, \
|
||||
find_existing_by_remote_id, resolve_remote_id
|
||||
find_existing_by_remote_id, resolve_remote_id, set_related_field
|
||||
from bookwyrm.activitypub import ActivitySerializerError
|
||||
from bookwyrm import models
|
||||
|
||||
|
@ -213,5 +213,32 @@ class BaseActivity(TestCase):
|
|||
body=self.image_data,
|
||||
status=200)
|
||||
|
||||
# sets the celery task call to the function call
|
||||
with patch(
|
||||
'bookwyrm.activitypub.base_activity.set_related_field.delay'):
|
||||
update_data.to_model(models.Status, instance=status)
|
||||
self.assertIsNone(status.attachments.first())
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_set_related_field(self):
|
||||
''' celery task to add back-references to created objects '''
|
||||
status = models.Status.objects.create(
|
||||
content='test status',
|
||||
user=self.user,
|
||||
)
|
||||
data = {
|
||||
'url': 'http://www.example.com/image.jpg',
|
||||
'name': 'alt text',
|
||||
'type': 'Image',
|
||||
}
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'http://www.example.com/image.jpg',
|
||||
body=self.image_data,
|
||||
status=200)
|
||||
set_related_field(
|
||||
'Image', 'Status', 'status', status.remote_id, data)
|
||||
|
||||
self.assertIsInstance(status.attachments.first(), models.Image)
|
||||
self.assertIsNotNone(status.attachments.first().image)
|
||||
|
|
Loading…
Reference in a new issue