Changes how test image data is loaded

This commit is contained in:
Mouse Reeve 2022-02-02 09:23:06 -08:00
parent 194c69f512
commit 6fd3ac0cb1
2 changed files with 37 additions and 37 deletions

View file

@ -443,18 +443,17 @@ class ModelFields(TestCase):
image_file = pathlib.Path(__file__).parent.joinpath( image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg" "../../static/images/default_avi.jpg"
) )
image = Image.open(image_file)
output = BytesIO()
image.save(output, format=image.format)
instance = fields.ImageField() instance = fields.ImageField()
responses.add( with open(image_file, "rb") as image_data:
responses.GET, responses.add(
"http://www.example.com/image.jpg", responses.GET,
body=image.tobytes(), "http://www.example.com/image.jpg",
status=200, body=image_data.read(),
) status=200,
content_type="image/jpeg",
stream=True,
)
loaded_image = instance.field_from_activity("http://www.example.com/image.jpg") loaded_image = instance.field_from_activity("http://www.example.com/image.jpg")
self.assertIsInstance(loaded_image, list) self.assertIsInstance(loaded_image, list)
self.assertIsInstance(loaded_image[1], ContentFile) self.assertIsInstance(loaded_image[1], ContentFile)
@ -465,18 +464,18 @@ class ModelFields(TestCase):
image_file = pathlib.Path(__file__).parent.joinpath( image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg" "../../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") instance = fields.ImageField(activitypub_field="cover", name="cover")
responses.add( with open(image_file, "rb") as image_data:
responses.GET, responses.add(
"http://www.example.com/image.jpg", responses.GET,
body=image.tobytes(), "http://www.example.com/image.jpg",
status=200, body=image_data.read(),
) content_type="image/jpeg",
status=200,
stream=True,
)
book = Edition.objects.create(title="hello") book = Edition.objects.create(title="hello")
MockActivity = namedtuple("MockActivity", ("cover")) MockActivity = namedtuple("MockActivity", ("cover"))
@ -491,18 +490,18 @@ class ModelFields(TestCase):
image_file = pathlib.Path(__file__).parent.joinpath( image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg" "../../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") instance = fields.ImageField(activitypub_field="cover", name="cover")
responses.add( with open(image_file, "rb") as image_data:
responses.GET, responses.add(
"http://www.example.com/image.jpg", responses.GET,
body=image.tobytes(), "http://www.example.com/image.jpg",
status=200, body=image_data.read(),
) status=200,
content_type="image/jpeg",
stream=True,
)
book = Edition.objects.create(title="hello") book = Edition.objects.create(title="hello")
MockActivity = namedtuple("MockActivity", ("cover")) MockActivity = namedtuple("MockActivity", ("cover"))
@ -565,18 +564,18 @@ class ModelFields(TestCase):
another_image_file = pathlib.Path(__file__).parent.joinpath( another_image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/logo.png" "../../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") instance = fields.ImageField(activitypub_field="cover", name="cover")
responses.add( with open(another_image_file, "rb") as another_image:
responses.GET, responses.add(
"http://www.example.com/image.jpg", responses.GET,
body=another_image.tobytes(), "http://www.example.com/image.jpg",
status=200, body=another_image.read(),
) status=200,
content_type="image/jpeg",
stream=True,
)
MockActivity = namedtuple("MockActivity", ("cover")) MockActivity = namedtuple("MockActivity", ("cover"))
mock_activity = MockActivity("http://www.example.com/image.jpg") mock_activity = MockActivity("http://www.example.com/image.jpg")

1
bw-dev
View file

@ -209,6 +209,7 @@ case "$CMD" in
echo " build" echo " build"
echo " clean" echo " clean"
echo " black" echo " black"
echo " prettier"
echo " populate_streams [--stream=<stream name>]" echo " populate_streams [--stream=<stream name>]"
echo " populate_suggestions" echo " populate_suggestions"
echo " generate_thumbnails" echo " generate_thumbnails"