]> git.parisson.com Git - django_quiz.git/commitdiff
tests for image field
authortomwalker <tomwalker0472@gmail.com>
Thu, 31 Jul 2014 15:46:04 +0000 (16:46 +0100)
committertomwalker <tomwalker0472@gmail.com>
Thu, 31 Jul 2014 15:46:04 +0000 (16:46 +0100)
multichoice/tests.py

index 51718826720250857a2b3ab20daf4269873a2b39..131a60fd2b21ab356a6d761ac97a44334102d7a4 100644 (file)
@@ -1,3 +1,7 @@
+from StringIO import StringIO
+
+from django.db.models.fields.files import ImageFieldFile
+from django.core.files.base import ContentFile
 from django.test import TestCase
 
 from .models import MCQuestion, Answer
@@ -34,3 +38,13 @@ class TestMCQuestionModel(TestCase):
         self.assertEqual(answers_by_method.count(), 2)
         self.assertEqual(self.q.answer_choice_to_string(123),
                          self.answer1.content)
+
+    def test_figure(self):
+        # http://stackoverflow.com/a/2473445/1694979
+        imgfile = StringIO(
+            'GIF87a\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00ccc,'
+            '\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;')
+        imgfile.name = 'test_img_file.gif'
+
+        self.q.figure.save('image', ContentFile(imgfile.read()))
+        self.assertIsInstance(self.q.figure, ImageFieldFile)