File: test_survey_ui_feedback.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (350 lines) | stat: -rw-r--r-- 16,014 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import odoo.tests
from odoo import Command
from odoo.addons.base.tests.common import HttpCaseWithUserDemo


@odoo.tests.common.tagged('post_install', '-at_install')
class TestUiFeedback(HttpCaseWithUserDemo):

    def setUp(self):
        super(TestUiFeedback, self).setUp()
        self.survey_feedback = self.env['survey.survey'].create({
            'title': 'User Feedback Form',
            'access_token': 'b137640d-14d4-4748-9ef6-344caaaaaae',
            'access_mode': 'public',
            'users_can_go_back': True,
            'questions_layout': 'page_per_section',
            'description': """<p>This survey allows you to give a feedback about your experience with our eCommerce solution.
    Filling it helps us improving your experience.</p></field>""",
            'question_and_page_ids': [
                (0, 0, {
                    'title': 'General information',
                    'sequence': 1,
                    'question_type': False,
                    'is_page': True,
                    'description': """<p>This section is about general information about you. Answering them helps qualifying your answers.</p>""",
                }), (0, 0, {
                    'title': 'Where do you live?',
                    'sequence': 2,
                    'question_type': 'char_box',
                    'constr_mandatory': False,
                }), (0, 0, {
                    'title': 'When is your date of birth?',
                    'sequence': 3,
                    'question_type': 'date',
                    'description': False,
                }), (0, 0, {
                    'title': 'How frequently do you buy products online?',
                    'sequence': 4,
                    'question_type': 'simple_choice',
                    'comments_allowed': True,
                    'comment_count_as_answer': True,
                    'constr_mandatory': True,
                    'suggested_answer_ids': [
                        (0, 0, {
                            'value': 'Once a day',
                            'sequence': 1,
                        }), (0, 0, {
                            'value': 'Once a week',
                            'sequence': 2,
                        }), (0, 0, {
                            'value': 'Once a month',
                            'sequence': 3,
                        }), (0, 0, {
                            'value': 'Once a year',
                            'sequence': 4,
                        }), (0, 0, {
                            'value': 'Other (answer in comment)',
                            'sequence': 5,
                        })],
                }), (0, 0, {
                    'title': 'How many times did you order products on our website?',
                    'sequence': 5,
                    'question_type': 'numerical_box',
                    'constr_mandatory': True,
                }), (0, 0, {
                    'title': 'About our ecommerce',
                    'sequence': 6,
                    'is_page': True,
                    'question_type': False,
                    'description': """<p>This section is about our eCommerce experience itself.</p>""",
                }), (0, 0, {
                    'title': 'Which of the following words would you use to describe our products?',
                    'sequence': 7,
                    'question_type': 'multiple_choice',
                    'constr_mandatory': True,
                    'comments_allowed': True,
                    'comment_count_as_answer': False,
                    'suggested_answer_ids': [
                        (0, 0, {
                            'value': 'High quality',
                            'sequence': 1,
                        }), (0, 0, {
                            'value': 'Useful',
                            'sequence': 2,
                        }), (0, 0, {
                            'value': 'Unique',
                            'sequence': 3,
                        }), (0, 0, {
                            'value': 'Good value for money',
                            'sequence': 4,
                        }), (0, 0, {
                            'value': 'Overpriced',
                            'sequence': 5,
                        }), (0, 0, {
                            'value': 'Impractical',
                            'sequence': 6,
                        }), (0, 0, {
                            'value': 'Ineffective',
                            'sequence': 7,
                        }), (0, 0, {
                            'value': 'Poor quality',
                            'sequence': 8,
                        }), (0, 0, {
                            'value': 'Other',
                            'sequence': 9,
                        })],
                }), (0, 0, {
                    'title': 'What do your think about our new eCommerce?',
                    'sequence': 8,
                    'question_type': 'matrix',
                    'matrix_subtype': 'multiple',
                    'constr_mandatory': True,
                    'suggested_answer_ids': [(0, 0, {
                        'value': 'Totally disagree',
                        'sequence': 1
                    }), (0, 0, {
                        'value': 'Disagree',
                        'sequence': 2,
                    }), (0, 0, {
                        'value': 'Agree',
                        'sequence': 3,
                    }), (0, 0, {
                        'value': 'Totally agree',
                        'sequence': 4,
                    })],
                    'matrix_row_ids': [(0, 0, {
                        'value': 'The new layout and design is fresh and up-to-date',
                        'sequence': 1,
                    }), (0, 0, {
                        'value': 'It is easy to find the product that I want',
                        'sequence': 2,
                    }), (0, 0, {
                        'value': 'The tool to compare the products is useful to make a choice',
                        'sequence': 3,
                    }), (0, 0, {
                        'value': 'The checkout process is clear and secure',
                        'sequence': 4,
                    }), (0, 0, {
                        'value': 'I have added products to my wishlist',
                        'sequence': 5,
                    })],
                }), (0, 0, {
                    'title': 'Do you have any other comments, questions, or concerns?',
                    'sequence': 9,
                    'question_type': 'text_box',
                    'constr_mandatory': False,
                }), (0, 0, {
                    'title': 'How would you rate your experience on our website?',
                    'sequence': 15,
                    'question_type': 'scale',
                    'scale_min': 1,
                    'scale_max': 5,
                    'scale_min_label': 'Bad experience',
                    'scale_mid_label': 'Do the job',
                    'scale_max_label': 'Very good experience',
                    'constr_mandatory': True,
                }),
            ],
        })

    def test_01_admin_survey_tour(self):
        access_token = self.survey_feedback.access_token
        self.start_tour("/survey/start/%s" % access_token, 'test_survey', login="admin")

    def test_02_demo_survey_tour(self):
        access_token = self.survey_feedback.access_token
        self.start_tour("/survey/start/%s" % access_token, 'test_survey', login="demo")

    def test_03_public_survey_tour(self):
        access_token = self.survey_feedback.access_token
        self.start_tour("/survey/start/%s" % access_token, 'test_survey')

    def test_04_public_survey_with_triggers(self):
        """ Check that chained conditional questions are correctly
        hidden from survey when a previously selected triggering answer is
        unselected. E.g., if a specific answer for "Question 1" is selected,
        which triggers asking "Question 2", and a specific answer for
        "Question 2" is selected and triggers asking "Question 3",
        changing the selected answer for "Question 1" should:
          * hide questions 2 and 3
          * enable submitting the survey without answering questions 2 and 3,
           even if "constr_mandatory=True", as they are not visible.
        """
        survey_with_triggers = self.env['survey.survey'].create({
            'title': 'Survey With Triggers',
            'access_token': '3cfadce3-3f7e-41da-920d-10fa0eb19527',
            'access_mode': 'public',
            'users_can_go_back': True,
            'questions_layout': 'one_page',
            'description': "<p>Test survey with conditional questions</p>",
            'question_and_page_ids': [
                (0, 0, {
                    'title': 'Q1',
                    'sequence': 1,
                    'question_type': 'simple_choice',
                    'suggested_answer_ids': [
                        Command.create({'value': 'Answer 1'}),
                        Command.create({'value': 'Answer 2'}),
                        Command.create({'value': 'Answer 3'}),
                    ],
                    'constr_mandatory': True,
                }), Command.create({
                    'title': 'Q2',
                    'sequence': 2,
                    'question_type': 'simple_choice',
                    'suggested_answer_ids': [
                        Command.create({'value': 'Answer 1'}),
                        Command.create({'value': 'Answer 2'}),
                    ],
                    'constr_mandatory': True,
                }), Command.create({
                    'title': 'Q3',
                    'sequence': 3,
                    'question_type': 'simple_choice',
                    'suggested_answer_ids': [
                        Command.create({'value': 'Answer 1'}),
                        Command.create({'value': 'Answer 2'}),
                    ],
                    'constr_mandatory': True,
                }), Command.create({
                    'title': 'Q4',
                    'sequence': 4,
                    'question_type': 'numerical_box',
                    'constr_mandatory': True,
                })
            ]
        })

        q1, q2, q3, q4 = survey_with_triggers.question_and_page_ids
        q1_a1, __, q1_a3 = q1.suggested_answer_ids
        q2_a1 = q2.suggested_answer_ids[0]

        q2.triggering_answer_ids = q1_a1
        q3.triggering_answer_ids = q1_a3 | q2_a1
        q4.triggering_answer_ids = q1_a1

        access_token = survey_with_triggers.access_token
        self.start_tour("/survey/start/%s" % access_token, 'test_survey_chained_conditional_questions')

    def test_05_public_survey_with_trigger_on_different_page(self):
        """Check that conditional questions are shown when triggered from a different page too."""
        survey_with_trigger_on_different_page = self.env['survey.survey'].create({
            'title': 'Survey With Trigger on a different page',
            'access_token': '1cb935bd-2399-4ed1-9e10-c649318fb4dc',
            'access_mode': 'public',
            'users_can_go_back': True,
            'questions_layout': 'page_per_section',
            'description': "<p>Test survey with conditional questions triggered from a previous section</p>",
            'question_and_page_ids': [
                Command.create({
                    'title': 'Section 1',
                    'is_page': True,
                    'sequence': 1,
                    'question_type': False,
                }), Command.create({
                    'title': 'Q1',
                    'sequence': 2,
                    'question_type': 'simple_choice',
                    'suggested_answer_ids': [
                        Command.create({'value': 'Answer 1'}),
                        Command.create({'value': 'Answer 2'}),
                        Command.create({'value': 'Answer 3'}),
                    ],
                    'constr_mandatory': False,
                }), Command.create({
                    'title': 'Section 2',
                    'is_page': True,
                    'sequence': 3,
                    'question_type': False,
                }), Command.create({
                    'title': 'Q2',
                    'sequence': 4,
                    'question_type': 'simple_choice',
                    'suggested_answer_ids': [
                        Command.create({'value': 'Answer 1'}),
                        Command.create({'value': 'Answer 2'}),
                    ],
                    'constr_mandatory': False,
                }), Command.create({
                    'title': 'Q3',
                    'sequence': 3,
                    'question_type': 'numerical_box',
                    'constr_mandatory': False,
                }),
            ]
        })

        q1 = survey_with_trigger_on_different_page.question_ids.filtered(lambda q: q.title == 'Q1')
        q1_a1 = q1.suggested_answer_ids.filtered(lambda a: a.value == 'Answer 1')

        q2 = survey_with_trigger_on_different_page.question_ids.filtered(lambda q: q.title == 'Q2')
        q2_a1 = q2.suggested_answer_ids.filtered(lambda a: a.value == 'Answer 1')

        q3 = survey_with_trigger_on_different_page.question_ids.filtered(lambda q: q.title == 'Q3')

        q3.triggering_answer_ids = q1_a1 | q2_a1

        access_token = survey_with_trigger_on_different_page.access_token
        self.start_tour("/survey/start/%s" % access_token, 'test_survey_conditional_question_on_different_page')

    def test_06_survey_prefill(self):
        access_token = self.survey_feedback.access_token
        self.start_tour("/survey/start/%s" % access_token, 'test_survey_prefill')

    def test_07_survey_roaming_mandatory_questions(self):
        survey_with_mandatory_questions = self.env['survey.survey'].create({
            'title': 'Survey With Mandatory questions',
            'access_token': '853ebb30-40f2-43bf-a95a-bbf0e367a365',
            'access_mode': 'public',
            'users_can_go_back': True,
            'questions_layout': 'page_per_question',
            'description': "<p>Test survey with roaming freely option and mandatory questions</p>",
            'question_and_page_ids': [
                Command.create({
                    'title': 'Q1',
                    'sequence': 1,
                    'question_type': 'simple_choice',
                    'constr_mandatory': True,
                    'suggested_answer_ids': [
                        Command.create({'value': 'Answer 1'}),
                        Command.create({'value': 'Answer 2'}),
                        Command.create({'value': 'Answer 3'}),
                    ],
                }), Command.create({
                    'title': 'Q2',
                    'sequence': 2,
                    'question_type': 'simple_choice',
                    'constr_mandatory': True,
                    'suggested_answer_ids': [
                        Command.create({'value': 'Answer 1'}),
                        Command.create({'value': 'Answer 2'}),
                        Command.create({'value': 'Answer 3'}),
                    ],
                }), Command.create({
                    'title': 'Q3',
                    'sequence': 3,
                    'question_type': 'simple_choice',
                    'constr_mandatory': True,
                    'suggested_answer_ids': [
                        Command.create({'value': 'Answer 1'}),
                        Command.create({'value': 'Answer 2'}),
                    ],
                }),
            ]
        })

        access_token = survey_with_mandatory_questions.access_token
        self.start_tour("/survey/start/%s" % access_token, 'test_survey_roaming_mandatory_questions')