[IMP] sale_product_configurator: Adapt tests to work with/without demo data

This commit is contained in:
Yannick Tivisse
2019-11-05 16:18:10 +01:00
parent 0a829410a6
commit 2f44fd9a8f
7 changed files with 125 additions and 26 deletions
@@ -9,7 +9,7 @@ tour.register('sale_product_configurator_advanced_tour', {
url: "/web",
test: true,
}, [tour.STEPS.SHOW_APPS_MENU_ITEM, {
trigger: '.o_app[data-menu-xmlid="sale.sale_menu_root"]',
trigger: '.o_app[data-menu-xmlid="sale.sale_menu_root"]', // Note: The module sale_management is mandatory
edition: 'community'
}, {
trigger: '.o_app[data-menu-xmlid="sale.sale_menu_root"]',
@@ -37,7 +37,7 @@ tour.register('sale_product_configurator_advanced_tour', {
$input.trigger(keyDownEvent);
}
}, {
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk")',
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk (TEST)")',
run: 'click'
}, {
trigger: 'span:contains("Custom")',
@@ -103,14 +103,14 @@ tour.register('sale_product_configurator_advanced_tour', {
extra_trigger: '.oe_optional_products_modal',
run: function () {} //check
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("Conference Chair (CONFIG) (Steel)")',
trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("Conference Chair (TEST) (Steel)")',
run: function () {
optionVariantImage = $('.oe_optional_products_modal .js_product:eq(1) img.variant_image').attr('src');
}
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) input[data-value_name="Aluminium"]',
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("Conference Chair (CONFIG) (Aluminium)")',
trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("Conference Chair (TEST) (Aluminium)")',
run: function () {
var newVariantImage = $('.oe_optional_products_modal .js_product:eq(1) img.variant_image').attr('src');
if (newVariantImage !== optionVariantImage) {
@@ -126,7 +126,7 @@ tour.register('sale_product_configurator_advanced_tour', {
extra_trigger: '.oe_optional_products_modal',
run: 'click'
}, {
trigger: 'td.o_data_cell:contains("Customizable Desk (CONFIG) (Custom, White, PAV9, PAV5, PAV1)")',
trigger: 'td.o_data_cell:contains("Customizable Desk (TEST) (Custom, White, PAV9, PAV5, PAV1)")',
extra_trigger: 'div[name="order_line"]',
in_modal: false,
run: function (){} //check
@@ -28,7 +28,7 @@ tour.register('sale_product_configurator_edition_tour', {
$input.trigger(keyDownEvent);
}
}, {
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk")',
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk (TEST)")',
run: 'click'
}, {
trigger: '.configurator_container span:contains("Steel")',
@@ -49,7 +49,7 @@ tour.register('sale_product_configurator_edition_tour', {
extra_trigger: '.oe_optional_products_modal',
run: 'click'
}, {
trigger: 'td.o_data_cell:contains("Customizable Desk (CONFIG) (Aluminium, White)")',
trigger: 'td.o_data_cell:contains("Customizable Desk (TEST) (Aluminium, White)")',
extra_trigger: 'div[name="order_line"]',
run: function (){} // check added product
}, {
@@ -94,7 +94,7 @@ tour.register('sale_product_configurator_edition_tour', {
}, {
trigger: '.o_sale_product_configurator_edit',
}, {
trigger: 'td.o_data_cell:contains("Customizable Desk (CONFIG) (Custom, Black)")',
trigger: 'td.o_data_cell:contains("Customizable Desk (TEST) (Custom, Black)")',
extra_trigger: 'div[name="order_line"]',
run: function (){} // check updated product
}, {
@@ -148,7 +148,7 @@ tour.register('sale_product_configurator_edition_tour', {
run: function () {
// used to check that the description does not contain a custom value anymore
if ($('td.o_data_cell:contains("Custom: another nice custom value")').length === 0){
$('td.o_data_cell:contains("Customizable Desk (CONFIG) (Steel, Black)")').html('tour success');
$('td.o_data_cell:contains("Customizable Desk (TEST) (Steel, Black)")').html('tour success');
}
}
}, {
@@ -28,7 +28,7 @@ tour.register('sale_product_configurator_optional_products_tour', {
$input.trigger(keyDownEvent);
}
}, {
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk")',
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk (TEST)")',
run: 'click'
}, {
trigger: '.o_sale_product_configurator_add'
@@ -48,7 +48,7 @@ tour.STEPS.SHOW_APPS_MENU_ITEM,
$input.trigger(keyDownEvent);
}
}, {
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk")',
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk (TEST)")',
run: 'click'
}, {
content: "check price is correct (USD)",
@@ -66,7 +66,7 @@ tour.STEPS.SHOW_APPS_MENU_ITEM,
trigger: '.o_sale_product_configurator_add:not(.disabled)'
}, {
content: "check we are on the add modal",
trigger: '.td-product_name:contains("Customizable Desk (CONFIG) (Steel, White)")',
trigger: '.td-product_name:contains("Customizable Desk (TEST) (Steel, White)")',
extra_trigger: '.oe_optional_products_modal',
run: 'click'
}, {
@@ -29,7 +29,7 @@ tour.register('sale_product_configurator_single_custom_attribute_tour', {
$input.trigger(keyDownEvent);
}
}, {
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk")',
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk (TEST)")',
run: 'click'
}, {
trigger: '.configurator_container span:contains("Aluminium")',
@@ -32,7 +32,7 @@ tour.register('sale_product_configurator_tour', {
$input.trigger(keyDownEvent);
}
}, {
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk")',
trigger: 'ul.ui-autocomplete a:contains("Customizable Desk (TEST)")',
run: 'click'
}, {
trigger: '.configurator_container span:contains("Steel")',
@@ -71,12 +71,12 @@ tour.register('sale_product_configurator_tour', {
},
// check that 3 products were added to the SO
{
trigger: 'td.o_data_cell:contains("Customizable Desk (CONFIG) (Aluminium, White)")',
trigger: 'td.o_data_cell:contains("Customizable Desk (TEST) (Aluminium, White)")',
extra_trigger: 'div[name="order_line"]',
in_modal: false,
run: function (){}
}, {
trigger: 'td.o_data_cell:contains("Conference Chair (CONFIG) (Aluminium)")',
trigger: 'td.o_data_cell:contains("Conference Chair (TEST) (Aluminium)")',
extra_trigger: 'div[name="order_line"]',
in_modal: false,
run: function (){}
@@ -1,11 +1,107 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import base64
import odoo.tests
from odoo.modules.module import get_module_resource
@odoo.tests.tagged('post_install', '-at_install')
class TestUi(odoo.tests.HttpCase):
def setUp(self):
super(TestUi, self).setUp()
# Setup attributes and attributes values
self.product_attribute_1 = self.env['product.attribute'].create({
'name': 'Legs',
'sequence': 10,
})
product_attribute_value_1 = self.env['product.attribute.value'].create({
'name': 'Steel',
'attribute_id': self.product_attribute_1.id,
'sequence': 1,
})
product_attribute_value_2 = self.env['product.attribute.value'].create({
'name': 'Aluminium',
'attribute_id': self.product_attribute_1.id,
'sequence': 2,
})
product_attribute_2 = self.env['product.attribute'].create({
'name': 'Color',
'sequence': 20,
})
product_attribute_value_3 = self.env['product.attribute.value'].create({
'name': 'White',
'attribute_id': product_attribute_2.id,
'sequence': 1,
})
product_attribute_value_4 = self.env['product.attribute.value'].create({
'name': 'Black',
'attribute_id': product_attribute_2.id,
'sequence': 2,
})
# Create product template
self.product_product_4_product_template = self.env['product.template'].create({
'name': 'Customizable Desk (TEST)',
'standard_price': 500.0,
'list_price': 750.0,
})
# Generate variants
self.env['product.template.attribute.line'].create([{
'product_tmpl_id': self.product_product_4_product_template.id,
'attribute_id': self.product_attribute_1.id,
'value_ids': [(4, product_attribute_value_1.id), (4, product_attribute_value_2.id)],
}, {
'product_tmpl_id': self.product_product_4_product_template.id,
'attribute_id': product_attribute_2.id,
'value_ids': [(4, product_attribute_value_3.id), (4, product_attribute_value_4.id)],
}])
# Apply a price_extra for the attribute Aluminium
self.product_product_4_product_template.attribute_line_ids[0].product_template_value_ids[1].price_extra = 50.40
# Add a Custom attribute
product_attribute_value_7 = self.env['product.attribute.value'].create({
'name': 'Custom',
'attribute_id': self.product_attribute_1.id,
'sequence': 3,
'is_custom': True
})
self.product_product_4_product_template.attribute_line_ids[0].write({'value_ids': [(4, product_attribute_value_7.id)]})
# Disable the aluminium + black product
self.product_product_4_product_template.product_variant_ids[3].active = False
# Setup a first optional product
img_path = get_module_resource('product', 'static', 'img', 'product_product_11-image.png')
img_content = base64.b64encode(open(img_path, "rb").read())
self.product_product_11_product_template = self.env['product.template'].create({
'name': 'Conference Chair (TEST)',
'image_1920': img_content,
'list_price': 16.50,
})
self.env['product.template.attribute.line'].create({
'product_tmpl_id': self.product_product_11_product_template.id,
'attribute_id': self.product_attribute_1.id,
'value_ids': [(4, product_attribute_value_1.id), (4, product_attribute_value_2.id)],
})
self.product_product_4_product_template.optional_product_ids = [(4, self.product_product_11_product_template.id)]
# Setup a second optional product
self.product_product_1_product_template = self.env['product.template'].create({
'name': 'Chair floor protection',
'list_price': 12.0,
})
self.product_product_11_product_template.optional_product_ids = [(4, self.product_product_1_product_template.id)]
def test_01_product_configurator(self):
# To be able to test the product configurator, admin user must have access to "variants" feature, so we give him the right group for that
self.env.ref('base.user_admin').write({'groups_id': [(4, self.env.ref('product.group_product_variant').id)]})
@@ -63,7 +159,7 @@ class TestUi(odoo.tests.HttpCase):
'attribute_id': product_attribute.id
} for i in range(1, 11) for product_attribute in product_attributes])
product_template = self.env.ref("product.product_product_4_product_template")
product_template = self.product_product_4_product_template
self.env['product.template.attribute.line'].create([{
'attribute_id': product_attribute.id,
@@ -104,7 +200,7 @@ class TestUi(odoo.tests.HttpCase):
'attribute_id': product_attributes[0].id
}])
product_template = self.env.ref("product.product_product_4_product_template")
product_template = self.product_product_4_product_template
self.env['product.template.attribute.line'].create([{
'attribute_id': product_attributes[0].id,
@@ -131,14 +227,14 @@ class TestUi(odoo.tests.HttpCase):
# Add a 15% tax on desk
tax = self.env['account.tax'].create({'name': "Test tax", 'amount': 15})
self.env.ref('product.product_product_4_product_template').taxes_id = tax
self.product_product_4_product_template.taxes_id = tax
# Remove tax from Conference Chair and Chair floor protection
self.env.ref('sale_product_configurator.product_product_1_product_template').taxes_id = None
self.env.ref('product.product_product_11_product_template').taxes_id = None
self.product_product_1_product_template.taxes_id = None
self.product_product_11_product_template.taxes_id = None
# Make sure pricelist rule exist
product_template = self.env.ref('product.product_product_4_product_template')
product_template = self.product_product_4_product_template
pricelist = self.env.ref('product.list0')
if not pricelist.item_ids.filtered(lambda i: i.product_tmpl_id == product_template and i.applied_on == '1_product' and i.price_discount == 20):
@@ -161,12 +257,15 @@ class TestUi(odoo.tests.HttpCase):
"""
# add an optional product to the office chair and the custo desk for testing purposes
office_chair = self.env.ref('product.product_product_12')
custo_desk = self.env.ref('product.product_product_4')
office_chair = self.env['product.product'].create({
'name': 'Office Chair Black',
})
custo_desk = self.product_product_4_product_template.product_variant_ids[0]
office_chair.update({
'optional_product_ids': [(6, 0, [self.env.ref('sale_product_configurator.product_product_1_product_template').id])]
'optional_product_ids': [(6, 0, [self.product_product_1_product_template.id])]
})
custo_desk.update({
'optional_product_ids': [(6, 0, [self.env.ref('product.product_product_12_product_template').id, self.env.ref('product.product_product_11_product_template').id])]
'optional_product_ids': [(6, 0, [office_chair.product_tmpl_id.id, self.product_product_11_product_template.id])]
})
self.start_tour("/web", 'sale_product_configurator_optional_products_tour', login="admin")