19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -1,14 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo import Command
from odoo.addons.website_sale.controllers.main import WebsiteSale
from odoo.addons.website.tools import MockRequest
from odoo.addons.website.tests.common import HttpCaseWithWebsiteUser
from odoo.exceptions import ValidationError
from odoo.fields import Command
from odoo.tests import HttpCase, tagged
from odoo.addons.http_routing.tests.common import MockRequest
from odoo.addons.website_sale.controllers.main import WebsiteSale
_logger = logging.getLogger(__name__)
ATTACHMENT_DATA = [
@ -45,8 +47,9 @@ class TestProductPictureController(HttpCase):
def _create_product_images(self):
with MockRequest(self.product.env, website=self.website):
self.WebsiteSaleController.add_product_images(
self.WebsiteSaleController.add_product_media(
[{'id': attachment.id} for attachment in self.attachments],
'image',
self.product.id,
self.product.product_tmpl_id.id,
)
@ -114,8 +117,9 @@ class TestProductPictureController(HttpCase):
})
self.assertEqual(0, len(product_template.product_variant_ids))
with MockRequest(product_template.env, website=self.website):
self.WebsiteSaleController.add_product_images(
self.WebsiteSaleController.add_product_media(
[{'id': self.attachments[0].id}],
'image',
False,
product_template.id,
[product_template_attribute_line.product_template_value_ids[0].id],
@ -223,26 +227,21 @@ class TestProductPictureController(HttpCase):
@tagged('post_install', '-at_install')
class TestWebsiteSaleEditor(HttpCase):
class TestWebsiteSaleEditor(HttpCaseWithWebsiteUser):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env['res.users'].create({
'name': 'Restricted Editor',
'login': 'restricted',
'password': 'restricted',
'groups_id': [Command.set([
cls.env.ref('base.group_user').id,
cls.env.ref('sales_team.group_sale_manager').id,
cls.env.ref('website.group_website_restricted_editor').id
])]
})
cls.user_website_user.group_ids += cls.env.ref('sales_team.group_sale_manager')
cls.user_website_user.group_ids += cls.env.ref('product.group_product_manager')
def test_category_page_and_products_snippet(self):
category = self.env['product.public.category'].create({
'name': 'Test Category',
})
self.env['product.public.category'].create({
'parent_id': category.id,
'name': 'Test Category - Child',
})
self.env['product.template'].create({
'name': 'Test Product',
'website_published': True,
@ -254,7 +253,7 @@ class TestWebsiteSaleEditor(HttpCase):
'name': 'Test Product Outside Category',
'website_published': True,
})
self.start_tour(self.env['website'].get_client_action_url('/shop'), 'category_page_and_products_snippet_edition', login='restricted')
self.start_tour(self.env['website'].get_client_action_url('/shop'), 'category_page_and_products_snippet_edition', login="admin")
self.start_tour('/shop', 'category_page_and_products_snippet_use', login=None)
def test_website_sale_restricted_editor_ui(self):
@ -263,4 +262,57 @@ class TestWebsiteSaleEditor(HttpCase):
'website_sequence': 0,
'website_published': True,
})
self.start_tour(self.env['website'].get_client_action_url('/shop'), 'website_sale_restricted_editor_ui', login='restricted')
self.start_tour(self.env['website'].get_client_action_url('/shop'), 'website_sale_restricted_editor_ui', login="website_user")
@tagged('post_install', '-at_install')
class TestProductVideoUpload(HttpCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.website = cls.env['website'].browse(1)
cls.WebsiteSaleController = WebsiteSale()
cls.product = cls.env['product.product'].create({
'name': 'Test Video Product',
'standard_price': 100.0,
'list_price': 120.0,
'website_published': True,
})
cls.video_data = {
'src': 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', # A placeholder video URL
'name': 'Test Video',
}
def _upload_video(self):
with MockRequest(self.product.env, website=self.website):
self.WebsiteSaleController.add_product_media(
[{'src': self.video_data['src'], 'name': self.video_data['name']}],
'video',
self.product.id,
self.product.product_tmpl_id.id,
)
def test_video_upload(self):
# Upload a video to the product
self._upload_video()
# Retrieve the product's media data
video_url = self.product.product_template_image_ids[0].video_url
image_1920 = self.product.product_template_image_ids[0].image_1920
# Check that the video URL and thumbnail are correctly saved
self.assertEqual(video_url, self.video_data['src'])
self.assertIsNotNone(image_1920) # Ensure a thumbnail was generated
# Verify that the video was added as part of the media
self.assertEqual(len(self.product.product_template_image_ids), 1)
def test_video_upload_invalid(self):
# Try to upload invalid video data (e.g., empty src)
with MockRequest(self.product.env, website=self.website):
with self.assertRaises(ValidationError):
self.WebsiteSaleController.add_product_media(
[{'src': '', 'name': 'Invalid Video'}],
'video',
self.product.id,
self.product.product_tmpl_id.id,
)