fixes tests with broadcast kwarg

This commit is contained in:
Mouse Reeve 2021-02-09 12:48:46 -08:00
parent 25e8b3ddeb
commit 1d7cea2789
3 changed files with 36 additions and 28 deletions

View file

@ -234,7 +234,7 @@ class ActivitypubMixins(TestCase):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
with patch('django.db.models.Model.save'): with patch('django.db.models.Model.save'):
super().save(*args, **kwargs) super().save(*args, **kwargs)
def broadcast(self, activity, sender):#pylint: disable=arguments-differ def broadcast(self, activity, sender, **kwargs):#pylint: disable=arguments-differ
''' do something ''' ''' do something '''
raise Success() raise Success()
def to_create_activity(self, user):#pylint: disable=arguments-differ def to_create_activity(self, user):#pylint: disable=arguments-differ

View file

@ -19,7 +19,9 @@ class Shelf(TestCase):
def test_remote_id(self): def test_remote_id(self):
''' shelves use custom remote ids ''' ''' shelves use custom remote ids '''
real_broadcast = models.Shelf.broadcast real_broadcast = models.Shelf.broadcast
models.Shelf.broadcast = lambda x, y, z: None def broadcast_mock(_, activity, user, **kwargs):
''' nah '''
models.Shelf.broadcast = broadcast_mock
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
name='Test Shelf', identifier='test-shelf', name='Test Shelf', identifier='test-shelf',
user=self.local_user) user=self.local_user)
@ -31,7 +33,9 @@ class Shelf(TestCase):
def test_to_activity(self): def test_to_activity(self):
''' jsonify it ''' ''' jsonify it '''
real_broadcast = models.Shelf.broadcast real_broadcast = models.Shelf.broadcast
models.Shelf.broadcast = lambda x, y, z: None def empty_mock(_, activity, user, **kwargs):
''' nah '''
models.Shelf.broadcast = empty_mock
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
name='Test Shelf', identifier='test-shelf', name='Test Shelf', identifier='test-shelf',
user=self.local_user) user=self.local_user)
@ -48,7 +52,7 @@ class Shelf(TestCase):
def test_create_update_shelf(self): def test_create_update_shelf(self):
''' create and broadcast shelf creation ''' ''' create and broadcast shelf creation '''
real_broadcast = models.Shelf.broadcast real_broadcast = models.Shelf.broadcast
def create_mock(_, activity, user): def create_mock(_, activity, user, **kwargs):
''' ok ''' ''' ok '''
self.assertEqual(user.remote_id, self.local_user.remote_id) self.assertEqual(user.remote_id, self.local_user.remote_id)
self.assertEqual(activity['type'], 'Create') self.assertEqual(activity['type'], 'Create')
@ -59,7 +63,7 @@ class Shelf(TestCase):
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
name='Test Shelf', identifier='test-shelf', user=self.local_user) name='Test Shelf', identifier='test-shelf', user=self.local_user)
def update_mock(_, activity, user): def update_mock(_, activity, user, **kwargs):
''' ok ''' ''' ok '''
self.assertEqual(user.remote_id, self.local_user.remote_id) self.assertEqual(user.remote_id, self.local_user.remote_id)
self.assertEqual(activity['type'], 'Update') self.assertEqual(activity['type'], 'Update')
@ -78,7 +82,7 @@ class Shelf(TestCase):
real_broadcast = models.Shelf.broadcast real_broadcast = models.Shelf.broadcast
real_shelfbook_broadcast = models.ShelfBook.broadcast real_shelfbook_broadcast = models.ShelfBook.broadcast
def add_mock(_, activity, user): def add_mock(_, activity, user, **kwargs):
''' ok ''' ''' ok '''
self.assertEqual(user.remote_id, self.local_user.remote_id) self.assertEqual(user.remote_id, self.local_user.remote_id)
self.assertEqual(activity['type'], 'Add') self.assertEqual(activity['type'], 'Add')
@ -86,7 +90,7 @@ class Shelf(TestCase):
self.assertEqual(activity['object']['id'], self.book.remote_id) self.assertEqual(activity['object']['id'], self.book.remote_id)
self.assertEqual(activity['target'], shelf.remote_id) self.assertEqual(activity['target'], shelf.remote_id)
def remove_mock(_, activity, user): def remove_mock(_, activity, user, **kwargs):
''' ok ''' ''' ok '''
self.assertEqual(user.remote_id, self.local_user.remote_id) self.assertEqual(user.remote_id, self.local_user.remote_id)
self.assertEqual(activity['type'], 'Remove') self.assertEqual(activity['type'], 'Remove')
@ -94,7 +98,10 @@ class Shelf(TestCase):
self.assertEqual(activity['object']['id'], self.book.remote_id) self.assertEqual(activity['object']['id'], self.book.remote_id)
self.assertEqual(activity['target'], shelf.remote_id) self.assertEqual(activity['target'], shelf.remote_id)
models.Shelf.broadcast = lambda x, y, z: None def empty_mock(_, activity, user, **kwargs):
''' nah '''
models.Shelf.broadcast = empty_mock
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
name='Test Shelf', identifier='test-shelf', user=self.local_user) name='Test Shelf', identifier='test-shelf', user=self.local_user)

View file

@ -1,4 +1,5 @@
''' testing models ''' ''' testing models '''
from unittest.mock import patch
from io import BytesIO from io import BytesIO
import pathlib import pathlib
@ -11,6 +12,7 @@ from django.utils import timezone
from bookwyrm import models, settings from bookwyrm import models, settings
@patch('bookwyrm.models.Status.broadcast')
class Status(TestCase): class Status(TestCase):
''' lotta types of statuses ''' ''' lotta types of statuses '''
def setUp(self): def setUp(self):
@ -29,9 +31,8 @@ class Status(TestCase):
'test.jpg', 'test.jpg',
ContentFile(output.getvalue()) ContentFile(output.getvalue())
) )
models.Status.broadcast = lambda x, y, z: None
def test_status_generated_fields(self): def test_status_generated_fields(self, _):
''' setting remote id ''' ''' setting remote id '''
status = models.Status.objects.create(content='bleh', user=self.user) status = models.Status.objects.create(content='bleh', user=self.user)
expected_id = 'https://%s/user/mouse/status/%d' % \ expected_id = 'https://%s/user/mouse/status/%d' % \
@ -39,7 +40,7 @@ class Status(TestCase):
self.assertEqual(status.remote_id, expected_id) self.assertEqual(status.remote_id, expected_id)
self.assertEqual(status.privacy, 'public') self.assertEqual(status.privacy, 'public')
def test_replies(self): def test_replies(self, _):
''' get a list of replies ''' ''' get a list of replies '''
parent = models.Status.objects.create(content='hi', user=self.user) parent = models.Status.objects.create(content='hi', user=self.user)
child = models.Status.objects.create( child = models.Status.objects.create(
@ -55,7 +56,7 @@ class Status(TestCase):
# should select subclasses # should select subclasses
self.assertIsInstance(replies.last(), models.Review) self.assertIsInstance(replies.last(), models.Review)
def test_status_type(self): def test_status_type(self, _):
''' class name ''' ''' class name '''
self.assertEqual(models.Status().status_type, 'Note') self.assertEqual(models.Status().status_type, 'Note')
self.assertEqual(models.Review().status_type, 'Review') self.assertEqual(models.Review().status_type, 'Review')
@ -63,14 +64,14 @@ class Status(TestCase):
self.assertEqual(models.Comment().status_type, 'Comment') self.assertEqual(models.Comment().status_type, 'Comment')
self.assertEqual(models.Boost().status_type, 'Boost') self.assertEqual(models.Boost().status_type, 'Boost')
def test_boostable(self): def test_boostable(self, _):
''' can a status be boosted, based on privacy ''' ''' can a status be boosted, based on privacy '''
self.assertTrue(models.Status(privacy='public').boostable) self.assertTrue(models.Status(privacy='public').boostable)
self.assertTrue(models.Status(privacy='unlisted').boostable) self.assertTrue(models.Status(privacy='unlisted').boostable)
self.assertFalse(models.Status(privacy='followers').boostable) self.assertFalse(models.Status(privacy='followers').boostable)
self.assertFalse(models.Status(privacy='direct').boostable) self.assertFalse(models.Status(privacy='direct').boostable)
def test_to_replies(self): def test_to_replies(self, _):
''' activitypub replies collection ''' ''' activitypub replies collection '''
parent = models.Status.objects.create(content='hi', user=self.user) parent = models.Status.objects.create(content='hi', user=self.user)
child = models.Status.objects.create( child = models.Status.objects.create(
@ -84,7 +85,7 @@ class Status(TestCase):
self.assertEqual(replies['id'], '%s/replies' % parent.remote_id) self.assertEqual(replies['id'], '%s/replies' % parent.remote_id)
self.assertEqual(replies['totalItems'], 2) self.assertEqual(replies['totalItems'], 2)
def test_status_to_activity(self): def test_status_to_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Status.objects.create( status = models.Status.objects.create(
content='test content', user=self.user) content='test content', user=self.user)
@ -94,7 +95,7 @@ class Status(TestCase):
self.assertEqual(activity['content'], 'test content') self.assertEqual(activity['content'], 'test content')
self.assertEqual(activity['sensitive'], False) self.assertEqual(activity['sensitive'], False)
def test_status_to_activity_tombstone(self): def test_status_to_activity_tombstone(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Status.objects.create( status = models.Status.objects.create(
content='test content', user=self.user, content='test content', user=self.user,
@ -104,7 +105,7 @@ class Status(TestCase):
self.assertEqual(activity['type'], 'Tombstone') self.assertEqual(activity['type'], 'Tombstone')
self.assertFalse(hasattr(activity, 'content')) self.assertFalse(hasattr(activity, 'content'))
def test_status_to_pure_activity(self): def test_status_to_pure_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Status.objects.create( status = models.Status.objects.create(
content='test content', user=self.user) content='test content', user=self.user)
@ -115,7 +116,7 @@ class Status(TestCase):
self.assertEqual(activity['sensitive'], False) self.assertEqual(activity['sensitive'], False)
self.assertEqual(activity['attachment'], []) self.assertEqual(activity['attachment'], [])
def test_generated_note_to_activity(self): def test_generated_note_to_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.GeneratedNote.objects.create( status = models.GeneratedNote.objects.create(
content='test content', user=self.user) content='test content', user=self.user)
@ -128,7 +129,7 @@ class Status(TestCase):
self.assertEqual(activity['sensitive'], False) self.assertEqual(activity['sensitive'], False)
self.assertEqual(len(activity['tag']), 2) self.assertEqual(len(activity['tag']), 2)
def test_generated_note_to_pure_activity(self): def test_generated_note_to_pure_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.GeneratedNote.objects.create( status = models.GeneratedNote.objects.create(
content='test content', user=self.user) content='test content', user=self.user)
@ -150,7 +151,7 @@ class Status(TestCase):
self.assertEqual( self.assertEqual(
activity['attachment'][0].name, 'Test Edition cover') activity['attachment'][0].name, 'Test Edition cover')
def test_comment_to_activity(self): def test_comment_to_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Comment.objects.create( status = models.Comment.objects.create(
content='test content', user=self.user, book=self.book) content='test content', user=self.user, book=self.book)
@ -160,7 +161,7 @@ class Status(TestCase):
self.assertEqual(activity['content'], 'test content') self.assertEqual(activity['content'], 'test content')
self.assertEqual(activity['inReplyToBook'], self.book.remote_id) self.assertEqual(activity['inReplyToBook'], self.book.remote_id)
def test_comment_to_pure_activity(self): def test_comment_to_pure_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Comment.objects.create( status = models.Comment.objects.create(
content='test content', user=self.user, book=self.book) content='test content', user=self.user, book=self.book)
@ -177,7 +178,7 @@ class Status(TestCase):
self.assertEqual( self.assertEqual(
activity['attachment'][0].name, 'Test Edition cover') activity['attachment'][0].name, 'Test Edition cover')
def test_quotation_to_activity(self): def test_quotation_to_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Quotation.objects.create( status = models.Quotation.objects.create(
quote='a sickening sense', content='test content', quote='a sickening sense', content='test content',
@ -189,7 +190,7 @@ class Status(TestCase):
self.assertEqual(activity['content'], 'test content') self.assertEqual(activity['content'], 'test content')
self.assertEqual(activity['inReplyToBook'], self.book.remote_id) self.assertEqual(activity['inReplyToBook'], self.book.remote_id)
def test_quotation_to_pure_activity(self): def test_quotation_to_pure_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Quotation.objects.create( status = models.Quotation.objects.create(
quote='a sickening sense', content='test content', quote='a sickening sense', content='test content',
@ -207,7 +208,7 @@ class Status(TestCase):
self.assertEqual( self.assertEqual(
activity['attachment'][0].name, 'Test Edition cover') activity['attachment'][0].name, 'Test Edition cover')
def test_review_to_activity(self): def test_review_to_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Review.objects.create( status = models.Review.objects.create(
name='Review name', content='test content', rating=3, name='Review name', content='test content', rating=3,
@ -220,7 +221,7 @@ class Status(TestCase):
self.assertEqual(activity['content'], 'test content') self.assertEqual(activity['content'], 'test content')
self.assertEqual(activity['inReplyToBook'], self.book.remote_id) self.assertEqual(activity['inReplyToBook'], self.book.remote_id)
def test_review_to_pure_activity(self): def test_review_to_pure_activity(self, _):
''' subclass of the base model version with a "pure" serializer ''' ''' subclass of the base model version with a "pure" serializer '''
status = models.Review.objects.create( status = models.Review.objects.create(
name='Review name', content='test content', rating=3, name='Review name', content='test content', rating=3,
@ -238,7 +239,7 @@ class Status(TestCase):
self.assertEqual( self.assertEqual(
activity['attachment'][0].name, 'Test Edition cover') activity['attachment'][0].name, 'Test Edition cover')
def test_favorite(self): def test_favorite(self, _):
''' fav a status ''' ''' fav a status '''
real_broadcast = models.Favorite.broadcast real_broadcast = models.Favorite.broadcast
def fav_broadcast_mock(_, activity, user): def fav_broadcast_mock(_, activity, user):
@ -261,7 +262,7 @@ class Status(TestCase):
self.assertEqual(activity['object'], status.remote_id) self.assertEqual(activity['object'], status.remote_id)
models.Favorite.broadcast = real_broadcast models.Favorite.broadcast = real_broadcast
def test_boost(self): def test_boost(self, _):
''' boosting, this one's a bit fussy ''' ''' boosting, this one's a bit fussy '''
status = models.Status.objects.create( status = models.Status.objects.create(
content='test content', user=self.user) content='test content', user=self.user)
@ -273,7 +274,7 @@ class Status(TestCase):
self.assertEqual(activity['type'], 'Announce') self.assertEqual(activity['type'], 'Announce')
self.assertEqual(activity, boost.to_activity(pure=True)) self.assertEqual(activity, boost.to_activity(pure=True))
def test_notification(self): def test_notification(self, _):
''' a simple model ''' ''' a simple model '''
notification = models.Notification.objects.create( notification = models.Notification.objects.create(
user=self.user, notification_type='FAVORITE') user=self.user, notification_type='FAVORITE')