forked from mirrors/bookwyrm
Fixes duplicate boost model verification
This commit is contained in:
parent
b457446f2f
commit
32e694032b
2 changed files with 14 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue