diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-11-26 12:27:48 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-12-05 15:21:28 +0000 |
| commit | 351a4439b3a28d3832cd9bf17840dc9feaad7231 (patch) | |
| tree | 9c038856bc8170e50945465991f83934d1a80ac1 /addons/survey/tests | |
| parent | bb3d4634df39dec2f899397628641d96525e5f6b (diff) | |
[REF] survey: clean results page and its code generating statistics
PURPOSE
As new features are about to land in survey, notably live interactions [1]
and new survey building [2] performing a pre cleaning is necessary. In this
PR we clean survey models by: removing unnecessary fields, cleaning some code
and finally renaming models.
SPECIFICATIONS
Purpose of this commit is to globally rewrite the way statistics are
pre computed and used in results page of surveys. Indeed current code is
very complex, having a lot of calls to the same methods while taking only
part of its results. It also have a mix of model and controller methods,
data is computed several times a bit differently, ...
In this commit we rewrite that part. Including
* a simpler code flow;
* a simpler data structure;
* use a better naming for methods instead of "prepare_results" called
randomly within the code and re-using part of its returned content;
* use record sets / records instead of giving sub-elements of a record
like question.title, label.value, ...
Data structure
* simply give a question_and_page_ids to the template that will iterate
on pages / questions;
* have a graph_data, table_data dictionaries available for graph and
table display with simple entries;
* graph_data: holding all necessary but minimalist data for graph display
if question allows it;
* table_data: holding all necessary but minimalist data for table / summary
display;
* hold record sets of done / failed answers and answer lines;
In this commit we also simplify and clean pagination in survey graph results
* remove page_range helper tool that can be inlined in the templates
directly, doing a simple range;
* fix and improve pagination code;
LINKS
[0] Related to Task ID 2061901 (survey models cleaning and preparation)
[1] Task ID 1972640 (live interactions)
[2] Task ID 2119587 (new frontend for building surveys)
PR #40765
Diffstat (limited to 'addons/survey/tests')
| -rw-r--r-- | addons/survey/tests/test_survey.py | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/addons/survey/tests/test_survey.py b/addons/survey/tests/test_survey.py index 23ccab5f83e..77ed53f6a69 100644 --- a/addons/survey/tests/test_survey.py +++ b/addons/survey/tests/test_survey.py @@ -120,53 +120,3 @@ class TestSurveyInternals(common.TestSurveyCommon): question.validate_question('valid'), {} ) - - @users('survey_manager') - def test_result_data_simple_multiple_choice(self): - question = self._add_question( - self.page_0, 'Q0', 'simple_choice', - labels=[{'value': 'Choice0'}, {'value': 'Choice1'}] - ) - for i in range(3): - answer = self._add_answer(self.survey, False, email='public@example.com') - self._add_answer_line( - question, answer, random.choice(question.suggested_answer_ids.ids), - answer_type='suggestion', answer_fname='suggested_answer_id') - lines = [line.suggested_answer_id.id for line in question.user_input_line_ids] - answers = [{'text': label.value, 'count': lines.count(label.id), 'answer_id': label.id, 'answer_score': label.answer_score} for label in question.suggested_answer_ids] - prp_result = self.env['survey.survey'].prepare_result(question)['answers'] - self.assertItemsEqual(prp_result, answers) - - @users('survey_manager') - def test_result_data_matrix(self): - question = self._add_question( - self.page_0, 'Q0', 'matrix', matrix_subtype='simple', - labels=[{'value': 'Column0'}, {'value': 'Column1'}], - labels_2=[{'value': 'Row0'}, {'value': 'Row1'}] - ) - for i in range(3): - answer = self._add_answer(self.survey, False, email='public@example.com') - self._add_answer_line( - question, answer, random.choice(question.suggested_answer_ids.ids), - answer_type='suggestion', answer_fname='suggested_answer_id', matrix_row_id=random.choice(question.matrix_row_ids.ids) - ) - lines = [(line.matrix_row_id.id, line.suggested_answer_id.id) for line in question.user_input_line_ids] - res = {} - for i in product(question.matrix_row_ids.ids, question.suggested_answer_ids.ids): - res[i] = lines.count((i)) - self.assertEqual(self.env['survey.survey'].prepare_result(question)['result'], res) - - @users('survey_manager') - def test_result_data_numeric_box(self): - question = self._add_question(self.page_0, 'Q0', 'numerical_box') - num = [float(n) for n in random.sample(range(1, 100), 3)] - nsum = sum(num) - for i in range(3): - answer = self._add_answer(self.survey, False, email='public@example.com') - self._add_answer_line(question, answer, num[i]) - exresult = { - 'average': round((nsum / len(num)), 2), 'max': round(max(num), 2), - 'min': round(min(num), 2), 'sum': nsum, 'most_common': Counter(num).most_common(5)} - result = self.env['survey.survey'].prepare_result(question) - for key in exresult: - self.assertEqual(result[key], exresult[key]) |
