From 32e694032b2f4d24623da0d25db1e7744efc08c8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 23 Apr 2021 10:49:17 -0700 Subject: [PATCH] Fixes duplicate boost model verification --- bookwyrm/models/status.py | 2 +- .../tests/views/inbox/test_inbox_announce.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 65bf71d28..3784680fb 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -356,7 +356,7 @@ class Boost(ActivityMixin, Status): # unique_together = ('user', 'boosted_status') if Boost.objects.filter( boosted_status=self.boosted_status, user=self.user - ).exists(): + ).exclude(id=self.id).exists(): return super().save(*args, **kwargs) diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index 954d4e647..dbe4ec568 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -51,7 +51,7 @@ class InboxActivities(TestCase): models.SiteSettings.objects.create() @patch("bookwyrm.activitystreams.ActivityStream.add_status") - def test_handle_boost(self, _): + def test_boost(self, redis_mock): """ boost a status """ self.assertEqual(models.Notification.objects.count(), 0) activity = { @@ -66,16 +66,23 @@ class InboxActivities(TestCase): with patch("bookwyrm.models.status.Status.ignore_activity") as discarder: discarder.return_value = False views.inbox.activity_task(activity) + + # boost added to redis activitystreams + self.assertTrue(redis_mock.called) + + # boost created of correct status boost = models.Boost.objects.get() self.assertEqual(boost.boosted_status, self.status) + + # notification sent to original poster notification = models.Notification.objects.get() self.assertEqual(notification.user, self.local_user) self.assertEqual(notification.related_status, self.status) @responses.activate @patch("bookwyrm.activitystreams.ActivityStream.add_status") - def test_handle_boost_remote_status(self, redis_mock): - """ boost a status """ + def test_boost_remote_status(self, redis_mock): + """ boost a status from a remote server """ work = models.Work.objects.create(title="work title") book = models.Edition.objects.create( title="Test", @@ -123,7 +130,7 @@ class InboxActivities(TestCase): self.assertEqual(boost.boosted_status.comment.book, book) @responses.activate - def test_handle_discarded_boost(self): + def test_discarded_boost(self): """ test a boost of a mastodon status that will be discarded """ status = models.Status( content="hi", @@ -146,7 +153,7 @@ class InboxActivities(TestCase): views.inbox.activity_task(activity) self.assertEqual(models.Boost.objects.count(), 0) - def test_handle_unboost(self): + def test_unboost(self): """ undo a boost """ with patch("bookwyrm.activitystreams.ActivityStream.add_status"): boost = models.Boost.objects.create( @@ -175,7 +182,7 @@ class InboxActivities(TestCase): self.assertTrue(redis_mock.called) self.assertFalse(models.Boost.objects.exists()) - def test_handle_unboost_unknown_boost(self): + def test_unboost_unknown_boost(self): """ undo a boost """ activity = { "type": "Undo",