From 802fd495e5b0a062ddb3cf29c1d3a4a94e3fd48a Mon Sep 17 00:00:00 2001 From: tomwalker Date: Thu, 31 Jul 2014 17:42:32 +0100 Subject: [PATCH] unit test that image with the question content as its alt is shown when viewing a question --- quiz/templates/question.html | 2 +- quiz/tests.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/quiz/templates/question.html b/quiz/templates/question.html index 65e0a80..273c63d 100644 --- a/quiz/templates/question.html +++ b/quiz/templates/question.html @@ -49,7 +49,7 @@

{{ question.content }}

{% if question.figure %} - + {{ question.content }} {% endif %}
{% csrf_token %} diff --git a/quiz/tests.py b/quiz/tests.py index 6a97ce4..ab22bb6 100644 --- a/quiz/tests.py +++ b/quiz/tests.py @@ -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, '