Skip to content

Commit

Permalink
[ADD] Results test
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Nov 8, 2016
1 parent 042feb6 commit 922a159
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
5 changes: 2 additions & 3 deletions survey_percent_question/models/survey.py
Expand Up @@ -14,10 +14,10 @@ class Survey(models.Model):

@api.model
def prepare_result(self, question, current_filters=None):
'''
"""
Compute statistical data for questions by counting number of vote per
choice on basis of filter
'''
"""
current_filters = current_filters if current_filters else []
result_summary = {}

Expand Down Expand Up @@ -53,7 +53,6 @@ def prepare_result(self, question, current_filters=None):
row[order["comment_value"]] = line["value_number"]
row[order["comment_label"]] = line["value_text"]
result_summary["data"] = list(data.values())

else:
return super(Survey, self).prepare_result(
question, current_filters=current_filters)
Expand Down
37 changes: 31 additions & 6 deletions survey_percent_question/tests/test_percent_question.py
Expand Up @@ -135,10 +135,10 @@ def test_save_line_w_comments(self):
line_obj.save_line_percent_split(
input_id,
self.q_percent,
{"{0}_comment_value".format(self.tag): "30",
{"{0}_comment_value".format(self.tag): "40",
"{0}_comment_label".format(self.tag): "Data",
"{0}_{1}".format(self.tag, self.l_covered.id): "60",
"{0}_{1}".format(self.tag, self.l_uncover.id): "10"},
"{0}_{1}".format(self.tag, self.l_uncover.id): "0"},
self.tag,
)
for line in line_obj.get_old_lines(input_id, self.q_percent):
Expand All @@ -147,11 +147,36 @@ def test_save_line_w_comments(self):
self.assertEquals(line.value_number, 60,
"Covered value should be 60%")
elif line.value_suggested_row.id == self.l_uncover.id:
self.assertEquals(line.value_number, 10,
"Uncovered value should be 10%")
self.assertEquals(line.value_number, 0,
"Uncovered value should be 0%")
else:
raise AssertionError("Unexpected result line")
else:
self.assertEquals(line.value_text, "Data")
self.assertEquals(line.value_number, 30,
"Data value should be 30%")
self.assertEquals(line.value_number, 40,
"Data value should be 40%")

def test_prepare_result(self):
self.q_percent.comments_allowed = True
input_id = self.env["survey.user_input"].create({
"token": "test",
"survey_id": self.survey.id,
}).id
line_obj = self.env["survey.user_input_line"]
line_obj.save_line_percent_split(
input_id,
self.q_percent,
{"{0}_comment_value".format(self.tag): "30",
"{0}_comment_label".format(self.tag): "Data",
"{0}_{1}".format(self.tag, self.l_covered.id): "10",
"{0}_{1}".format(self.tag, self.l_uncover.id): "60"},
self.tag,
)
res = self.env["survey.survey"].prepare_result(
self.q_percent
)
self.assertEquals(res['header'],
['Covered', 'Not Covered', 'Other', 'Comment'])
self.assertEquals(res['data'][0][0], 10)
self.assertEquals(res['data'][0][1], 60)
self.assertEquals(res['data'][0][2], 30)

0 comments on commit 922a159

Please sign in to comment.