[FIX] website: Make tests demo data independent

Part-of: odoo/odoo#146649
This commit is contained in:
Yannick Tivisse
2023-12-18 23:32:05 +00:00
parent 533df43e67
commit 7466ecd400
18 changed files with 191 additions and 25 deletions
@@ -7,5 +7,10 @@ import odoo.tests
@odoo.tests.tagged('-at_install', 'post_install')
class TestWebsiteSettings(odoo.tests.HttpCase):
def test_01_multi_website_settings(self):
# If not enabled (like in demo data), landing on res.config will try
# to disable module_sale_quotation_builder and raise an issue
group_order_template = self.env.ref('sale_management.group_sale_order_template', raise_if_not_found=False)
if group_order_template:
self.env.ref('base.group_user').write({"implied_ids": [(4, group_order_template.id)]})
self.env['website'].create({'name': "Website Test Settings", 'specific_user_account': True})
self.start_tour("/web", 'website_settings_m2o_dirty', login="admin")
@@ -4,8 +4,14 @@
import odoo.tests
from odoo.addons.website.tests.test_configurator import TestConfiguratorCommon
@odoo.tests.common.tagged('post_install', '-at_install')
class TestConfigurator(TestConfiguratorCommon):
def test_01_configurator_flow(self):
# If not enabled (like in demo data), landing on res.config will try
# to disable module_sale_quotation_builder and raise an issue
group_order_template = self.env.ref('sale_management.group_sale_order_template', raise_if_not_found=False)
if group_order_template:
self.env.ref('base.group_user').write({"implied_ids": [(4, group_order_template.id)]})
self.start_tour('/web#action=website.action_website_configuration', 'configurator_flow', login="admin")
@@ -8,6 +8,11 @@ class TestAutomaticEditor(TestConfiguratorCommon):
# We create a lang because if the new website is displayed in this lang
# instead of the website's default one, the editor won't automatically
# start.
# If not enabled (like in demo data), landing on res.config will try
# to disable module_sale_quotation_builder and raise an issue
group_order_template = self.env.ref('sale_management.group_sale_order_template', raise_if_not_found=False)
if group_order_template:
self.env.ref('base.group_user').write({"implied_ids": [(4, group_order_template.id)]})
self.env['res.lang'].create({
'name': 'Parseltongue',
'code': 'pa_GB',
+28
View File
@@ -26,6 +26,15 @@ class Crawler(HttpCaseWithUserDemo):
def setUp(self):
super(Crawler, self).setUp()
self.env.ref('website.default_website').write({
'social_facebook': "https://www.facebook.com/Odoo",
'social_twitter': 'https://twitter.com/Odoo',
'social_linkedin': 'https://www.linkedin.com/company/odoo',
'social_youtube': 'https://www.youtube.com/user/OpenERPonline',
'social_github': 'https://github.com/odoo',
'social_instagram': 'https://www.instagram.com/explore/tags/odoo/',
'social_tiktok': 'https://www.tiktok.com/@odoo',
})
if hasattr(self.env['res.partner'], 'grade_id'):
# Create at least one published parter, so that /partners doesn't
@@ -96,6 +105,19 @@ class Crawler(HttpCaseWithUserDemo):
_logger.runbot("public crawled %s urls in %.2fs %s queries, %.3fs %.2fq per request, ", count, duration, sql, duration / count, float(sql) / count)
def test_20_crawl_demo(self):
# Demo user without sales/crm/helpdesk/... rights won't be able to access to
# portals like /my/leads. Grant him those rights if exists.
groups = self.env['res.groups']
group_xmlids = [
'sales_team.group_sale_salesman',
'purchase.group_purchase_user',
'helpdesk.group_helpdesk_user',
]
for group_xmlid in group_xmlids:
group = self.env.ref(group_xmlid, raise_if_not_found=False)
if group:
groups += group
self.env.ref('base.group_user').write({'implied_ids': [(4, group.id) for group in groups]})
t0 = time.time()
t0_sql = self.registry.test_cr.sql_log_count
self.authenticate('demo', 'demo')
@@ -106,6 +128,12 @@ class Crawler(HttpCaseWithUserDemo):
_logger.runbot("demo crawled %s urls in %.2fs %s queries, %.3fs %.2fq per request", count, duration, sql, duration / count, float(sql) / count)
def test_30_crawl_admin(self):
# If no forum.post is existing, the route /forum//ask will be called instead -> 404
if 'forum.post' in self.env:
self.env['forum.post'].create({
'name': 'Very Smart Question',
'forum_id': self.env.ref('website_forum.forum_help').id,
})
t0 = time.time()
t0_sql = self.registry.test_cr.sql_log_count
self.authenticate('admin', 'admin')
+7
View File
@@ -76,6 +76,13 @@ class TestMenu(common.TransactionCase):
def test_04_specific_menu_translation(self):
IrModuleModule = self.env['ir.module.module']
if self.env['website'].search_count([]) == 1:
self.env['website'].create({
'name': 'My Website 2',
'domain': '',
'sequence': 20,
})
Menu = self.env['website.menu']
existing_menus = Menu.search([])
@@ -7,4 +7,10 @@ import odoo.tests
class TestWebsitePageManager(odoo.tests.HttpCase):
def test_01_page_manager(self):
if self.env['website'].search_count([]) == 1:
self.env['website'].create({
'name': 'My Website 2',
'domain': '',
'sequence': 20,
})
self.start_tour(self.env['website'].get_client_action_url('/'), 'website_page_manager', login="admin")
+8 -2
View File
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import copy
from odoo.addons.base.tests.common import HttpCaseWithUserPortal, HttpCaseWithUserDemo
from contextlib import nullcontext
@@ -19,8 +20,7 @@ be added:
cr.close()
"""
class UtilPerf(HttpCase):
class UtilPerf(HttpCaseWithUserPortal, HttpCaseWithUserDemo):
def _get_url_hot_query(self, url, cache=True, table_count=False):
""" This method returns the number of SQL Queries used inside a request.
The returned query number will be the same as a "real" (outside of test
@@ -85,6 +85,12 @@ class UtilPerf(HttpCase):
class TestStandardPerformance(UtilPerf):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env['res.users'].browse(2).image_1920 = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGNgYGAAAAAEAAH2FzhVAAAAAElFTkSuQmCC'
@mute_logger('odoo.http')
def test_10_perf_sql_img_controller(self):
self.authenticate('demo', 'demo')
+14
View File
@@ -34,12 +34,26 @@ class TestSnippets(HttpCase):
path = url_encode({
'path': '/?' + snippets_names_encoded
})
if 'mail.group' in self.env and not self.env['mail.group'].search_count([]):
self.env['mail.group'].create({
'name': 'My Mail Group',
'alias_name': 'my_mail_group',
})
self.start_tour("/web#action=website.website_preview&%s" % path, "snippets_all_drag_and_drop", login='admin', timeout=300)
def test_04_countdown_preview(self):
self.start_tour(self.env['website'].get_client_action_url('/'), 'snippet_countdown', login='admin')
def test_05_social_media(self):
self.env.ref('website.default_website').write({
'social_facebook': "https://www.facebook.com/Odoo",
'social_twitter': 'https://twitter.com/Odoo',
'social_linkedin': 'https://www.linkedin.com/company/odoo',
'social_youtube': 'https://www.youtube.com/user/OpenERPonline',
'social_github': 'https://github.com/odoo',
'social_instagram': 'https://www.instagram.com/explore/tags/odoo/',
'social_tiktok': 'https://www.tiktok.com/@odoo',
})
IrAttachment = self.env['ir.attachment']
base = "http://%s:%s" % (HOST, config['http_port'])
IrAttachment.create({
+10 -2
View File
@@ -7,6 +7,7 @@ from werkzeug.urls import url_encode
import odoo
import odoo.tests
from odoo.addons.base.tests.common import HttpCaseWithUserDemo
@odoo.tests.tagged('-at_install', 'post_install')
@@ -61,7 +62,8 @@ class TestUiCustomizeTheme(odoo.tests.HttpCase):
@odoo.tests.tagged('-at_install', 'post_install')
class TestUiHtmlEditor(odoo.tests.HttpCase):
class TestUiHtmlEditor(HttpCaseWithUserDemo):
def test_html_editor_multiple_templates(self):
Website = self.env['website']
View = self.env['ir.ui.view']
@@ -101,7 +103,7 @@ class TestUiHtmlEditor(odoo.tests.HttpCase):
self.assertEqual(len(specific_page.inherit_children_ids.filtered(lambda v: 'oe_structure' in v.name)), 1, "oe_structure view should have been created on the specific tree")
def test_html_editor_scss(self):
self.env.ref('base.user_demo').write({
self.user_demo.write({
'groups_id': [(6, 0, [
self.env.ref('base.group_user').id,
self.env.ref('website.group_website_designer').id
@@ -402,6 +404,12 @@ class TestUi(odoo.tests.HttpCase):
def test_24_snippet_cache_across_websites(self):
default_website = self.env.ref('website.default_website')
if self.env['website'].search_count([]) == 1:
self.env['website'].create({
'name': 'My Website 2',
'domain': '',
'sequence': 20,
})
self.env['ir.ui.view'].with_context(website_id=default_website.id).save_snippet(
name='custom_snippet_test',
arch="""
@@ -2,10 +2,20 @@
# -*- coding: utf-8 -*-
import odoo.tests
from odoo.addons.base.tests.common import HttpCaseWithUserPortal
@odoo.tests.tagged('post_install', '-at_install')
class TestWebsiteFormEditor(odoo.tests.HttpCase):
class TestWebsiteFormEditor(HttpCaseWithUserPortal):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.company.email = "info@yourcompany.example.com"
cls.env.ref("base.user_admin").write({
'name': "Mitchell Admin",
'phone': "+1 555-555-5555",
})
def test_tour(self):
self.start_tour(self.env['website'].get_client_action_url('/'), 'website_form_editor_tour', login='admin', timeout=120)
self.start_tour('/', 'website_form_editor_tour_submit')
@@ -13,7 +13,6 @@ class TestWebsiteResetPassword(HttpCase):
def test_01_website_reset_password_tour(self):
"""The goal of this test is to make sure the reset password works."""
# We override unlink because we don't want the email to be auto deleted
# if the send works.
MailMail = odoo.addons.mail.models.mail_mail.MailMail
@@ -33,13 +32,21 @@ class TestWebsiteResetPassword(HttpCase):
'name': 'The King',
'email': 'noop@example.com',
})
website_1 = self.env['website'].browse(1)
website_2 = self.env['website'].browse(2)
websites = self.env['website'].search([])
website_1 = websites[0]
if len(websites) == 1:
website_2 = self.env['website'].create({
'name': 'My Website 2',
'domain': '',
'sequence': 20,
})
else:
website_2 = websites[1]
website_1.domain = "my-test-domain.com"
website_2.domain = "https://domain-not-used.fr"
user.partner_id.website_id = 2
user.partner_id.website_id = website_2.id
self.env.invalidate_all() # invalidate get_base_url
user.action_reset_password()
@@ -47,7 +54,7 @@ class TestWebsiteResetPassword(HttpCase):
self.env.invalidate_all()
user.partner_id.website_id = 1
user.partner_id.website_id = website_1.id
user.action_reset_password()
self.assertIn(website_1.domain, user.signup_url)
+27 -1
View File
@@ -12,9 +12,35 @@ class TestBlogPerformance(UtilPerf):
if 'channel_id' in self.env['website']:
self.env['website'].search([]).channel_id = False
self.env['blog.blog'].search([]).active = False
blogs = self.env['blog.blog'].create([{
"name": 'aaa Blog Test',
"subtitle": 'Blog Test Subtitle',
"cover_properties": """{"background-image": "url('/website_blog/static/src/img/blog_1.jpeg')", "resize_class": "o_record_has_cover o_half_screen_height", "opacity": "0.4"}""",
}, {
"name": 'bbb Blog Test',
"subtitle": 'Blog Test Subtitle',
"cover_properties": """{"background-image": "url('/website_blog/static/src/img/blog_1.jpeg')", "resize_class": "o_record_has_cover o_half_screen_height", "opacity": "0.4"}""",
}])
blog_tags = self.env['blog.tag'].create([{
'name': 'Tag 1',
}, {
'name': 'Tag 2',
}])
self.env['blog.post'].create([{
"name": "Post Test",
"subtitle": "Subtitle Test",
"blog_id": blog.id,
"author_id": self.env.user.id,
"tag_ids": [(4, tag.id) for tag in blog_tags],
"is_published": True,
"cover_properties": """{"background-image": "url('/website_blog/static/src/img/cover_1.jpg')", "resize_class": "o_record_has_cover o_half_screen_height", "opacity": "0"}""",
} for blog in blogs])
def test_10_perf_sql_blog_standard_data(self):
self.assertEqual(self._get_url_hot_query('/blog'), 11)
self.assertLessEqual(self._get_url_hot_query('/blog', cache=False), 26)
self.assertLessEqual(self._get_url_hot_query('/blog', cache=False), 23)
def test_20_perf_sql_blog_bigger_data_scaling(self):
BlogPost = self.env['blog.post']
+23 -1
View File
@@ -5,7 +5,29 @@ import odoo.tests
@odoo.tests.tagged('post_install', '-at_install')
class TestUi(odoo.tests.HttpCase):
class TestWebsiteBlogUi(odoo.tests.HttpCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
blog = cls.env['blog.blog'].create({
"name": 'aaa Blog Test',
"subtitle": 'Blog Test Subtitle',
"cover_properties": """{"background-image": "url('/website_blog/static/src/img/blog_1.jpeg')", "resize_class": "o_record_has_cover o_half_screen_height", "opacity": "0.4"}""",
})
blog_tag = cls.env.ref('website_blog.blog_tag_2', raise_if_not_found=False)
if not blog_tag:
blog_tag = cls.env['blog.tag'].create({'name': 'adventure'})
cls.env['blog.post'].create({
"name": "Post Test",
"subtitle": "Subtitle Test",
"blog_id": blog.id,
"author_id": cls.env.user.id,
"tag_ids": [(4, blog_tag.id)],
"is_published": True,
"cover_properties": """{"background-image": "url('/website_blog/static/src/img/cover_1.jpg')", "resize_class": "o_record_has_cover o_half_screen_height", "opacity": "0"}""",
})
def test_admin(self):
# Ensure at least two blogs exist for the step asking to select a blog
self.env['blog.blog'].create({'name': 'Travel'})
@@ -379,7 +379,8 @@ class TestForumKarma(TestForumCommon):
for post_user_group in groups:
self.assertEqual(post_user_group['__count'], 1)
check_vote_records_count_and_integrity(2)
ORIGIN_COUNT = len(self.env['forum.post.vote'].search([]).post_id)
check_vote_records_count_and_integrity(ORIGIN_COUNT)
self.post.create_uid.karma = KARMA['ask']
self.user_portal.karma = KARMA['dwv']
initial_vote_count = self.post.vote_count
@@ -416,7 +417,7 @@ class TestForumKarma(TestForumCommon):
self.post.invalidate_recordset()
self.assertEqual(post_as_portal.user_vote, -1)
check_vote_records_count_and_integrity(3)
check_vote_records_count_and_integrity(ORIGIN_COUNT + 1)
@mute_logger('odoo.addons.base.models.ir_model', 'odoo.models')
def test_vote_crash(self):
@@ -7,6 +7,14 @@ from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestUi(HttpCaseGamification):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env['forum.post'].create({
'name': 'Very Smart Question',
'forum_id': cls.env.ref('website_forum.forum_help').id,
})
def test_01_admin_forum_tour(self):
self.start_tour("/", 'question', login="admin", step_delay=100)
@@ -5,7 +5,7 @@ import json
from odoo.tests.common import HttpCase, new_test_user
class TestController(HttpCase):
class TestAttachmentController(HttpCase):
@classmethod
def setUpClass(cls):
@@ -27,8 +27,12 @@ class TestController(HttpCase):
}
def test_01_portal_attachment(self):
post = self.env['forum.post'].create({
"name": "Forum Post Test",
"forum_id": self.env.ref("website_forum.forum_help").id,
})
self.authenticate(self.portal_user.login, self.portal_user.login)
payload = self._build_payload({'name': 'pixel', 'data': self.pixel, 'is_image': True, 'res_model': 'forum.post', 'res_id': 1})
payload = self._build_payload({'name': 'pixel', 'data': self.pixel, 'is_image': True, 'res_model': 'forum.post', 'res_id': post.id})
self.portal_user.karma = 30
response = self.url_open('/web_editor/attachment/add_data', data=json.dumps(payload), headers=self.headers, timeout=60000)
self.assertEqual(200, response.status_code)
@@ -45,7 +49,7 @@ class TestController(HttpCase):
attachment = self.env['ir.attachment'].create([{'name': 'test_pixel', 'public': True, 'res_id': False,
'mimetype': 'text/plain', 'res_model': 'forum.post',
'raw': self.pixel, 'website_id': 1}])
'raw': self.pixel, 'website_id': self.env.ref('website.default_website').id}])
domain = [('name', '=', 'test_pixel')]
result = attachment.search(domain, limit=1)
self.assertTrue(result, "No attachment fetched")
@@ -19,9 +19,12 @@ registry.category("web_tour.tours").add('website_links_tour', {
run: function () {
var url = window.location.host + '/contactus';
$('#o_website_links_link_tracker_form input#url').val(url);
$('.o_website_links_utm_forms input#campaign-select').val(1).change();
$('.o_website_links_utm_forms input#channel-select').val(1).change();
$('.o_website_links_utm_forms input#source-select').val(1).change();
const campaignId = Object.entries($('#s2id_campaign-select')[0]).find(([key, value]) => value.select2)[1].select2.opts.data.find(d => d.text === "Sale").id
$('.o_website_links_utm_forms input#campaign-select').val(campaignId).change();
const channelId = Object.entries($('#s2id_channel-select')[0]).find(([key, value]) => value.select2)[1].select2.opts.data.find(d => d.text === "Website").id
$('.o_website_links_utm_forms input#channel-select').val(channelId).change();
const sourceId = Object.entries($('#s2id_source-select')[0]).find(([key, value]) => value.select2)[1].select2.opts.data.find(d => d.text === "Search engine").id
$('.o_website_links_utm_forms input#source-select').val(sourceId).change();
// Patch and ignore write on clipboard in tour as we don't have permissions
const oldWriteText = browser.navigator.clipboard.writeText;
browser.navigator.clipboard.writeText = () => { console.info('Copy in clipboard ignored!') };
@@ -44,7 +47,7 @@ registry.category("web_tour.tours").add('website_links_tour', {
run: function () {
var expectedUrl = "/contactus?utm_campaign=Sale&utm_source=Search+engine&utm_medium=Website";
if (window.location.pathname + window.location.search !== expectedUrl) {
console.error("The link was not correctly created.");
console.error("The link was not correctly created. " + window.location.search);
}
window.location.href = '/r';
},
+4 -4
View File
@@ -9,7 +9,7 @@ import odoo.tests
class TestUi(odoo.tests.HttpCase):
def setUp(self):
super(TestUi, self).setUp()
super().setUp()
def _get_title_from_url(addr, **kw):
return 'Contact Us | My Website'
@@ -19,9 +19,9 @@ class TestUi(odoo.tests.HttpCase):
def test_01_test_ui(self):
self.env['link.tracker'].search_or_create({
'campaign_id': 2,
'medium_id': 2,
'source_id': 2,
'campaign_id': self.env['utm.campaign'].create({'name': 'Sale'}).id,
'medium_id': self.env['utm.medium'].create({'name': 'Website'}).id,
'source_id': self.env['utm.source'].create({'name': 'Search'}).id,
'url': self.env["ir.config_parameter"].sudo().get_param("web.base.url") + '/contactus',
})
self.start_tour("/", 'website_links_tour', login="admin")