Fixing case for freeform answers

EmailTemplateFixes
Griffin Caprio 2015-01-06 18:53:58 -06:00
parent 7ad30322b2
commit 22a8f7e214
2 changed files with 26 additions and 4 deletions

View File

@ -2,6 +2,19 @@ from questionnaire.models import Question, Answer
import logging
def explode_answer_into_list(answers):
answer_list = []
for answer in answers:
if type(answer) == type(list()):
for list_answer in answer:
answer_list.append(list_answer)
else:
answer_list.append(answer)
return answer_list
def check_actual_answers_against_expression(check_answer, actual_answer, check_question):
# Numeric Value Expressions
if check_answer[0:1] in "<>":
@ -122,7 +135,6 @@ def dep_check(expr, runinfo, answerdict):
# Convert freeform question type answers from a list of lists to just a single list.
# FIXME: Figure out why the hell freeform questions store their values as lists within lists.
if type(actual_answer) == type(list()):
actual_answer = actual_answer[0]
answer_list = explode_answer_into_list(actual_answer)
return check_actual_answers_against_expression(check_answer, actual_answer, check_question)
return check_actual_answers_against_expression(check_answer, answer_list, check_question)

View File

@ -1,10 +1,20 @@
from django.test import TestCase
from dependency_checker import check_actual_answers_against_expression
from dependency_checker import check_actual_answers_against_expression, explode_answer_into_list
from .models import Question
class QuestionSetTests(TestCase):
def test_exploding_answer_into_list(self):
answer = ['1A']
self.assertEqual(['1A'], explode_answer_into_list(answer))
answer = ['1A', ['foobar']]
self.assertEqual(['1A', 'foobar'], explode_answer_into_list(answer))
answer = ['1A', ['foobar', 'barfoo']]
self.assertEqual(['1A', 'foobar', 'barfoo'], explode_answer_into_list(answer))
def test_dependencies_for_multiple_choice_question(self):
check_question = Question()
self.assertTrue(check_actual_answers_against_expression('3B', ['3B', '3E'], check_question))