Adds tests for the tags and simplifies progress code

EmailTemplateFixes
Denis Krienbühl 2011-12-22 10:22:33 +01:00
parent d5498d9cb1
commit fbd96f9778
4 changed files with 50 additions and 18 deletions

View File

@ -82,12 +82,12 @@
emailcount: 0, emailcount: 0,
emailsent: !!timestamp '2009-05-16 15:05:11.775082', emailsent: !!timestamp '2009-05-16 15:05:11.775082',
lastemailerror: null, lastemailerror: null,
questionset: 2, questionset: 3,
random: 'test:withtags', random: 'test:withtags',
runid: 'test:withtags', runid: 'test:withtags',
state: '', state: '',
subject: 1, tags: 'testtag',
tags: 'testtag' subject: 1
} }
model: questionnaire.runinfo model: questionnaire.runinfo
pk: 2 pk: 2
@ -97,12 +97,12 @@
emailcount: 0, emailcount: 0,
emailsent: !!timestamp '2009-05-16 15:05:11.775082', emailsent: !!timestamp '2009-05-16 15:05:11.775082',
lastemailerror: null, lastemailerror: null,
questionset: 2, questionset: 3,
random: 'test:withouttags', random: 'test:withouttags',
runid: 'test:withouttags', runid: 'test:withouttags',
state: '', state: '',
subject: 1, tags: '',
tags: '' subject: 1
} }
model: questionnaire.runinfo model: questionnaire.runinfo
pk: 3 pk: 3

View File

@ -24,8 +24,8 @@
{% if progress %} {% if progress %}
<div id="progress_bar" class="ui-progress-bar ui-container"> <div id="progress_bar" class="ui-progress-bar ui-container">
<div class="ui-progress" style="width: {{progress.0}}%;"> <div class="ui-progress" style="width: {{progress}}%;">
<span class="ui-label"><b class="value">{{progress.0}}%</b></span> <span class="ui-label"><b class="value">{{progress}}%</b></span>
</div> </div>
</div> </div>
{% endif %} {% endif %}

View File

@ -153,3 +153,39 @@ class TypeTest(TestCase):
v = v.replace('\r', '\\r').replace('\n', '\\n') v = v.replace('\r', '\\r').replace('\n', '\\n')
self.assertEqual(ans.answer, v) self.assertEqual(ans.answer, v)
def test070_tags(self):
c = self.client
# the first questionset in questionnaire 2 is always shown,
# but one of its 2 questions is tagged with testtag
with_tags = c.get('/q/test:withtags/1/')
# so we'll get two questions shown if the run is tagged
self.assertEqual(with_tags.status_code, 200)
self.assertEqual(len(with_tags.context['qlist']), 2)
# one question, if the run is not tagged
without_tags = c.get('/q/test:withouttags/1/')
self.assertEqual(without_tags.status_code, 200)
self.assertEqual(len(without_tags.context['qlist']), 1)
# the second questionset is only shown if the run is tagged
with_tags = c.get('/q/test:withtags/2/')
self.assertEqual(with_tags.status_code, 200)
self.assertEqual(len(with_tags.context['qlist']), 1)
# meaning it'll be skipped on the untagged run
without_tags = c.get('/q/test.withouttags/2/')
self.assertEqual(without_tags.status_code, 302) # redirect
# the progress values of the first questionset should reflect
# the fact that in one run there's only one questionset
with_tags = c.get('/q/test:withtags/1/')
without_tags = c.get('/q/test:withouttags/1/')
self.assertEqual(with_tags.context['progress'], 50)
self.assertEqual(without_tags.context['progress'], 100)

View File

@ -320,14 +320,6 @@ def questionnaire(request, runcode=None, qs=None):
transaction.commit() transaction.commit()
return redirect_to_qs(runinfo) return redirect_to_qs(runinfo)
def get_progress(percent):
"Based on a percentage as a float, calculate percentage needed for CSS progress bar"
if int(percent) >= 1:
return 100, "1"
pc = "-%s" % (120 - int(percent * 120) + 1)
return (int(percent * 100), pc)
def get_total_questionsets(runinfo): def get_total_questionsets(runinfo):
"Returns the total of visible questionsets" "Returns the total of visible questionsets"
sets = runinfo.questionset.questionnaire.questionsets() sets = runinfo.questionset.questionnaire.questionsets()
@ -437,7 +429,11 @@ def show_questionnaire(request, runinfo, errors={}):
if not all((pos, total)): if not all((pos, total)):
progress = None progress = None
else: else:
progress = get_progress(float(pos) / float(total)) progress = float(pos) / float(total) * 100.00
# progress is always at least one percent
progress = progress > 1.0 and int(progress) or 1
if request.POST: if request.POST:
for k,v in request.POST.items(): for k,v in request.POST.items():