forked from mirrors/bookwyrm
another round of mocks
This commit is contained in:
parent
59400511c9
commit
2653458e56
11 changed files with 38 additions and 61 deletions
|
@ -10,6 +10,7 @@ from bookwyrm import models, settings
|
|||
@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.activitystreams.remove_book_statuses_task.delay")
|
||||
class Shelf(TestCase):
|
||||
"""some activitypub oddness ahead"""
|
||||
|
||||
|
|
|
@ -55,9 +55,8 @@ class InboxActivities(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||
def test_boost(self, redis_mock, _):
|
||||
@patch("bookwyrm.activitystreams.handle_boost_task.delay")
|
||||
def test_boost(self, _):
|
||||
"""boost a status"""
|
||||
self.assertEqual(models.Notification.objects.count(), 0)
|
||||
activity = {
|
||||
|
@ -73,9 +72,6 @@ class InboxActivities(TestCase):
|
|||
discarder.return_value = False
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
# boost added to redis activitystreams
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
||||
# boost created of correct status
|
||||
boost = models.Boost.objects.get()
|
||||
self.assertEqual(boost.boosted_status, self.status)
|
||||
|
@ -86,9 +82,8 @@ class InboxActivities(TestCase):
|
|||
self.assertEqual(notification.related_status, self.status)
|
||||
|
||||
@responses.activate
|
||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||
def test_boost_remote_status(self, redis_mock, _):
|
||||
@patch("bookwyrm.activitystreams.handle_boost_task.delay")
|
||||
def test_boost_remote_status(self, _):
|
||||
"""boost a status from a remote server"""
|
||||
work = models.Work.objects.create(title="work title")
|
||||
book = models.Edition.objects.create(
|
||||
|
@ -129,7 +124,6 @@ class InboxActivities(TestCase):
|
|||
with patch("bookwyrm.models.status.Status.ignore_activity") as discarder:
|
||||
discarder.return_value = False
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
||||
boost = models.Boost.objects.get()
|
||||
self.assertEqual(boost.boosted_status.remote_id, "https://remote.com/status/1")
|
||||
|
@ -161,7 +155,8 @@ class InboxActivities(TestCase):
|
|||
self.assertEqual(models.Boost.objects.count(), 0)
|
||||
|
||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.handle_boost_task.delay")
|
||||
@patch("bookwyrm.activitystreams.remove_status_task.delay")
|
||||
def test_unboost(self, *_):
|
||||
"""undo a boost"""
|
||||
boost = models.Boost.objects.create(
|
||||
|
|
|
@ -56,7 +56,7 @@ class InboxBlock(TestCase):
|
|||
}
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_user_statuses"
|
||||
"bookwyrm.activitystreams.remove_user_statuses_task.delay"
|
||||
) as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
@ -94,7 +94,7 @@ class InboxBlock(TestCase):
|
|||
},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.add_user_statuses"
|
||||
"bookwyrm.activitystreams.add_user_statuses_task.delay"
|
||||
) as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
""" tests incoming activities"""
|
||||
"""tests incoming activities"""
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
|
@ -63,9 +63,7 @@ class InboxActivities(TestCase):
|
|||
"actor": self.remote_user.remote_id,
|
||||
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
# deletion doens't remove the status, it turns it into a tombstone
|
||||
|
@ -94,9 +92,7 @@ class InboxActivities(TestCase):
|
|||
"actor": self.remote_user.remote_id,
|
||||
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
# deletion doens't remove the status, it turns it into a tombstone
|
||||
|
|
|
@ -183,7 +183,8 @@ class InboxRelationships(TestCase):
|
|||
views.inbox.activity_task(activity)
|
||||
self.assertIsNone(self.local_user.followers.first())
|
||||
|
||||
def test_follow_accept(self):
|
||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
||||
def test_follow_accept(self, _):
|
||||
"""a remote user approved a follow request from local"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
rel = models.UserFollowRequest.objects.create(
|
||||
|
|
|
@ -83,7 +83,8 @@ class InboxUpdate(TestCase):
|
|||
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
|
||||
|
||||
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
||||
def test_update_user(self, _):
|
||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
||||
def test_update_user(self, *_):
|
||||
"""update an existing user"""
|
||||
models.UserFollows.objects.create(
|
||||
user_subject=self.local_user,
|
||||
|
|
|
@ -104,7 +104,7 @@ class BookViews(TestCase):
|
|||
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
def test_switch_edition(self, _):
|
||||
def test_switch_edition(self, *_):
|
||||
"""updates user's relationships to a book"""
|
||||
work = models.Work.objects.create(title="test work")
|
||||
edition1 = models.Edition.objects.create(title="first ed", parent_work=work)
|
||||
|
|
|
@ -11,6 +11,7 @@ from bookwyrm import models, views
|
|||
@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")
|
||||
class ReadingViews(TestCase):
|
||||
"""viewing and creating statuses"""
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ from bookwyrm import models
|
|||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
|
||||
class ReadThrough(TestCase):
|
||||
"""readthrough tests"""
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ from bookwyrm.activitypub import ActivitypubResponse
|
|||
@patch("bookwyrm.models.activitypub_mixin.broadcast_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.activitystreams.remove_book_statuses_task.delay")
|
||||
class ShelfViews(TestCase):
|
||||
"""tag views"""
|
||||
|
||||
|
|
|
@ -63,9 +63,7 @@ class StatusViews(TestCase):
|
|||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
|
||||
view(request, "comment")
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
||||
status = models.Comment.objects.get()
|
||||
self.assertEqual(status.content, "<p>hi</p>")
|
||||
|
@ -78,7 +76,6 @@ class StatusViews(TestCase):
|
|||
user = models.User.objects.create_user(
|
||||
"rat", "rat@rat.com", "password", local=True
|
||||
)
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
parent = models.Status.objects.create(
|
||||
content="parent status", user=self.local_user
|
||||
)
|
||||
|
@ -93,9 +90,7 @@ class StatusViews(TestCase):
|
|||
request = self.factory.post("", form.data)
|
||||
request.user = user
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
|
||||
view(request, "reply")
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
||||
status = models.Status.objects.get(user=user)
|
||||
self.assertEqual(status.content, "<p>hi</p>")
|
||||
|
@ -123,9 +118,7 @@ class StatusViews(TestCase):
|
|||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
|
||||
view(request, "comment")
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
||||
status = models.Status.objects.get()
|
||||
self.assertEqual(list(status.mention_users.all()), [user])
|
||||
|
@ -151,9 +144,7 @@ class StatusViews(TestCase):
|
|||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
|
||||
view(request, "comment")
|
||||
self.assertTrue(redis_mock.called)
|
||||
status = models.Status.objects.get()
|
||||
|
||||
form = forms.ReplyForm(
|
||||
|
@ -167,9 +158,7 @@ class StatusViews(TestCase):
|
|||
request = self.factory.post("", form.data)
|
||||
request.user = user
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock:
|
||||
view(request, "reply")
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
||||
reply = models.Status.replies(status).first()
|
||||
self.assertEqual(reply.content, "<p>right</p>")
|
||||
|
@ -183,14 +172,11 @@ class StatusViews(TestCase):
|
|||
view = views.DeleteAndRedraft.as_view()
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
status = models.Comment.objects.create(
|
||||
content="hi", book=self.book, user=self.local_user
|
||||
)
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock:
|
||||
result = view(request, status.id)
|
||||
self.assertTrue(mock.called)
|
||||
result.render()
|
||||
|
@ -209,9 +195,7 @@ class StatusViews(TestCase):
|
|||
book=self.book, rating=2.0, user=self.local_user
|
||||
)
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock:
|
||||
result = view(request, status.id)
|
||||
self.assertFalse(mock.called)
|
||||
self.assertEqual(result.status_code, 400)
|
||||
|
@ -229,9 +213,7 @@ class StatusViews(TestCase):
|
|||
content="hi", user=self.local_user
|
||||
)
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock:
|
||||
result = view(request, status.id)
|
||||
self.assertFalse(mock.called)
|
||||
self.assertEqual(result.status_code, 400)
|
||||
|
@ -354,9 +336,7 @@ class StatusViews(TestCase):
|
|||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock:
|
||||
view(request, status.id)
|
||||
self.assertTrue(redis_mock.called)
|
||||
activity = json.loads(mock.call_args_list[1][0][1])
|
||||
|
@ -389,9 +369,7 @@ class StatusViews(TestCase):
|
|||
request.user = self.remote_user
|
||||
request.user.is_superuser = True
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock:
|
||||
view(request, status.id)
|
||||
self.assertTrue(redis_mock.called)
|
||||
activity = json.loads(mock.call_args_list[1][0][1])
|
||||
|
|
Loading…
Reference in a new issue