diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index e79314310..2d2e0ee18 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -227,7 +227,7 @@ class ActivitypubMixins(TestCase): # ObjectMixin - def test_object_save(self): + def test_object_save_create(self): ''' should save uneventufully when broadcast is disabled ''' class Success(Exception): ''' this means we got to the right method ''' @@ -247,10 +247,33 @@ class ActivitypubMixins(TestCase): with self.assertRaises(Success): ObjectModel(user=self.local_user).save() + ObjectModel(user=self.remote_user).save() ObjectModel(user=self.local_user).save(broadcast=False) ObjectModel(user=None).save() + def test_object_save_update(self): + ''' should save uneventufully when broadcast is disabled ''' + class Success(Exception): + ''' this means we got to the right method ''' + + class UpdateObjectModel(ObjectMixin, base_model.BookWyrmModel): + ''' real simple mock model because BookWyrmModel is abstract ''' + user = models.fields.ForeignKey('User', on_delete=db.models.CASCADE) + last_edited_by = models.fields.ForeignKey( + 'User', on_delete=db.models.CASCADE) + def save(self, *args, **kwargs): + with patch('django.db.models.Model.save'): + super().save(*args, **kwargs) + def to_update_activity(self, user): + raise Success() + + with self.assertRaises(Success): + UpdateObjectModel(id=1, user=self.local_user).save() + with self.assertRaises(Success): + UpdateObjectModel(id=1, last_edited_by=self.local_user).save() + + def test_object_save_delete(self): ''' should create delete activities when objects are deleted by flag ''' class ActivitySuccess(Exception):