From 1cf4c0d5cc632918cbb479b272ec11700a09facc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 23 Mar 2021 08:27:24 -0700 Subject: [PATCH] Mocks redis in interaction tests --- bookwyrm/tests/views/test_interaction.py | 35 ++++++++++++------------ bookwyrm/tests/views/test_isbn.py | 2 -- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index 857f7061..b52e9a66 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -5,7 +5,7 @@ from django.test.client import RequestFactory from bookwyrm import models, views - +@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") class InteractionViews(TestCase): """ viewing and creating statuses """ @@ -38,12 +38,12 @@ class InteractionViews(TestCase): parent_work=work, ) - def test_handle_favorite(self): + def test_handle_favorite(self, _): """ create and broadcast faving a status """ view = views.Favorite.as_view() request = self.factory.post("") request.user = self.remote_user - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): status = models.Status.objects.create(user=self.local_user, content="hi") view(request, status.id) @@ -56,12 +56,12 @@ class InteractionViews(TestCase): self.assertEqual(notification.user, self.local_user) self.assertEqual(notification.related_user, self.remote_user) - def test_handle_unfavorite(self): + def test_handle_unfavorite(self, _): """ unfav a status """ view = views.Unfavorite.as_view() request = self.factory.post("") request.user = self.remote_user - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): status = models.Status.objects.create(user=self.local_user, content="hi") views.Favorite.as_view()(request, status.id) @@ -73,12 +73,12 @@ class InteractionViews(TestCase): self.assertEqual(models.Favorite.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0) - def test_handle_boost(self): + def test_handle_boost(self, _): """ boost a status """ view = views.Boost.as_view() request = self.factory.post("") request.user = self.remote_user - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): status = models.Status.objects.create(user=self.local_user, content="hi") view(request, status.id) @@ -94,12 +94,12 @@ class InteractionViews(TestCase): self.assertEqual(notification.related_user, self.remote_user) self.assertEqual(notification.related_status, status) - def test_handle_boost_unlisted(self): + def test_handle_boost_unlisted(self, _): """ boost a status """ view = views.Boost.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): status = models.Status.objects.create( user=self.local_user, content="hi", privacy="unlisted" ) @@ -109,12 +109,12 @@ class InteractionViews(TestCase): boost = models.Boost.objects.get() self.assertEqual(boost.privacy, "unlisted") - def test_handle_boost_private(self): + def test_handle_boost_private(self, _): """ boost a status """ view = views.Boost.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): status = models.Status.objects.create( user=self.local_user, content="hi", privacy="followers" ) @@ -122,31 +122,32 @@ class InteractionViews(TestCase): view(request, status.id) self.assertFalse(models.Boost.objects.exists()) - def test_handle_boost_twice(self): + def test_handle_boost_twice(self, _): """ boost a status """ view = views.Boost.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): status = models.Status.objects.create(user=self.local_user, content="hi") view(request, status.id) view(request, status.id) self.assertEqual(models.Boost.objects.count(), 1) - def test_handle_unboost(self): + def test_handle_unboost(self, broadcast_mock): """ undo a boost """ view = views.Unboost.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): status = models.Status.objects.create(user=self.local_user, content="hi") views.Boost.as_view()(request, status.id) self.assertEqual(models.Boost.objects.count(), 1) self.assertEqual(models.Notification.objects.count(), 1) - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: + broadcast_mock.call_count = 0 + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): view(request, status.id) - self.assertEqual(mock.call_count, 1) + self.assertEqual(broadcast_mock.call_count, 1) self.assertEqual(models.Boost.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0) diff --git a/bookwyrm/tests/views/test_isbn.py b/bookwyrm/tests/views/test_isbn.py index c7ae1f39..7f03a610 100644 --- a/bookwyrm/tests/views/test_isbn.py +++ b/bookwyrm/tests/views/test_isbn.py @@ -3,12 +3,10 @@ import json from unittest.mock import patch from django.http import JsonResponse -from django.template.response import TemplateResponse from django.test import TestCase from django.test.client import RequestFactory from bookwyrm import models, views -from bookwyrm.connectors import abstract_connector from bookwyrm.settings import DOMAIN