Adds tests for the tags and simplifies progress code
parent
d5498d9cb1
commit
fbd96f9778
|
@ -82,12 +82,12 @@
|
|||
emailcount: 0,
|
||||
emailsent: !!timestamp '2009-05-16 15:05:11.775082',
|
||||
lastemailerror: null,
|
||||
questionset: 2,
|
||||
questionset: 3,
|
||||
random: 'test:withtags',
|
||||
runid: 'test:withtags',
|
||||
state: '',
|
||||
subject: 1,
|
||||
tags: 'testtag'
|
||||
tags: 'testtag',
|
||||
subject: 1
|
||||
}
|
||||
model: questionnaire.runinfo
|
||||
pk: 2
|
||||
|
@ -97,12 +97,12 @@
|
|||
emailcount: 0,
|
||||
emailsent: !!timestamp '2009-05-16 15:05:11.775082',
|
||||
lastemailerror: null,
|
||||
questionset: 2,
|
||||
questionset: 3,
|
||||
random: 'test:withouttags',
|
||||
runid: 'test:withouttags',
|
||||
state: '',
|
||||
subject: 1,
|
||||
tags: ''
|
||||
tags: '',
|
||||
subject: 1
|
||||
}
|
||||
model: questionnaire.runinfo
|
||||
pk: 3
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
{% if progress %}
|
||||
<div id="progress_bar" class="ui-progress-bar ui-container">
|
||||
<div class="ui-progress" style="width: {{progress.0}}%;">
|
||||
<span class="ui-label"><b class="value">{{progress.0}}%</b></span>
|
||||
<div class="ui-progress" style="width: {{progress}}%;">
|
||||
<span class="ui-label"><b class="value">{{progress}}%</b></span>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -152,4 +152,40 @@ class TypeTest(TestCase):
|
|||
question__number=k)
|
||||
|
||||
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)
|
|
@ -320,14 +320,6 @@ def questionnaire(request, runcode=None, qs=None):
|
|||
transaction.commit()
|
||||
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):
|
||||
"Returns the total of visible questionsets"
|
||||
sets = runinfo.questionset.questionnaire.questionsets()
|
||||
|
@ -437,7 +429,11 @@ def show_questionnaire(request, runinfo, errors={}):
|
|||
if not all((pos, total)):
|
||||
progress = None
|
||||
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:
|
||||
for k,v in request.POST.items():
|
||||
|
|
Loading…
Reference in New Issue