Add tests for remove_user_preview_image_task

This commit is contained in:
Joachim 2022-12-17 17:49:39 +01:00
parent b570602a47
commit cd940e2c40

View file

@ -14,6 +14,7 @@ from bookwyrm.preview_images import (
generate_edition_preview_image_task,
generate_user_preview_image_task,
generate_preview_image,
remove_user_preview_image_task,
save_and_cleanup,
)
@ -59,6 +60,24 @@ class PreviewImages(TestCase):
outbox="https://example.com/users/rat/outbox",
)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.remote_user_with_preview = models.User.objects.create_user(
"badger@your.domain.here",
"badger@badger.com",
"badgeword",
local=False,
remote_id="https://example.com/users/badger",
inbox="https://example.com/users/badger/inbox",
outbox="https://example.com/users/badger/outbox",
avatar=SimpleUploadedFile(
avatar_file,
open(avatar_file, "rb").read(),
content_type="image/jpeg",
),
)
self.work = models.Work.objects.create(title="Test Work")
self.edition = models.Edition.objects.create(
title="Example Edition",
@ -127,7 +146,7 @@ class PreviewImages(TestCase):
self.local_user.refresh_from_db()
self.assertIsInstance(self.local_user.preview_image, ImageFieldFile)
self.assertTrue(self.local_user.preview_image)
self.assertIsNotNone(self.local_user.preview_image)
self.assertEqual(
self.local_user.preview_image.width, settings.PREVIEW_IMG_WIDTH
)
@ -151,3 +170,12 @@ class PreviewImages(TestCase):
args = generate_mock.call_args.kwargs
self.assertEqual(args["texts"]["text_one"], "possum")
self.assertEqual(args["texts"]["text_three"], f"@possum@{settings.DOMAIN}")
def test_remove_user_preview_image_task(self, *args, **kwargs):
"""you can delete the preview image for a (remote) user"""
remove_user_preview_image_task(self.remote_user_with_preview.id)
self.remote_user_with_preview.refresh_from_db()
self.assertFalse(self.remote_user_with_preview.preview_image)