Files
odoo_source/addons/survey/tests/test_survey_flow.py
T
ijas ahammed 3010751e95 [IMP] {hr_recruitment_,website_slides_}survey: remove 'state' field
The goal of the draft state on survey is to have the survey under edition
mode before before sending it to participants. Under this mode:
  - the responsible can test it (can be done with "In Progress" mode)
  - the survey can't be answered (same as the state closed)

The risk that the survey can be leaked before being ready is really
limited. If it's a live survey, participants will have to guess the
4 digits access code and wait for the host to go to the next question.
Else, participant will have to guess the token.

Considering these facts, the use of the draft state is very limited so
'draft' state can be dropped. If we do so, we are left with only two
stages that are 'open' and 'closed'. But whether to consider survey
open or closed can be simply achieved with active field we already
have (if active=False, survey is closed, otherwise it's considered
as open).

So with this commit, we remove the state field from survey and thus
simplify the flow. It means that we no longer require 'Start Survey'
button, and so that button is also removed, and for the closed surveys,
instead of the button 'Set to draft', now we have a 'Reopen' button
which will activate the survey. And instead of displaying few buttons
after saving a record, we now display all the buttons from beginning.

Task ID-2389434
COM PR odoo/odoo#62712
ENT PR odoo/enterprise#15217
UPG PR odoo/upgrade#2006
2021-02-10 17:03:03 +00:00

121 lines
5.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.survey.tests import common
from odoo.tests import tagged
from odoo.tests.common import HttpCase
@tagged('-at_install', 'post_install', 'functional')
class TestSurveyFlow(common.TestSurveyCommon, HttpCase):
def _format_submission_data(self, page, answer_data, additional_post_data):
post_data = {}
post_data['page_id'] = page.id
for question_id, answer_vals in answer_data.items():
question = page.question_ids.filtered(lambda q: q.id == question_id)
post_data.update(self._prepare_post_data(question, answer_vals['value'], post_data))
post_data.update(**additional_post_data)
return post_data
def test_flow_public(self):
# Step: survey manager creates the survey
# --------------------------------------------------
with self.with_user('survey_manager'):
survey = self.env['survey.survey'].create({
'title': 'Public Survey for Tarte Al Djotte',
'access_mode': 'public',
'users_login_required': False,
'questions_layout': 'page_per_section',
})
# First page is about customer data
page_0 = self.env['survey.question'].create({
'is_page': True,
'sequence': 1,
'title': 'Page1: Your Data',
'survey_id': survey.id,
})
page0_q0 = self._add_question(
page_0, 'What is your name', 'text_box',
comments_allowed=False,
constr_mandatory=True, constr_error_msg='Please enter your name', survey_id=survey.id)
page0_q1 = self._add_question(
page_0, 'What is your age', 'numerical_box',
comments_allowed=False,
constr_mandatory=True, constr_error_msg='Please enter your name', survey_id=survey.id)
# Second page is about tarte al djotte
page_1 = self.env['survey.question'].create({
'is_page': True,
'sequence': 4,
'title': 'Page2: Tarte Al Djotte',
'survey_id': survey.id,
})
page1_q0 = self._add_question(
page_1, 'What do you like most in our tarte al djotte', 'multiple_choice',
labels=[{'value': 'The gras'},
{'value': 'The bette'},
{'value': 'The tout'},
{'value': 'The regime is fucked up'}], survey_id=survey.id)
# fetch starting data to check only newly created data during this flow
answers = self.env['survey.user_input'].search([('survey_id', '=', survey.id)])
answer_lines = self.env['survey.user_input.line'].search([('survey_id', '=', survey.id)])
self.assertEqual(answers, self.env['survey.user_input'])
self.assertEqual(answer_lines, self.env['survey.user_input.line'])
# Step: customer takes the survey
# --------------------------------------------------
# Customer opens start page
r = self._access_start(survey)
self.assertResponse(r, 200, [survey.title])
# -> this should have generated a new answer with a token
answers = self.env['survey.user_input'].search([('survey_id', '=', survey.id)])
self.assertEqual(len(answers), 1)
answer_token = answers.access_token
self.assertTrue(answer_token)
self.assertAnswer(answers, 'new', self.env['survey.question'])
# Customer begins survey with first page
r = self._access_page(survey, answer_token)
self.assertResponse(r, 200)
self.assertAnswer(answers, 'new', self.env['survey.question'])
csrf_token = self._find_csrf_token(r.text)
r = self._access_begin(survey, answer_token)
self.assertResponse(r, 200)
# Customer submit first page answers
answer_data = {
page0_q0.id: {'value': ['Alfred Poilvache']},
page0_q1.id: {'value': ['44.0']},
}
post_data = self._format_submission_data(page_0, answer_data, {'csrf_token': csrf_token, 'token': answer_token, 'button_submit': 'next'})
r = self._access_submit(survey, answer_token, post_data)
self.assertResponse(r, 200)
answers.invalidate_cache() # TDE note: necessary as lots of sudo in controllers messing with cache
# -> this should have generated answer lines
self.assertAnswer(answers, 'in_progress', page_0)
self.assertAnswerLines(page_0, answers, answer_data)
# Customer is redirected on second page and begins filling it
r = self._access_page(survey, answer_token)
self.assertResponse(r, 200)
csrf_token = self._find_csrf_token(r.text)
# Customer submit second page answers
answer_data = {
page1_q0.id: {'value': [page1_q0.suggested_answer_ids.ids[0], page1_q0.suggested_answer_ids.ids[1]]},
}
post_data = self._format_submission_data(page_1, answer_data, {'csrf_token': csrf_token, 'token': answer_token, 'button_submit': 'next'})
r = self._access_submit(survey, answer_token, post_data)
self.assertResponse(r, 200)
answers.invalidate_cache() # TDE note: necessary as lots of sudo in controllers messing with cache
# -> this should have generated answer lines and closed the answer
self.assertAnswer(answers, 'done', page_1)
self.assertAnswerLines(page_1, answers, answer_data)