2020-12-09 19:57:29 +00:00
|
|
|
''' quotation activty object serializer class '''
|
2020-09-17 20:02:52 +00:00
|
|
|
import json
|
|
|
|
import pathlib
|
2020-11-29 18:08:19 +00:00
|
|
|
from unittest.mock import patch
|
2020-09-17 20:02:52 +00:00
|
|
|
|
|
|
|
from django.test import TestCase
|
2020-09-21 15:10:37 +00:00
|
|
|
from bookwyrm import activitypub, models
|
2020-09-17 20:02:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Quotation(TestCase):
|
|
|
|
''' we have hecka ways to create statuses '''
|
|
|
|
def setUp(self):
|
2020-12-09 19:57:29 +00:00
|
|
|
''' model objects we'll need '''
|
2020-11-29 18:08:19 +00:00
|
|
|
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
|
|
|
self.user = models.User.objects.create_user(
|
|
|
|
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
|
|
|
local=False,
|
|
|
|
inbox='https://example.com/user/mouse/inbox',
|
|
|
|
outbox='https://example.com/user/mouse/outbox',
|
|
|
|
remote_id='https://example.com/user/mouse',
|
|
|
|
)
|
2020-09-17 20:02:52 +00:00
|
|
|
self.book = models.Edition.objects.create(
|
|
|
|
title='Example Edition',
|
|
|
|
remote_id='https://example.com/book/1',
|
|
|
|
)
|
|
|
|
datafile = pathlib.Path(__file__).parent.joinpath(
|
|
|
|
'../data/ap_quotation.json'
|
|
|
|
)
|
|
|
|
self.status_data = json.loads(datafile.read_bytes())
|
|
|
|
|
|
|
|
|
|
|
|
def test_quotation_activity(self):
|
2020-12-09 19:57:29 +00:00
|
|
|
''' create a Quoteation ap object from json '''
|
2020-09-17 20:02:52 +00:00
|
|
|
quotation = activitypub.Quotation(**self.status_data)
|
|
|
|
|
|
|
|
self.assertEqual(quotation.type, 'Quotation')
|
|
|
|
self.assertEqual(
|
|
|
|
quotation.id, 'https://example.com/user/mouse/quotation/13')
|
|
|
|
self.assertEqual(quotation.content, 'commentary')
|
|
|
|
self.assertEqual(quotation.quote, 'quote body')
|
|
|
|
self.assertEqual(quotation.inReplyToBook, 'https://example.com/book/1')
|
|
|
|
self.assertEqual(
|
|
|
|
quotation.published, '2020-05-10T02:38:31.150343+00:00')
|
|
|
|
|
|
|
|
|
|
|
|
def test_activity_to_model(self):
|
2020-12-09 19:57:29 +00:00
|
|
|
''' create a model instance from an activity object '''
|
2020-09-17 20:02:52 +00:00
|
|
|
activity = activitypub.Quotation(**self.status_data)
|
2021-02-17 04:17:38 +00:00
|
|
|
quotation = activity.to_model(model=models.Quotation)
|
2020-09-17 20:02:52 +00:00
|
|
|
|
|
|
|
self.assertEqual(quotation.book, self.book)
|
|
|
|
self.assertEqual(quotation.user, self.user)
|