Changes how test image data is loaded
This commit is contained in:
parent
194c69f512
commit
6fd3ac0cb1
|
@ -443,17 +443,16 @@ 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()
|
||||
|
||||
with open(image_file, "rb") as image_data:
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://www.example.com/image.jpg",
|
||||
body=image.tobytes(),
|
||||
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)
|
||||
|
@ -465,17 +464,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(activitypub_field="cover", name="cover")
|
||||
|
||||
with open(image_file, "rb") as image_data:
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://www.example.com/image.jpg",
|
||||
body=image.tobytes(),
|
||||
body=image_data.read(),
|
||||
content_type="image/jpeg",
|
||||
status=200,
|
||||
stream=True,
|
||||
)
|
||||
book = Edition.objects.create(title="hello")
|
||||
|
||||
|
@ -491,17 +490,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(activitypub_field="cover", name="cover")
|
||||
|
||||
with open(image_file, "rb") as image_data:
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://www.example.com/image.jpg",
|
||||
body=image.tobytes(),
|
||||
body=image_data.read(),
|
||||
status=200,
|
||||
content_type="image/jpeg",
|
||||
stream=True,
|
||||
)
|
||||
book = Edition.objects.create(title="hello")
|
||||
|
||||
|
@ -565,17 +564,17 @@ 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")
|
||||
|
||||
with open(another_image_file, "rb") as another_image:
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://www.example.com/image.jpg",
|
||||
body=another_image.tobytes(),
|
||||
body=another_image.read(),
|
||||
status=200,
|
||||
content_type="image/jpeg",
|
||||
stream=True,
|
||||
)
|
||||
|
||||
MockActivity = namedtuple("MockActivity", ("cover"))
|
||||
|
|
Loading…
Reference in New Issue