diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_event_questions/tests | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_event_questions/tests')
4 files changed, 212 insertions, 0 deletions
diff --git a/addons/website_event_questions/tests/__init__.py b/addons/website_event_questions/tests/__init__.py new file mode 100644 index 00000000..38db7698 --- /dev/null +++ b/addons/website_event_questions/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import common +from . import test_event_internals +from . import test_event_ui diff --git a/addons/website_event_questions/tests/common.py b/addons/website_event_questions/tests/common.py new file mode 100644 index 00000000..7ad2697a --- /dev/null +++ b/addons/website_event_questions/tests/common.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.event.tests.common import TestEventCommon + + +class TestEventQuestionCommon(TestEventCommon): + + @classmethod + def setUpClass(cls): + super(TestEventQuestionCommon, cls).setUpClass() + + cls.event_question_1 = cls.env['event.question'].create({ + 'title': 'Question1', + 'question_type': 'simple_choice', + 'event_type_id': cls.event_type_complex.id, + 'once_per_order': False, + 'answer_ids': [ + (0, 0, {'name': 'Q1-Answer1'}), + (0, 0, {'name': 'Q1-Answer2'}) + ], + }) + cls.event_question_2 = cls.env['event.question'].create({ + 'title': 'Question2', + 'question_type': 'simple_choice', + 'event_type_id': cls.event_type_complex.id, + 'once_per_order': True, + 'answer_ids': [ + (0, 0, {'name': 'Q2-Answer1'}), + (0, 0, {'name': 'Q2-Answer2'}) + ], + }) + cls.event_question_3 = cls.env['event.question'].create({ + 'title': 'Question3', + 'question_type': 'text_box', + 'event_type_id': cls.event_type_complex.id, + 'once_per_order': True, + }) + cls.event_type_complex.write({'use_questions': True}) diff --git a/addons/website_event_questions/tests/test_event_internals.py b/addons/website_event_questions/tests/test_event_internals.py new file mode 100644 index 00000000..28c90997 --- /dev/null +++ b/addons/website_event_questions/tests/test_event_internals.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from datetime import datetime, timedelta + +from odoo.fields import Datetime as FieldsDatetime +from odoo.tests.common import users +from odoo.addons.website.tools import MockRequest +from odoo.addons.website_event_questions.controllers.main import WebsiteEvent +from odoo.addons.website_event_questions.tests.common import TestEventQuestionCommon + + +class TestEventData(TestEventQuestionCommon): + + @users('user_eventmanager') + def test_event_type_configuration_from_type(self): + event_type = self.event_type_complex.with_user(self.env.user) + + event = self.env['event.event'].create({ + 'name': 'Event Update Type', + 'event_type_id': event_type.id, + 'date_begin': FieldsDatetime.to_string(datetime.today() + timedelta(days=1)), + 'date_end': FieldsDatetime.to_string(datetime.today() + timedelta(days=15)), + }) + + self.assertEqual( + event.question_ids.mapped('question_type'), + ['simple_choice', 'simple_choice', 'text_box']) + self.assertEqual(event.specific_question_ids.title, 'Question1') + self.assertEqual( + set(event.specific_question_ids.mapped('answer_ids.name')), + set(['Q1-Answer1', 'Q1-Answer2'])) + self.assertEqual(len(event.general_question_ids), 2) + self.assertEqual(event.general_question_ids[0].title, 'Question2') + self.assertEqual(event.general_question_ids[1].title, 'Question3') + self.assertEqual( + set(event.general_question_ids[0].mapped('answer_ids.name')), + set(['Q2-Answer1', 'Q2-Answer2'])) + + def test_process_attendees_form(self): + event = self.env['event.event'].create({ + 'name': 'Event Update Type', + 'event_type_id': self.event_type_complex.with_user(self.env.user).id, + 'date_begin': FieldsDatetime.to_string(datetime.today() + timedelta(days=1)), + 'date_end': FieldsDatetime.to_string(datetime.today() + timedelta(days=15)), + }) + + form_details = { + '1-name': 'Pixis', + '1-email': 'pixis@gmail.com', + '1-phone': '+32444444444', + '1-event_ticket_id': '2', + '2-name': 'Geluchat', + '2-email': 'geluchat@gmail.com', + '2-phone': '+32777777777', + '2-event_ticket_id': '3', + 'question_answer-1-%s' % self.event_question_1.id: '5', + 'question_answer-2-%s' % self.event_question_1.id: '9', + 'question_answer-0-%s' % self.event_question_2.id: '7', + 'question_answer-0-%s' % self.event_question_3.id: 'Free Text', + } + + with MockRequest(self.env): + registrations = WebsiteEvent()._process_attendees_form(event, form_details) + + self.assertEqual(registrations, [ + {'name': 'Pixis', 'email': 'pixis@gmail.com', 'phone': '+32444444444', 'event_ticket_id': 2, + 'registration_answer_ids': [ + (0, 0, {'question_id': self.event_question_1.id, 'value_answer_id': 5}), + (0, 0, {'question_id': self.event_question_2.id, 'value_answer_id': 7}), + (0, 0, {'question_id': self.event_question_3.id, 'value_text_box': 'Free Text'})]}, + {'name': 'Geluchat', 'email': 'geluchat@gmail.com', 'phone': '+32777777777', 'event_ticket_id': 3, + 'registration_answer_ids': [ + (0, 0, {'question_id': self.event_question_1.id, 'value_answer_id': 9}), + (0, 0, {'question_id': self.event_question_2.id, 'value_answer_id': 7}), + (0, 0, {'question_id': self.event_question_3.id, 'value_text_box': 'Free Text'})]} + ]) diff --git a/addons/website_event_questions/tests/test_event_ui.py b/addons/website_event_questions/tests/test_event_ui.py new file mode 100644 index 00000000..fdebd0c4 --- /dev/null +++ b/addons/website_event_questions/tests/test_event_ui.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from dateutil.relativedelta import relativedelta + +from odoo import fields, tests + + +@tests.tagged('post_install', '-at_install') +class TestUi(tests.HttpCase): + + def test_01_tickets_questions(self): + """ Will execute the tour that fills up two tickets with a few questions answers + and then assert that the answers are correctly saved for each attendee. """ + + self.design_fair_event = self.env['event.event'].create({ + 'name': 'Design Fair New York', + 'date_begin': fields.Datetime.now() - relativedelta(days=15), + 'date_end': fields.Datetime.now() + relativedelta(days=15), + 'event_ticket_ids': [(0, 0, { + 'name': 'Free', + 'start_sale_date': fields.Datetime.now() - relativedelta(days=15) + }), (0, 0, { + 'name': 'Other', + 'start_sale_date': fields.Datetime.now() - relativedelta(days=15) + })], + 'website_published': True, + 'question_ids': [(0, 0, { + 'title': 'Meal Type', + 'question_type': 'simple_choice', + 'answer_ids': [ + (0, 0, {'name': 'Mixed'}), + (0, 0, {'name': 'Vegetarian'}), + (0, 0, {'name': 'Pastafarian'}) + ] + }), (0, 0, { + 'title': 'Allergies', + 'question_type': 'text_box' + }), (0, 0, { + 'title': 'How did you learn about this event?', + 'question_type': 'simple_choice', + 'once_per_order': True, + 'answer_ids': [ + (0, 0, {'name': 'Our website'}), + (0, 0, {'name': 'Commercials'}), + (0, 0, {'name': 'A friend'}) + ] + })] + }) + + self.start_tour("/", 'test_tickets_questions', login="portal") + + registrations = self.env['event.registration'].search([ + ('email', 'in', ['attendee-a@gmail.com', 'attendee-b@gmail.com']) + ]) + self.assertEqual(len(registrations), 2) + first_registration = registrations.filtered(lambda reg: reg.email == 'attendee-a@gmail.com') + second_registration = registrations.filtered(lambda reg: reg.email == 'attendee-b@gmail.com') + self.assertEqual(first_registration.name, 'Attendee A') + self.assertEqual(first_registration.phone, '+32499123456') + self.assertEqual(second_registration.name, 'Attendee B') + + event_questions = registrations.mapped('event_id.question_ids') + self.assertEqual(len(event_questions), 3) + + first_registration_answers = first_registration.registration_answer_ids + self.assertEqual(len(first_registration_answers), 3) + + self.assertEqual(first_registration_answers.filtered( + lambda answer: answer.question_id.title == 'Meal Type' + ).value_answer_id.name, 'Vegetarian') + + self.assertEqual(first_registration_answers.filtered( + lambda answer: answer.question_id.title == 'Allergies' + ).value_text_box, 'Fish and Nuts') + + self.assertEqual(first_registration_answers.filtered( + lambda answer: answer.question_id.title == 'How did you learn about this event?' + ).value_answer_id.name, 'A friend') + + second_registration_answers = second_registration.registration_answer_ids + self.assertEqual(len(second_registration_answers), 2) + + self.assertEqual(second_registration_answers.filtered( + lambda answer: answer.question_id.title == 'Meal Type' + ).value_answer_id.name, 'Pastafarian') + + self.assertEqual(first_registration_answers.filtered( + lambda answer: answer.question_id.title == 'How did you learn about this event?' + ).value_answer_id.name, 'A friend') |
