python - Django testing model with ImageField -
I need to test the photo model of my Django app. How can I duplicate ImageField with a test image file?
tests.py test.py
Class PhotoTestCase (TestCase): def test_add_photo (auto): NewPhoto = Photo () newPhoto.image = #? Formula Newphoto.save () self.assertEqual (Photo.objects.count (), 1)
< P> For future users, I have solved the problem You can copy an ImageField with SimpleUploadedFile example. Import django.core.files.uploadedfile from
SimpleUploadedFile newPhoto.image = SimpleUploadedFile (name = 'test_image.jpg ', Content = open (image_path,' rb '). Read (), content_type =' image / jpeg ')
Comments
Post a Comment