Refactors test mocks
This commit is contained in:
@ -22,22 +22,19 @@ class FeedViews(TestCase):
|
||||
def setUp(self):
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
self.book = models.Edition.objects.create(
|
||||
parent_work=models.Work.objects.create(title="hi"),
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
)
|
||||
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||
models.SiteSettings.objects.create()
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.book = models.Edition.objects.create(
|
||||
parent_work=models.Work.objects.create(title="hi"),
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_feed(self, *_):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
@ -92,14 +89,11 @@ class FeedViews(TestCase):
|
||||
output = BytesIO()
|
||||
image.save(output, format=image.format)
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
with patch(
|
||||
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||
):
|
||||
status = models.Review.objects.create(
|
||||
content="hi",
|
||||
user=self.local_user,
|
||||
book=self.book,
|
||||
)
|
||||
status = models.Review.objects.create(
|
||||
content="hi",
|
||||
user=self.local_user,
|
||||
book=self.book,
|
||||
)
|
||||
attachment = models.Image.objects.create(
|
||||
status=status, caption="alt text here"
|
||||
)
|
||||
@ -152,13 +146,12 @@ class FeedViews(TestCase):
|
||||
|
||||
def test_get_suggested_book(self, *_):
|
||||
"""gets books the ~*~ algorithm ~*~ thinks you want to post about"""
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
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"),
|
||||
)
|
||||
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"),
|
||||
)
|
||||
suggestions = views.feed.get_suggested_books(self.local_user)
|
||||
self.assertEqual(suggestions[0]["name"], "Currently Reading")
|
||||
self.assertEqual(suggestions[0]["books"][0], self.book)
|
||||
|
Reference in New Issue
Block a user