From 32923eef4a03ca2ab675b539ccbe1b906f267c67 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Mon, 4 Nov 2019 16:48:05 +0100 Subject: [PATCH] [IMP] test_website_slides_full: Adapt tests to work with/without demo data --- .../tests/test_ui_wslides.py | 161 +++++++++++++++++- .../tours/slides_certification_member.js | 2 +- 2 files changed, 156 insertions(+), 7 deletions(-) diff --git a/addons/test_website_slides_full/tests/test_ui_wslides.py b/addons/test_website_slides_full/tests/test_ui_wslides.py index 5d8592b9eb2..39ff909e2b5 100644 --- a/addons/test_website_slides_full/tests/test_ui_wslides.py +++ b/addons/test_website_slides_full/tests/test_ui_wslides.py @@ -1,20 +1,169 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from dateutil.relativedelta import relativedelta +from odoo.fields import Datetime from odoo import tests - +from odoo.addons.website_slides.tests.test_ui_wslides import TestUICommon @tests.common.tagged('post_install', '-at_install') -class TestUi(tests.HttpCase): +class TestUi(TestUICommon): def test_course_certification_employee(self): - # remove membership because we need to be able to join the course during the tour - user_demo = self.env.ref('base.user_demo') + user_demo = self.user_demo user_demo.flush() + # Avoid Billing/Shipping address page user_demo.write({ - 'groups_id': [(5, 0), (4, self.env.ref('base.group_user').id)] + 'groups_id': [(5, 0), (4, self.env.ref('base.group_user').id)], + 'street': '215 Vine St', + 'city': 'Scranton', + 'zip': '18503', + 'country_id': self.env.ref('base.us').id, + 'state_id': self.env.ref('base.state_us_39').id, + 'phone': '+1 555-555-5555', + 'email': 'admin@yourcompany.example.com', + }) + + # Specify Accounting Data + cash_journal = self.env['account.journal'].create({'name': 'Cash - Test', 'type': 'cash', 'code': 'CASH - Test'}) + self.env['payment.acquirer'].search([('journal_id', '=', False)]).journal_id = cash_journal + a_recv = self.env['account.account'].create({ + 'code': 'X1012', + 'name': 'Debtors - (test)', + 'reconcile': True, + 'user_type_id': self.env.ref('account.data_account_type_receivable').id, + }) + a_pay = self.env['account.account'].create({ + 'code': 'X1111', + 'name': 'Creditors - (test)', + 'user_type_id': self.env.ref('account.data_account_type_payable').id, + 'reconcile': True, + }) + self.env['ir.property'].create([{ + 'name': 'property_account_receivable_id', + 'fields_id': self.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_account_receivable_id')], limit=1).id, + 'value': 'account.account,%s' % (a_recv.id), + 'company_id': self.env.company.id, + }, { + 'name': 'property_account_payable_id', + 'fields_id': self.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_account_payable_id')], limit=1).id, + 'value': 'account.account,%s' % (a_pay.id), + 'company_id': self.env.company.id, + }]) + + product_course_channel_6 = self.env['product.product'].create({ + 'name': 'DIY Furniture Course', + 'list_price': 100.0, + 'type': 'service', + 'is_published': True, + }) + + furniture_survey = self.env['survey.survey'].create({ + 'title': 'Furniture Creation Certification', + 'access_token': '5632a4d7-48cf-aaaa-8c52-2174d58cf50b', + 'state': 'open', + 'access_mode': 'public', + 'users_can_go_back': True, + 'users_login_required': True, + 'scoring_type': 'scoring_with_answers', + 'certificate': True, + 'certification_mail_template_id': self.env.ref('survey.mail_template_certification').id, + 'is_attempts_limited': True, + 'attempts_limit': 3, + 'description': "

Test your furniture knowledge!

", + 'thank_you_message': "

", + 'question_and_page_ids': [ + (0, 0, { + 'title': 'Furniture', + 'sequence': 1, + 'is_page': True, + 'description': "<p>Test your furniture knowledge!</p>", + }), (0, 0, { + 'title': 'What type of wood is the best for furniture?', + 'sequence': 2, + 'question_type': 'simple_choice', + 'display_mode': 'dropdown', + 'constr_mandatory': True, + 'labels_ids': [ + (0, 0, { + 'value': 'Fir', + 'sequence': 1, + }), (0, 0, { + 'value': 'Oak', + 'sequence': 2, + 'is_correct': True, + 'answer_score': 2.0, + }), (0, 0, { + 'value': 'Ash', + 'sequence': 3, + }), (0, 0, { + 'value': 'Beech', + 'sequence': 4, + }) + ] + }), (0, 0, { + 'title': 'Select all the furniture shown in the video', + 'sequence': 3, + 'question_type': 'multiple_choice', + 'column_nb': '4', + 'labels_ids': [ + (0, 0, { + 'value': 'Chair', + 'sequence': 1, + 'is_correct': True, + 'answer_score': 1.0, + }), (0, 0, { + 'value': 'Table', + 'sequence': 2, + 'answer_score': -1.0, + }), (0, 0, { + 'value': 'Desk', + 'sequence': 3, + 'is_correct': True, + 'answer_score': 1.0, + }), (0, 0, { + 'value': 'Shelve', + 'sequence': 4, + 'is_correct': True, + 'answer_score': 1.0, + }), (0, 0, { + 'value': 'Bed', + 'sequence': 5, + 'answer_score': -1.0, + }) + ] + }), (0, 0, { + 'title': 'What do you think about the content of the course? (not rated)', + 'sequence': 4, + 'question_type': 'free_text', + }) + ] + }) + + slide_channel_demo_6_furn3 = self.env['slide.channel'].create({ + 'name': 'DIY Furniture - TEST', + 'user_id': self.env.ref('base.user_admin').id, + 'enroll': 'payment', + 'product_id': product_course_channel_6.id, + 'channel_type': 'training', + 'allow_comment': True, + 'promote_strategy': 'most_voted', + 'is_published': True, + 'description': 'So much amazing certification.', + 'create_date': Datetime.now() - relativedelta(days=2), + 'slide_ids': [ + (0, 0, { + 'name': 'DIY Furniture Certification', + 'sequence': 1, + 'slide_type': 'certification', + 'category_id': False, + 'is_published': True, + 'is_preview': False, + 'description': "It's time to test your knowledge!", + 'survey_id': furniture_survey.id, + }) + ] }) - self.env.ref('website_slides.slide_channel_demo_6_furn3')._remove_membership(self.env.ref('base.partner_demo').ids) self.browser_js( '/slides', diff --git a/addons/test_website_slides_full/tests/tours/slides_certification_member.js b/addons/test_website_slides_full/tests/tours/slides_certification_member.js index c6f0e699cfd..53681eae54c 100644 --- a/addons/test_website_slides_full/tests/tours/slides_certification_member.js +++ b/addons/test_website_slides_full/tests/tours/slides_certification_member.js @@ -21,7 +21,7 @@ var tour = require('web_tour.tour'); var initTourSteps = [{ content: 'eLearning: go to certification course', - trigger: 'a:contains("DIY Furniture")' + trigger: 'a:contains("DIY Furniture - TEST")' }, { content: 'eLearning: does not have access to certification', trigger: '.o_wslides_course_main',