def test_to_model_many_to_many(self, _): """annoying that these all need special handling""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): status = models.Status.objects.create( content="test status", user=self.user, ) book = models.Edition.objects.create(title="Test Edition", remote_id="http://book.com/book") update_data = activitypub.Note( id=status.remote_id, content=status.content, attributedTo=self.user.remote_id, published="hi", to=[], cc=[], tag=[ { "type": "Mention", "name": "gerald", "href": "http://example.com/a/b" }, { "type": "Edition", "name": "gerald j. books", "href": "http://book.com/book", }, ], ) update_data.to_model(model=models.Status, instance=status) self.assertEqual(status.mention_users.first(), self.user) self.assertEqual(status.mention_books.first(), book)
def test_to_model_many_to_many(self): ''' annoying that these all need special handling ''' with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'): status = models.Status.objects.create( content='test status', user=self.user, ) book = models.Edition.objects.create(title='Test Edition', remote_id='http://book.com/book') update_data = activitypub.Note(id=status.remote_id, content=status.content, attributedTo=self.user.remote_id, published='hi', to=[], cc=[], tag=[ { 'type': 'Mention', 'name': 'gerald', 'href': 'http://example.com/a/b' }, { 'type': 'Edition', 'name': 'gerald j. books', 'href': 'http://book.com/book' }, ]) update_data.to_model(models.Status, instance=status) self.assertEqual(status.mention_users.first(), self.user) self.assertEqual(status.mention_books.first(), book)
def test_to_model_one_to_many(self): ''' these are reversed relationships, where the secondary object keys the primary object but not vice versa ''' with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'): status = models.Status.objects.create( content='test status', user=self.user, ) update_data = activitypub.Note( id=status.remote_id, content=status.content, attributedTo=self.user.remote_id, published='hi', to=[], cc=[], attachment=[{ '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) # 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())
def test_to_model_one_to_many(self, _): """these are reversed relationships, where the secondary object keys the primary object but not vice versa""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): status = models.Status.objects.create( content="test status", user=self.user, ) update_data = activitypub.Note( id=status.remote_id, content=status.content, attributedTo=self.user.remote_id, published="hi", to=[], cc=[], attachment=[{ "url": "http://www.example.com/image.jpg", "name": "alt text", "type": "Document", }], ) responses.add( responses.GET, "http://www.example.com/image.jpg", 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"): with patch("bookwyrm.models.status.Status.ignore_activity" ) as discarder: discarder.return_value = False update_data.to_model(model=models.Status, instance=status) self.assertIsNone(status.attachments.first())
def test_to_model_many_to_many(self): ''' annoying that these all need special handling ''' status = models.Status.objects.create( content='test status', user=self.user, ) book = models.Edition.objects.create(title='Test Edition', remote_id='http://book.com/book') update_data = activitypub.Note(**status.to_activity()) update_data.tag = [ { 'type': 'Mention', 'name': 'gerald', 'href': 'http://example.com/a/b' }, { 'type': 'Edition', 'name': 'gerald j. books', 'href': 'http://book.com/book' }, ] update_data.to_model(models.Status, instance=status) self.assertEqual(status.mention_users.first(), self.user) self.assertEqual(status.mention_books.first(), book)