From ee96c01cc1c255fe8b7ac7d6af38e485e2a2a739 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 10 Jan 2021 19:39:54 -0800 Subject: [PATCH] Boost unit tests --- bookwyrm/outgoing.py | 2 +- bookwyrm/tests/test_outgoing.py | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/bookwyrm/outgoing.py b/bookwyrm/outgoing.py index b5f545ae..39369e70 100644 --- a/bookwyrm/outgoing.py +++ b/bookwyrm/outgoing.py @@ -360,7 +360,7 @@ def handle_unfavorite(user, status): if status.user.local: models.Notification.objects.filter( user=status.user, related_user=user, - status=status, notification_type='FAVORITE' + related_status=status, notification_type='FAVORITE' ).first().delete() diff --git a/bookwyrm/tests/test_outgoing.py b/bookwyrm/tests/test_outgoing.py index 93221464..9e7e6945 100644 --- a/bookwyrm/tests/test_outgoing.py +++ b/bookwyrm/tests/test_outgoing.py @@ -638,3 +638,53 @@ class Outgoing(TestCase): outgoing.handle_unfavorite(self.remote_user, status) self.assertEqual(models.Favorite.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0) + + + def test_handle_boost(self): + ''' boost a status ''' + status = models.Status.objects.create( + user=self.local_user, content='hi') + + with patch('bookwyrm.broadcast.broadcast_task.delay'): + outgoing.handle_boost(self.remote_user, status) + + boost = models.Boost.objects.get() + self.assertEqual(boost.boosted_status, status) + self.assertEqual(boost.user, self.remote_user) + self.assertEqual(boost.privacy, 'public') + + notification = models.Notification.objects.get() + self.assertEqual(notification.notification_type, 'BOOST') + self.assertEqual(notification.user, self.local_user) + self.assertEqual(notification.related_user, self.remote_user) + self.assertEqual(notification.related_status, status) + + def test_handle_boost_unlisted(self): + ''' boost a status ''' + status = models.Status.objects.create( + user=self.local_user, content='hi', privacy='unlisted') + + with patch('bookwyrm.broadcast.broadcast_task.delay'): + outgoing.handle_boost(self.remote_user, status) + + boost = models.Boost.objects.get() + self.assertEqual(boost.privacy, 'unlisted') + + def test_handle_boost_private(self): + ''' boost a status ''' + status = models.Status.objects.create( + user=self.local_user, content='hi', privacy='followers') + + with patch('bookwyrm.broadcast.broadcast_task.delay'): + outgoing.handle_boost(self.remote_user, status) + self.assertFalse(models.Boost.objects.exists()) + + def test_handle_boost_twice(self): + ''' boost a status ''' + status = models.Status.objects.create( + user=self.local_user, content='hi') + + with patch('bookwyrm.broadcast.broadcast_task.delay'): + outgoing.handle_boost(self.remote_user, status) + outgoing.handle_boost(self.remote_user, status) + self.assertEqual(models.Boost.objects.count(), 1)