]> git.parisson.com Git - django_quiz.git/commitdiff
unit test that image with the question content as its alt is shown when viewing a...
authortomwalker <tomwalker0472@gmail.com>
Thu, 31 Jul 2014 16:42:32 +0000 (17:42 +0100)
committertomwalker <tomwalker0472@gmail.com>
Thu, 31 Jul 2014 16:42:32 +0000 (17:42 +0100)
quiz/templates/question.html
quiz/tests.py

index 65e0a80da2aa5f1346b956d82fab9c200f88f13b..273c63d9aa34d27e4ad626b69c3fbddb5e4cb029 100644 (file)
@@ -49,7 +49,7 @@
 <p class="lead">{{ question.content }}</p>
 
 {% if question.figure %}
-    <img src="{{ question.figure.url }}" alt />
+    <img src="{{ question.figure.url }}" alt="{{ question.content }}" />
 {% endif %}
 
 <form action="" method="POST">{% csrf_token %}
index 6a97ce431cf104f70606bb1edaf3a527fb62cc2e..ab22bb605a1b27d6c3acbfbfc610f230cfe03ce5 100644 (file)
@@ -1,8 +1,10 @@
 # -*- coding: iso-8859-15 -*-
+from StringIO import StringIO
 
 from django.conf import settings
 from django.contrib.auth.models import User, Permission
 from django.core.exceptions import ValidationError
+from django.core.files.base import ContentFile
 from django.core.urlresolvers import resolve
 from django.http import HttpRequest
 from django.test import TestCase
@@ -549,6 +551,19 @@ class TestQuestionViewsAnon(TestCase):
         self.assertEqual(self.client.session['1_q_list'], [1, 2])
         self.assertEqual(self.client.session['1_score'], 0)
 
+    def test_image_in_question(self):
+        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.question1.figure.save('image', ContentFile(imgfile.read()))
+        response = self.client.get('/tq1/take/')
+
+        self.assertContains(response, '<img src=')
+        self.assertContains(response,
+                            'alt="' + str(self.question1.content))
+
     def test_quiz_take_anon_submit(self):
         # show first question
         response = self.client.get('/tq1/take/')