summaryrefslogtreecommitdiff
path: root/addons/website_slides/tests/test_ui_wslides.py
diff options
context:
space:
mode:
authorOdoo's Mergebot <xmo+roboto@odoo.com>2019-11-07 08:37:12 +0100
committerGitHub <noreply@github.com>2019-11-07 08:37:12 +0100
commitcfc65bd1b72b6fb7833f67fa580fa9fdac28b1f5 (patch)
treec1aa353aa7e29d0ed918911dbdce456ed957b72e /addons/website_slides/tests/test_ui_wslides.py
parenta3f5afdd53f5f0d8d76427fe14dce6f02e064a75 (diff)
parentbc8fe668495a1d080ff883d5e61e961a128669de (diff)
[MERGE] various: Make the test suite demo data independant
Purpose ======= This is the first huge step to improve the test suite in several ways: - Make them demo data independent, allowing to modify the demo data without having to adapt the tests depending on it. It also allows to have a beautiful + convenient demo dataset to make a demonstration, and to configure complex data in the tests to manage the corner cases. - Improve the test performances by converting them into SavepointCase. Each test will be rollbacked to it's initial state, after the setUpClass call. That way the different data are not re-created at each test for nothing. - Introduce several test classes in base/tests/common.py to launch a TransactionCase, HttpCase or SavepointCase test with an available demo user, portal user or a large set of partners. - This is the first step to tend to a rolling release process, allowing to execute the tests (or a subset of the tests) on a migrated base, for example. closes odoo/odoo#39868 Taskid: 2075739 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/website_slides/tests/test_ui_wslides.py')
-rw-r--r--addons/website_slides/tests/test_ui_wslides.py109
1 files changed, 94 insertions, 15 deletions
diff --git a/addons/website_slides/tests/test_ui_wslides.py b/addons/website_slides/tests/test_ui_wslides.py
index 82b93de3ec1..4e60263553d 100644
--- a/addons/website_slides/tests/test_ui_wslides.py
+++ b/addons/website_slides/tests/test_ui_wslides.py
@@ -1,19 +1,104 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+import base64
+
+from dateutil.relativedelta import relativedelta
from odoo import tests
+from odoo.fields import Datetime
+from odoo.modules.module import get_module_resource
+from odoo.addons.base.tests.common import HttpCaseWithUserDemo, HttpCaseWithUserPortal
+
+
+class TestUICommon(HttpCaseWithUserDemo, HttpCaseWithUserPortal):
+
+ def setUp(self):
+ super(TestUICommon, self).setUp()
+ # Load pdf and img contents
+ pdf_path = get_module_resource('website_slides', 'static', 'src', 'img', 'presentation.pdf')
+ pdf_content = base64.b64encode(open(pdf_path, "rb").read())
+ img_path = get_module_resource('website_slides', 'static', 'src', 'img', 'slide_demo_gardening_1.jpg')
+ img_content = base64.b64encode(open(img_path, "rb").read())
+
+ self.env['slide.channel'].create({
+ 'name': 'Basics of Gardening - Test',
+ 'user_id': self.env.ref('base.user_admin').id,
+ 'enroll': 'public',
+ 'channel_type': 'training',
+ 'allow_comment': True,
+ 'promote_strategy': 'most_voted',
+ 'is_published': True,
+ 'description': 'Learn the basics of gardening !',
+ 'create_date': Datetime.now() - relativedelta(days=8),
+ 'slide_ids': [
+ (0, 0, {
+ 'name': 'Gardening: The Know-How',
+ 'sequence': 1,
+ 'datas': pdf_content,
+ 'slide_type': 'presentation',
+ 'is_published': True,
+ 'is_preview': True,
+ }), (0, 0, {
+ 'name': 'Home Gardening',
+ 'sequence': 2,
+ 'image_1920': img_content,
+ 'slide_type': 'infographic',
+ 'is_published': True,
+ }), (0, 0, {
+ 'name': 'Mighty Carrots',
+ 'sequence': 3,
+ 'image_1920': img_content,
+ 'slide_type': 'infographic',
+ 'is_published': True,
+ }), (0, 0, {
+ 'name': 'How to Grow and Harvest The Best Strawberries | Basics',
+ 'sequence': 4,
+ 'datas': pdf_content,
+ 'slide_type': 'document',
+ 'is_published': True,
+ }), (0, 0, {
+ 'name': 'Test your knowledge',
+ 'sequence': 5,
+ 'slide_type': 'quiz',
+ 'is_published': True,
+ 'question_ids': [
+ (0, 0, {
+ 'question': 'What is a strawberry ?',
+ 'answer_ids': [
+ (0, 0, {
+ 'text_value': 'A fruit',
+ 'is_correct': True,
+ }), (0, 0, {
+ 'text_value': 'A vegetable',
+ }), (0, 0, {
+ 'text_value': 'A table',
+ })
+ ]
+ }), (0, 0, {
+ 'question': 'What is the best tool to dig a hole for your plants ?',
+ 'answer_ids': [
+ (0, 0, {
+ 'text_value': 'A shovel',
+ 'is_correct': True,
+ }), (0, 0, {
+ 'text_value': 'A spoon',
+ })
+ ]
+ })
+ ]
+ })
+ ]
+ })
@tests.common.tagged('post_install', '-at_install')
-class TestUi(tests.HttpCase):
+class TestUi(TestUICommon):
def test_course_member_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()
user_demo.write({
'groups_id': [(5, 0), (4, self.env.ref('base.group_user').id)]
})
- self.env.ref('website_slides.slide_channel_demo_0_gard_0')._remove_membership(self.env.ref('base.partner_demo').ids)
self.browser_js(
'/slides',
@@ -22,14 +107,11 @@ class TestUi(tests.HttpCase):
login=user_demo.login)
def test_course_member_website_publisher(self):
- # remove membership because we need to be able to join the course during the tour
- # group_website_designer
- user_demo = self.env.ref('base.user_demo')
+ user_demo = self.user_demo
user_demo.flush()
user_demo.write({
'groups_id': [(5, 0), (4, self.env.ref('base.group_user').id), (4, self.env.ref('website.group_website_publisher').id)]
})
- self.env.ref('website_slides.slide_channel_demo_0_gard_0')._remove_membership(self.env.ref('base.partner_demo').ids)
self.browser_js(
'/slides',
@@ -38,11 +120,8 @@ class TestUi(tests.HttpCase):
login=user_demo.login)
def test_course_member_portal(self):
- # remove membership because we need to be able to join the course during the tour
- # group_website_designer
- user_portal = self.env.ref('base.demo_user0')
+ user_portal = self.user_portal
user_portal.flush()
- self.env.ref('website_slides.slide_channel_demo_0_gard_0')._remove_membership(self.env.ref('base.partner_demo_portal').ids)
self.browser_js(
'/slides',
@@ -52,11 +131,11 @@ class TestUi(tests.HttpCase):
@tests.common.tagged('external', 'post_install', '-standard', '-at_install')
-class TestUiYoutube(tests.HttpCase):
+class TestUiYoutube(HttpCaseWithUserDemo):
def test_course_member_yt_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()
user_demo.write({
'groups_id': [(5, 0), (4, self.env.ref('base.group_user').id)]
@@ -72,7 +151,7 @@ class TestUiYoutube(tests.HttpCase):
def test_course_publisher_website_designer(self):
# remove membership because we need to be able to join the course during the tour
# group_website_designer
- user_demo = self.env.ref('base.user_demo')
+ user_demo = self.user_demo
user_demo.flush()
user_demo.write({
'groups_id': [(5, 0), (4, self.env.ref('base.group_user').id), (4, self.env.ref('website.group_website_designer').id)]