Django testing model with ImageField

For future users, I’ve solved the problem.
You can mock an ImageField with a SimpleUploadedFile instance.

test.py

from django.core.files.uploadedfile import SimpleUploadedFile

newPhoto.image = SimpleUploadedFile(name="test_image.jpg", content=open(image_path, 'rb').read(), content_type="image/jpeg")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)