MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / test_image_field

Method test_image_field

tests/fields/test_file_field.py:377–406  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

375
376 @require_pil
377 def test_image_field(self):
378 class TestImage(Document):
379 image = ImageField()
380
381 TestImage.drop_collection()
382
383 with tempfile.TemporaryFile() as f:
384 f.write(b"Hello World!")
385 f.flush()
386
387 t = TestImage()
388 try:
389 t.image.put(f)
390 self.fail("Should have raised an invalidation error")
391 except ValidationError as e:
392 assert "%s" % e == "Invalid image: cannot identify image file %s" % f
393
394 t = TestImage()
395 t.image.put(get_file(TEST_IMAGE_PATH))
396 t.save()
397
398 t = TestImage.objects.first()
399
400 assert t.image.format == "PNG"
401
402 w, h = t.image.size
403 assert w == 371
404 assert h == 76
405
406 t.image.delete()
407
408 @require_pil
409 def test_image_field_reassigning(self):

Callers

nothing calls this directly

Calls 8

TestImageClass · 0.85
get_fileFunction · 0.85
drop_collectionMethod · 0.80
writeMethod · 0.45
putMethod · 0.45
saveMethod · 0.45
firstMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected