From 6fd3ac0cb13ed6ed1fe1c582729c89157401be13 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 2 Feb 2022 09:23:06 -0800 Subject: [PATCH] Changes how test image data is loaded --- bookwyrm/tests/models/test_fields.py | 73 ++++++++++++++-------------- bw-dev | 1 + 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/bookwyrm/tests/models/test_fields.py b/bookwyrm/tests/models/test_fields.py index 5bb7fecc6..f7386c2e4 100644 --- a/bookwyrm/tests/models/test_fields.py +++ b/bookwyrm/tests/models/test_fields.py @@ -443,18 +443,17 @@ class ModelFields(TestCase): 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) - instance = fields.ImageField() - responses.add( - responses.GET, - "http://www.example.com/image.jpg", - body=image.tobytes(), - status=200, - ) + with open(image_file, "rb") as image_data: + responses.add( + responses.GET, + "http://www.example.com/image.jpg", + body=image_data.read(), + status=200, + content_type="image/jpeg", + stream=True, + ) loaded_image = instance.field_from_activity("http://www.example.com/image.jpg") self.assertIsInstance(loaded_image, list) self.assertIsInstance(loaded_image[1], ContentFile) @@ -465,18 +464,18 @@ class ModelFields(TestCase): 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) instance = fields.ImageField(activitypub_field="cover", name="cover") - responses.add( - responses.GET, - "http://www.example.com/image.jpg", - body=image.tobytes(), - status=200, - ) + with open(image_file, "rb") as image_data: + responses.add( + responses.GET, + "http://www.example.com/image.jpg", + body=image_data.read(), + content_type="image/jpeg", + status=200, + stream=True, + ) book = Edition.objects.create(title="hello") MockActivity = namedtuple("MockActivity", ("cover")) @@ -491,18 +490,18 @@ class ModelFields(TestCase): 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) instance = fields.ImageField(activitypub_field="cover", name="cover") - responses.add( - responses.GET, - "http://www.example.com/image.jpg", - body=image.tobytes(), - status=200, - ) + with open(image_file, "rb") as image_data: + responses.add( + responses.GET, + "http://www.example.com/image.jpg", + body=image_data.read(), + status=200, + content_type="image/jpeg", + stream=True, + ) book = Edition.objects.create(title="hello") MockActivity = namedtuple("MockActivity", ("cover")) @@ -565,18 +564,18 @@ class ModelFields(TestCase): another_image_file = pathlib.Path(__file__).parent.joinpath( "../../static/images/logo.png" ) - another_image = Image.open(another_image_file) - another_output = BytesIO() - another_image.save(another_output, format=another_image.format) instance = fields.ImageField(activitypub_field="cover", name="cover") - responses.add( - responses.GET, - "http://www.example.com/image.jpg", - body=another_image.tobytes(), - status=200, - ) + with open(another_image_file, "rb") as another_image: + responses.add( + responses.GET, + "http://www.example.com/image.jpg", + body=another_image.read(), + status=200, + content_type="image/jpeg", + stream=True, + ) MockActivity = namedtuple("MockActivity", ("cover")) mock_activity = MockActivity("http://www.example.com/image.jpg") diff --git a/bw-dev b/bw-dev index 00faa6a62..77d337297 100755 --- a/bw-dev +++ b/bw-dev @@ -209,6 +209,7 @@ case "$CMD" in echo " build" echo " clean" echo " black" + echo " prettier" echo " populate_streams [--stream=]" echo " populate_suggestions" echo " generate_thumbnails"