From 28651bd8042883118bfa61d9aea64f1073950697 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 23 Mar 2021 11:27:00 -0700 Subject: [PATCH] Fixes views tests --- bookwyrm/tests/views/test_goal.py | 3 +- bookwyrm/tests/views/test_interaction.py | 6 +++- bookwyrm/tests/views/test_landing.py | 4 ++- bookwyrm/tests/views/test_reading.py | 13 +++++---- bookwyrm/tests/views/test_rss_feed.py | 36 +++++++++++++----------- bookwyrm/tests/views/test_status.py | 1 - 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/bookwyrm/tests/views/test_goal.py b/bookwyrm/tests/views/test_goal.py index 990bb5c2..cbe4fe01 100644 --- a/bookwyrm/tests/views/test_goal.py +++ b/bookwyrm/tests/views/test_goal.py @@ -102,7 +102,8 @@ class GoalViews(TestCase): result = view(request, self.local_user.localname, 2020) self.assertEqual(result.status_code, 404) - def test_create_goal(self): + @patch("bookwyrm.activitystreams.ActivityStream.add_status") + def test_create_goal(self, _): """ create a new goal """ view = views.Goal.as_view() request = self.factory.post( diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index b52e9a66..40152c0f 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -5,6 +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 """ @@ -146,8 +147,11 @@ class InteractionViews(TestCase): self.assertEqual(models.Boost.objects.count(), 1) self.assertEqual(models.Notification.objects.count(), 1) broadcast_mock.call_count = 0 - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch( + "bookwyrm.activitystreams.ActivityStream.remove_status" + ) as redis_mock: view(request, status.id) self.assertEqual(broadcast_mock.call_count, 1) + self.assertTrue(redis_mock.called) self.assertEqual(models.Boost.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0) diff --git a/bookwyrm/tests/views/test_landing.py b/bookwyrm/tests/views/test_landing.py index 910e4a85..2513fecc 100644 --- a/bookwyrm/tests/views/test_landing.py +++ b/bookwyrm/tests/views/test_landing.py @@ -1,4 +1,5 @@ """ test for app action functionality """ +from unittest.mock import patch from django.contrib.auth.models import AnonymousUser from django.template.response import TemplateResponse from django.test import TestCase @@ -30,7 +31,8 @@ class LandingViews(TestCase): view = views.Home.as_view() request = self.factory.get("") request.user = self.local_user - result = view(request) + with patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream"): + result = view(request) self.assertEqual(result.status_code, 200) result.render() diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index 96d1f1f4..4661e487 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -8,6 +8,7 @@ from django.utils import timezone from bookwyrm import models, views +@patch("bookwyrm.activitystreams.ActivityStream.add_status") class ReadingViews(TestCase): """ viewing and creating statuses """ @@ -39,7 +40,7 @@ class ReadingViews(TestCase): outbox="https://example.com/users/rat/outbox", ) - def test_start_reading(self): + def test_start_reading(self, _): """ begin a book """ shelf = self.local_user.shelf_set.get(identifier="reading") self.assertFalse(shelf.books.exists()) @@ -70,7 +71,7 @@ class ReadingViews(TestCase): self.assertEqual(readthrough.user, self.local_user) self.assertEqual(readthrough.book, self.book) - def test_start_reading_reshelf(self): + def test_start_reading_reshelf(self, _): """ begin a book """ to_read_shelf = self.local_user.shelf_set.get(identifier="to-read") with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): @@ -90,7 +91,7 @@ class ReadingViews(TestCase): self.assertFalse(to_read_shelf.books.exists()) self.assertEqual(shelf.books.get(), self.book) - def test_finish_reading(self): + def test_finish_reading(self, _): """ begin a book """ shelf = self.local_user.shelf_set.get(identifier="read") self.assertFalse(shelf.books.exists()) @@ -126,7 +127,7 @@ class ReadingViews(TestCase): self.assertEqual(readthrough.user, self.local_user) self.assertEqual(readthrough.book, self.book) - def test_edit_readthrough(self): + def test_edit_readthrough(self, _): """ adding dates to an ongoing readthrough """ start = timezone.make_aware(dateutil.parser.parse("2021-01-03")) readthrough = models.ReadThrough.objects.create( @@ -153,7 +154,7 @@ class ReadingViews(TestCase): self.assertEqual(readthrough.finish_date.day, 7) self.assertEqual(readthrough.book, self.book) - def test_delete_readthrough(self): + def test_delete_readthrough(self, _): """ remove a readthrough """ readthrough = models.ReadThrough.objects.create( book=self.book, user=self.local_user @@ -170,7 +171,7 @@ class ReadingViews(TestCase): views.delete_readthrough(request) self.assertFalse(models.ReadThrough.objects.filter(id=readthrough.id).exists()) - def test_create_readthrough(self): + def test_create_readthrough(self, _): """ adding new read dates """ request = self.factory.post( "", diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index c7fef2a9..0230b4a9 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -26,28 +26,30 @@ class RssFeedView(TestCase): ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): - self.review = models.Review.objects.create( - name="Review name", - content="test content", - rating=3, - user=self.user, - book=self.book, - ) + with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + self.review = models.Review.objects.create( + name="Review name", + content="test content", + rating=3, + user=self.user, + book=self.book, + ) - self.quote = models.Quotation.objects.create( - quote="a sickening sense", - content="test content", - user=self.user, - book=self.book, - ) + self.quote = models.Quotation.objects.create( + quote="a sickening sense", + content="test content", + user=self.user, + book=self.book, + ) - self.generatednote = models.GeneratedNote.objects.create( - content="test content", user=self.user - ) + self.generatednote = models.GeneratedNote.objects.create( + content="test content", user=self.user + ) self.factory = RequestFactory() - def test_rss_feed(self): + @patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream") + def test_rss_feed(self, _): """ load an rss feed """ view = rss_feed.RssFeed() request = self.factory.get("/user/rss_user/rss") diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index 2a612850..5dc0e49a 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -159,7 +159,6 @@ class StatusViews(TestCase): view(request, "reply") self.assertTrue(redis_mock.called) - reply = models.Status.replies(status).first() self.assertEqual(reply.content, "

right

") self.assertEqual(reply.user, user)