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
@patch("bookwyrm.suggested_users.rerank_suggestions_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):
"""importing from goodreads csv"""

View file

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

View file

@ -6,6 +6,7 @@ from django.test import TestCase
from bookwyrm import models
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
class Relationship(TestCase):
"""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.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"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock:
request = models.UserFollowRequest.objects.create(
@ -51,7 +52,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_subject, self.local_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"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
request = models.UserFollowRequest.objects.create(
@ -69,7 +70,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_object, self.remote_user)
@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"""
models.UserFollowRequest.objects.create(
user_subject=self.local_user,
@ -81,7 +82,7 @@ class Relationship(TestCase):
self.assertEqual(activity["type"], "Follow")
@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"""
self.local_user.manually_approves_followers = True
self.local_user.save(
@ -107,7 +108,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_object, self.local_user)
@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"""
self.local_user.manually_approves_followers = True
self.local_user.save(

View file

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

View file

@ -16,7 +16,7 @@ from bookwyrm import activitypub, models, settings
# pylint: disable=too-many-public-methods
@patch("bookwyrm.models.Status.broadcast")
@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):
"""lotta types of statuses"""
@ -120,15 +120,12 @@ class Status(TestCase):
def test_status_to_activity_tombstone(self, *_):
"""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(
content="test content",
user=self.local_user,
deleted=True,
deleted_date=timezone.now(),
)
status = models.Status.objects.create(
content="test content",
user=self.local_user,
deleted=True,
deleted_date=timezone.now(),
)
activity = status.to_activity()
self.assertEqual(activity["id"], status.remote_id)
self.assertEqual(activity["type"], "Tombstone")

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.suggested_users.rerank_suggestions_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.remove_user_task.delay")
class SuggestedUsers(TestCase):

View file

@ -16,7 +16,7 @@ from bookwyrm.templatetags import (
@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):
"""lotta different things here"""
@ -75,15 +75,12 @@ class TemplateTags(TestCase):
second_child = models.Status.objects.create(
reply_parent=parent, user=self.user, content="hi"
)
with patch(
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
):
third_child = models.Status.objects.create(
reply_parent=parent,
user=self.user,
deleted=True,
deleted_date=timezone.now(),
)
third_child = models.Status.objects.create(
reply_parent=parent,
user=self.user,
deleted=True,
deleted_date=timezone.now(),
)
replies = status_display.get_replies(parent)
self.assertEqual(len(replies), 2)

View file

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

View file

@ -59,7 +59,7 @@ class BlockViews(TestCase):
request = self.factory.post("")
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)
block = models.UserBlocks.objects.get()
self.assertEqual(block.user_subject, self.local_user)
@ -74,7 +74,7 @@ class BlockViews(TestCase):
request = self.factory.post("")
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)
self.assertFalse(models.UserBlocks.objects.exists())

View file

@ -39,7 +39,9 @@ class EditUserViews(TestCase):
self.book = models.Edition.objects.create(
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(
book=self.book,
user=self.local_user,

View file

@ -172,14 +172,15 @@ class FeedViews(TestCase):
result.render()
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, *_):
"""gets books the ~*~ algorithm ~*~ thinks you want to post about"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.ShelfBook.objects.create(
book=self.book,
user=self.local_user,
shelf=self.local_user.shelf_set.get(identifier="reading"),
)
models.ShelfBook.objects.create(
book=self.book,
user=self.local_user,
shelf=self.local_user.shelf_set.get(identifier="reading"),
)
suggestions = views.feed.get_suggested_books(self.local_user)
self.assertEqual(suggestions[0]["name"], "Currently Reading")
self.assertEqual(suggestions[0]["books"][0], self.book)

View file

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

View file

@ -34,7 +34,7 @@ class GetStartedViews(TestCase):
)
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"""
view = views.GetStartedProfile.as_view()
request = self.factory.get("")
@ -66,7 +66,7 @@ class GetStartedViews(TestCase):
self.assertEqual(self.local_user.name, "New Name")
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"""
view = views.GetStartedBooks.as_view()
request = self.factory.get("")
@ -78,7 +78,7 @@ class GetStartedViews(TestCase):
result.render()
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"""
view = views.GetStartedBooks.as_view()
request = self.factory.get("?query=Example")
@ -91,7 +91,8 @@ class GetStartedViews(TestCase):
self.assertEqual(result.status_code, 200)
@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"""
view = views.GetStartedBooks.as_view()
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)
@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"""
view = views.GetStartedUsers.as_view()
request = self.factory.get("")
@ -123,7 +124,7 @@ class GetStartedViews(TestCase):
self.assertEqual(result.status_code, 200)
@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"""
view = views.GetStartedUsers.as_view()
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.activitystreams.remove_object_from_related_stores")
@patch("bookwyrm.activitystreams.remove_status_task.delay")
class InteractionViews(TestCase):
"""viewing and creating statuses"""
@ -173,17 +173,12 @@ class InteractionViews(TestCase):
request.user = self.remote_user
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.Notification.objects.count(), 1)
with patch(
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
) as redis_mock:
view(request, status.id)
self.assertTrue(redis_mock.called)
view(request, status.id)
self.assertEqual(models.Boost.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
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.remove_status_task.delay")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class StatusViews(TestCase):
"""viewing and creating statuses"""