Fixes image attachments
This commit is contained in:
@ -1,5 +1,10 @@
|
||||
""" test for app action functionality """
|
||||
from io import BytesIO
|
||||
from unittest.mock import patch
|
||||
import pathlib
|
||||
|
||||
from PIL import Image
|
||||
from django.core.files.base import ContentFile
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
@ -9,8 +14,8 @@ from bookwyrm import views
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
|
||||
|
||||
class FeedMessageViews(TestCase):
|
||||
""" dms """
|
||||
class FeedViews(TestCase):
|
||||
""" activity feed, statuses, dms """
|
||||
|
||||
def setUp(self):
|
||||
""" we need basic test data and mocks """
|
||||
@ -59,6 +64,42 @@ class FeedMessageViews(TestCase):
|
||||
self.assertIsInstance(result, ActivitypubResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_status_page_with_image(self):
|
||||
""" there are so many views, this just makes sure it LOADS """
|
||||
view = views.Status.as_view()
|
||||
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/default_avi.jpg"
|
||||
)
|
||||
image = Image.open(image_file)
|
||||
output = BytesIO()
|
||||
image.save(output, format=image.format)
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
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"
|
||||
)
|
||||
attachment.image.save("test.jpg", ContentFile(output.getvalue()))
|
||||
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.feed.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, "mouse", status.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch("bookwyrm.views.feed.is_api_request") as is_api:
|
||||
is_api.return_value = True
|
||||
result = view(request, "mouse", status.id)
|
||||
self.assertIsInstance(result, ActivitypubResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_replies_page(self):
|
||||
""" there are so many views, this just makes sure it LOADS """
|
||||
view = views.Replies.as_view()
|
||||
|
Reference in New Issue
Block a user