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

  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

test.py

  SimpleUploadedFile newPhoto.image = SimpleUploadedFile (name = 'test_image.jpg ', Content = open (image_path,' rb '). Read (), content_type =' image / jpeg ')    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -