mocks mocks more mocks

This commit is contained in:
Mouse Reeve 2021-09-06 16:59:58 -07:00
parent db34918347
commit 59400511c9
15 changed files with 75 additions and 86 deletions

View file

@ -23,7 +23,7 @@ def make_date(*args):
# pylint: disable=consider-using-with # pylint: disable=consider-using-with
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
class GoodreadsImport(TestCase): class GoodreadsImport(TestCase):
"""importing from goodreads csv""" """importing from goodreads csv"""

View file

@ -22,6 +22,7 @@ def make_date(*args):
# pylint: disable=consider-using-with # pylint: disable=consider-using-with
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
class LibrarythingImport(TestCase): class LibrarythingImport(TestCase):
"""importing from librarything tsv""" """importing from librarything tsv"""

View file

@ -6,6 +6,7 @@ from django.test import TestCase
from bookwyrm import models from bookwyrm import models
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
class Relationship(TestCase): class Relationship(TestCase):
"""following, blocking, stuff like that""" """following, blocking, stuff like that"""
@ -30,7 +31,7 @@ class Relationship(TestCase):
self.local_user.remote_id = "http://local.com/user/mouse" self.local_user.remote_id = "http://local.com/user/mouse"
self.local_user.save(broadcast=False, update_fields=["remote_id"]) self.local_user.save(broadcast=False, update_fields=["remote_id"])
def test_user_follows_from_request(self): def test_user_follows_from_request(self, _):
"""convert a follow request into a follow""" """convert a follow request into a follow"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock:
request = models.UserFollowRequest.objects.create( request = models.UserFollowRequest.objects.create(
@ -51,7 +52,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_subject, self.local_user) self.assertEqual(rel.user_subject, self.local_user)
self.assertEqual(rel.user_object, self.remote_user) self.assertEqual(rel.user_object, self.remote_user)
def test_user_follows_from_request_custom_remote_id(self): def test_user_follows_from_request_custom_remote_id(self, _):
"""store a specific remote id for a relationship provided by remote""" """store a specific remote id for a relationship provided by remote"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
request = models.UserFollowRequest.objects.create( request = models.UserFollowRequest.objects.create(
@ -69,7 +70,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_object, self.remote_user) self.assertEqual(rel.user_object, self.remote_user)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
def test_follow_request_activity(self, broadcast_mock): def test_follow_request_activity(self, broadcast_mock, _):
"""accept a request and make it a relationship""" """accept a request and make it a relationship"""
models.UserFollowRequest.objects.create( models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_subject=self.local_user,
@ -81,7 +82,7 @@ class Relationship(TestCase):
self.assertEqual(activity["type"], "Follow") self.assertEqual(activity["type"], "Follow")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
def test_follow_request_accept(self, broadcast_mock): def test_follow_request_accept(self, broadcast_mock, _):
"""accept a request and make it a relationship""" """accept a request and make it a relationship"""
self.local_user.manually_approves_followers = True self.local_user.manually_approves_followers = True
self.local_user.save( self.local_user.save(
@ -107,7 +108,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_object, self.local_user) self.assertEqual(rel.user_object, self.local_user)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
def test_follow_request_reject(self, broadcast_mock): def test_follow_request_reject(self, broadcast_mock, _):
"""accept a request and make it a relationship""" """accept a request and make it a relationship"""
self.local_user.manually_approves_followers = True self.local_user.manually_approves_followers = True
self.local_user.save( self.local_user.save(

View file

@ -9,6 +9,7 @@ from bookwyrm import models, settings
# pylint: disable=unused-argument # pylint: disable=unused-argument
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
class Shelf(TestCase): class Shelf(TestCase):
"""some activitypub oddness ahead""" """some activitypub oddness ahead"""

View file

@ -16,7 +16,7 @@ from bookwyrm import activitypub, models, settings
# pylint: disable=too-many-public-methods # pylint: disable=too-many-public-methods
@patch("bookwyrm.models.Status.broadcast") @patch("bookwyrm.models.Status.broadcast")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.remove_status_task.delay")
class Status(TestCase): class Status(TestCase):
"""lotta types of statuses""" """lotta types of statuses"""
@ -120,9 +120,6 @@ class Status(TestCase):
def test_status_to_activity_tombstone(self, *_): def test_status_to_activity_tombstone(self, *_):
"""subclass of the base model version with a "pure" serializer""" """subclass of the base model version with a "pure" serializer"""
with patch(
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
):
status = models.Status.objects.create( status = models.Status.objects.create(
content="test content", content="test content",
user=self.local_user, user=self.local_user,

View file

@ -13,6 +13,7 @@ from bookwyrm.suggested_users import suggested_users, get_annotated_users
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.suggested_users.rerank_user_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay")
@patch("bookwyrm.suggested_users.remove_user_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay")
class SuggestedUsers(TestCase): class SuggestedUsers(TestCase):

View file

@ -16,7 +16,7 @@ from bookwyrm.templatetags import (
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.remove_status_task.delay")
class TemplateTags(TestCase): class TemplateTags(TestCase):
"""lotta different things here""" """lotta different things here"""
@ -75,9 +75,6 @@ class TemplateTags(TestCase):
second_child = models.Status.objects.create( second_child = models.Status.objects.create(
reply_parent=parent, user=self.user, content="hi" reply_parent=parent, user=self.user, content="hi"
) )
with patch(
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
):
third_child = models.Status.objects.create( third_child = models.Status.objects.create(
reply_parent=parent, reply_parent=parent,
user=self.user, user=self.user,

View file

@ -11,6 +11,7 @@ from bookwyrm.activitypub import ActivitySerializerError
# pylint: disable=too-many-public-methods # pylint: disable=too-many-public-methods
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
class InboxCreate(TestCase): class InboxCreate(TestCase):
"""readthrough tests""" """readthrough tests"""
@ -49,7 +50,6 @@ class InboxCreate(TestCase):
} }
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
@patch("bookwyrm.activitystreams.add_status_task.delay")
def test_create_status(self, *_): def test_create_status(self, *_):
"""the "it justs works" mode""" """the "it justs works" mode"""
datafile = pathlib.Path(__file__).parent.joinpath( datafile = pathlib.Path(__file__).parent.joinpath(
@ -63,9 +63,7 @@ class InboxCreate(TestCase):
activity = self.create_json activity = self.create_json
activity["object"] = status_data activity["object"] = status_data
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertTrue(redis_mock.called)
status = models.Quotation.objects.get() status = models.Quotation.objects.get()
self.assertEqual( self.assertEqual(
@ -79,7 +77,6 @@ class InboxCreate(TestCase):
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertEqual(models.Status.objects.count(), 1) self.assertEqual(models.Status.objects.count(), 1)
@patch("bookwyrm.activitystreams.add_status_task.delay")
def test_create_comment_with_reading_status(self, *_): def test_create_comment_with_reading_status(self, *_):
"""the "it justs works" mode""" """the "it justs works" mode"""
datafile = pathlib.Path(__file__).parent.joinpath("../../data/ap_comment.json") datafile = pathlib.Path(__file__).parent.joinpath("../../data/ap_comment.json")
@ -92,9 +89,7 @@ class InboxCreate(TestCase):
activity = self.create_json activity = self.create_json
activity["object"] = status_data activity["object"] = status_data
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertTrue(redis_mock.called)
status = models.Comment.objects.get() status = models.Comment.objects.get()
self.assertEqual(status.remote_id, "https://example.com/user/mouse/comment/6") self.assertEqual(status.remote_id, "https://example.com/user/mouse/comment/6")
@ -106,7 +101,7 @@ class InboxCreate(TestCase):
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertEqual(models.Status.objects.count(), 1) self.assertEqual(models.Status.objects.count(), 1)
def test_create_status_remote_note_with_mention(self, _): def test_create_status_remote_note_with_mention(self, *_):
"""should only create it under the right circumstances""" """should only create it under the right circumstances"""
self.assertFalse( self.assertFalse(
models.Notification.objects.filter(user=self.local_user).exists() models.Notification.objects.filter(user=self.local_user).exists()
@ -117,9 +112,8 @@ class InboxCreate(TestCase):
activity = self.create_json activity = self.create_json
activity["object"] = status_data activity["object"] = status_data
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertTrue(redis_mock.called)
status = models.Status.objects.last() status = models.Status.objects.last()
self.assertEqual(status.content, "test content in note") self.assertEqual(status.content, "test content in note")
self.assertEqual(status.mention_users.first(), self.local_user) self.assertEqual(status.mention_users.first(), self.local_user)
@ -128,9 +122,8 @@ class InboxCreate(TestCase):
) )
self.assertEqual(models.Notification.objects.get().notification_type, "MENTION") self.assertEqual(models.Notification.objects.get().notification_type, "MENTION")
def test_create_status_remote_note_with_reply(self, _): def test_create_status_remote_note_with_reply(self, *_):
"""should only create it under the right circumstances""" """should only create it under the right circumstances"""
with patch("bookwyrm.activitystreams.add_status_task.delay"):
parent_status = models.Status.objects.create( parent_status = models.Status.objects.create(
user=self.local_user, user=self.local_user,
content="Test status", content="Test status",
@ -147,16 +140,14 @@ class InboxCreate(TestCase):
activity = self.create_json activity = self.create_json
activity["object"] = status_data activity["object"] = status_data
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertTrue(redis_mock.called)
status = models.Status.objects.last() status = models.Status.objects.last()
self.assertEqual(status.content, "test content in note") self.assertEqual(status.content, "test content in note")
self.assertEqual(status.reply_parent, parent_status) self.assertEqual(status.reply_parent, parent_status)
self.assertTrue(models.Notification.objects.filter(user=self.local_user)) self.assertTrue(models.Notification.objects.filter(user=self.local_user))
self.assertEqual(models.Notification.objects.get().notification_type, "REPLY") self.assertEqual(models.Notification.objects.get().notification_type, "REPLY")
def test_create_rating(self, _): def test_create_rating(self, *_):
"""a remote rating activity""" """a remote rating activity"""
book = models.Edition.objects.create( book = models.Edition.objects.create(
title="Test Book", remote_id="https://example.com/book/1" title="Test Book", remote_id="https://example.com/book/1"
@ -186,14 +177,12 @@ class InboxCreate(TestCase):
"rating": 3, "rating": 3,
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
} }
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertTrue(redis_mock.called)
rating = models.ReviewRating.objects.first() rating = models.ReviewRating.objects.first()
self.assertEqual(rating.book, book) self.assertEqual(rating.book, book)
self.assertEqual(rating.rating, 3.0) self.assertEqual(rating.rating, 3.0)
def test_create_list(self, _): def test_create_list(self, *_):
"""a new list""" """a new list"""
activity = self.create_json activity = self.create_json
activity["object"] = { activity["object"] = {
@ -217,7 +206,7 @@ class InboxCreate(TestCase):
self.assertEqual(book_list.description, "summary text") self.assertEqual(book_list.description, "summary text")
self.assertEqual(book_list.remote_id, "https://example.com/list/22") self.assertEqual(book_list.remote_id, "https://example.com/list/22")
def test_create_unsupported_type(self, _): def test_create_unsupported_type(self, *_):
"""ignore activities we know we can't handle""" """ignore activities we know we can't handle"""
activity = self.create_json activity = self.create_json
activity["object"] = { activity["object"] = {
@ -227,7 +216,7 @@ class InboxCreate(TestCase):
# just observer how it doesn't throw an error # just observer how it doesn't throw an error
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
def test_create_unknown_type(self, _): def test_create_unknown_type(self, *_):
"""ignore activities we know we've never heard of""" """ignore activities we know we've never heard of"""
activity = self.create_json activity = self.create_json
activity["object"] = { activity["object"] = {

View file

@ -59,7 +59,7 @@ class BlockViews(TestCase):
request = self.factory.post("") request = self.factory.post("")
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.activitystreams.ActivityStream.remove_user_statuses"): with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
view(request, self.remote_user.id) view(request, self.remote_user.id)
block = models.UserBlocks.objects.get() block = models.UserBlocks.objects.get()
self.assertEqual(block.user_subject, self.local_user) self.assertEqual(block.user_subject, self.local_user)
@ -74,7 +74,7 @@ class BlockViews(TestCase):
request = self.factory.post("") request = self.factory.post("")
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.activitystreams.ActivityStream.add_user_statuses"): with patch("bookwyrm.activitystreams.add_user_statuses_task.delay"):
views.block.unblock(request, self.remote_user.id) views.block.unblock(request, self.remote_user.id)
self.assertFalse(models.UserBlocks.objects.exists()) self.assertFalse(models.UserBlocks.objects.exists())

View file

@ -39,7 +39,9 @@ class EditUserViews(TestCase):
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="test", parent_work=models.Work.objects.create(title="test work") title="test", parent_work=models.Work.objects.create(title="test work")
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"), patch(
"bookwyrm.activitystreams.add_book_statuses_task.delay"
):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
book=self.book, book=self.book,
user=self.local_user, user=self.local_user,

View file

@ -172,9 +172,10 @@ class FeedViews(TestCase):
result.render() result.render()
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
def test_get_suggested_book(self, *_): def test_get_suggested_book(self, *_):
"""gets books the ~*~ algorithm ~*~ thinks you want to post about""" """gets books the ~*~ algorithm ~*~ thinks you want to post about"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
book=self.book, book=self.book,
user=self.local_user, user=self.local_user,

View file

@ -10,6 +10,7 @@ from django.test.client import RequestFactory
from bookwyrm import models, views from bookwyrm import models, views
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
class FollowViews(TestCase): class FollowViews(TestCase):
"""follows""" """follows"""
@ -52,7 +53,7 @@ class FollowViews(TestCase):
parent_work=self.work, parent_work=self.work,
) )
def test_handle_follow_remote(self): def test_handle_follow_remote(self, _):
"""send a follow request""" """send a follow request"""
request = self.factory.post("", {"user": self.remote_user.username}) request = self.factory.post("", {"user": self.remote_user.username})
request.user = self.local_user request.user = self.local_user
@ -67,7 +68,7 @@ class FollowViews(TestCase):
self.assertEqual(rel.user_object, self.remote_user) self.assertEqual(rel.user_object, self.remote_user)
self.assertEqual(rel.status, "follow_request") self.assertEqual(rel.status, "follow_request")
def test_handle_follow_local_manually_approves(self): def test_handle_follow_local_manually_approves(self, _):
"""send a follow request""" """send a follow request"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay" "bookwyrm.activitystreams.populate_stream_task.delay"
@ -93,7 +94,7 @@ class FollowViews(TestCase):
self.assertEqual(rel.user_object, rat) self.assertEqual(rel.user_object, rat)
self.assertEqual(rel.status, "follow_request") self.assertEqual(rel.status, "follow_request")
def test_handle_follow_local(self): def test_handle_follow_local(self, _):
"""send a follow request""" """send a follow request"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay" "bookwyrm.activitystreams.populate_stream_task.delay"
@ -119,7 +120,8 @@ class FollowViews(TestCase):
self.assertEqual(rel.user_object, rat) self.assertEqual(rel.user_object, rat)
self.assertEqual(rel.status, "follows") self.assertEqual(rel.status, "follows")
def test_handle_unfollow(self): @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
def test_handle_unfollow(self, *_):
"""send an unfollow""" """send an unfollow"""
request = self.factory.post("", {"user": self.remote_user.username}) request = self.factory.post("", {"user": self.remote_user.username})
request.user = self.local_user request.user = self.local_user
@ -133,7 +135,7 @@ class FollowViews(TestCase):
self.assertEqual(self.remote_user.followers.count(), 0) self.assertEqual(self.remote_user.followers.count(), 0)
def test_handle_accept(self): def test_handle_accept(self, _):
"""accept a follow request""" """accept a follow request"""
self.local_user.manually_approves_followers = True self.local_user.manually_approves_followers = True
self.local_user.save( self.local_user.save(
@ -152,7 +154,7 @@ class FollowViews(TestCase):
# follow relationship should exist # follow relationship should exist
self.assertEqual(self.local_user.followers.first(), self.remote_user) self.assertEqual(self.local_user.followers.first(), self.remote_user)
def test_handle_reject(self): def test_handle_reject(self, _):
"""reject a follow request""" """reject a follow request"""
self.local_user.manually_approves_followers = True self.local_user.manually_approves_followers = True
self.local_user.save( self.local_user.save(

View file

@ -34,7 +34,7 @@ class GetStartedViews(TestCase):
) )
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
def test_profile_view(self): def test_profile_view(self, *_):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.GetStartedProfile.as_view() view = views.GetStartedProfile.as_view()
request = self.factory.get("") request = self.factory.get("")
@ -66,7 +66,7 @@ class GetStartedViews(TestCase):
self.assertEqual(self.local_user.name, "New Name") self.assertEqual(self.local_user.name, "New Name")
self.assertTrue(self.local_user.discoverable) self.assertTrue(self.local_user.discoverable)
def test_books_view(self): def test_books_view(self, _):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.GetStartedBooks.as_view() view = views.GetStartedBooks.as_view()
request = self.factory.get("") request = self.factory.get("")
@ -78,7 +78,7 @@ class GetStartedViews(TestCase):
result.render() result.render()
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_books_view_with_query(self): def test_books_view_with_query(self, _):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.GetStartedBooks.as_view() view = views.GetStartedBooks.as_view()
request = self.factory.get("?query=Example") request = self.factory.get("?query=Example")
@ -91,7 +91,8 @@ class GetStartedViews(TestCase):
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
def test_books_view_post(self, _): @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
def test_books_view_post(self, *_):
"""shelve some books""" """shelve some books"""
view = views.GetStartedBooks.as_view() view = views.GetStartedBooks.as_view()
data = {self.book.id: self.local_user.shelf_set.first().id} data = {self.book.id: self.local_user.shelf_set.first().id}
@ -110,7 +111,7 @@ class GetStartedViews(TestCase):
self.assertEqual(shelfbook.user, self.local_user) self.assertEqual(shelfbook.user, self.local_user)
@patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions")
def test_users_view(self, _): def test_users_view(self, *_):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.GetStartedUsers.as_view() view = views.GetStartedUsers.as_view()
request = self.factory.get("") request = self.factory.get("")
@ -123,7 +124,7 @@ class GetStartedViews(TestCase):
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions")
def test_users_view_with_query(self, _): def test_users_view_with_query(self, *_):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.GetStartedUsers.as_view() view = views.GetStartedUsers.as_view()
request = self.factory.get("?query=rat") request = self.factory.get("?query=rat")

View file

@ -8,7 +8,7 @@ from bookwyrm import models, views
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
@patch("bookwyrm.activitystreams.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.remove_status_task.delay")
class InteractionViews(TestCase): class InteractionViews(TestCase):
"""viewing and creating statuses""" """viewing and creating statuses"""
@ -173,17 +173,12 @@ class InteractionViews(TestCase):
request.user = self.remote_user request.user = self.remote_user
status = models.Status.objects.create(user=self.local_user, content="hi") status = models.Status.objects.create(user=self.local_user, content="hi")
with patch(
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
):
views.Boost.as_view()(request, status.id) views.Boost.as_view()(request, status.id)
self.assertEqual(models.Boost.objects.count(), 1) self.assertEqual(models.Boost.objects.count(), 1)
self.assertEqual(models.Notification.objects.count(), 1) self.assertEqual(models.Notification.objects.count(), 1)
with patch(
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
) as redis_mock:
view(request, status.id) view(request, status.id)
self.assertTrue(redis_mock.called)
self.assertEqual(models.Boost.objects.count(), 0) self.assertEqual(models.Boost.objects.count(), 0)
self.assertEqual(models.Notification.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0)

View file

@ -11,6 +11,7 @@ from bookwyrm.settings import DOMAIN
# pylint: disable=invalid-name # pylint: disable=invalid-name
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.remove_status_task.delay")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class StatusViews(TestCase): class StatusViews(TestCase):
"""viewing and creating statuses""" """viewing and creating statuses"""