This commit is contained in:
2026-11-08 20:08:53 +08:00
parent 7526a5fe4d
commit 9b924747c5
2692 changed files with 394867 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_replace_website_image_with_ai_tour
from . import test_ai_website_builder
from . import test_ai_website_service_snippets
from . import test_ai_web_page

View File

@@ -0,0 +1,21 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
@tagged("post_install", "-at_install")
class TestAIWebPage(TransactionCase):
def _create_web_page(self, url):
return self.env["ai.web.page"].create({"url": url})
def test_robots_txt_uses_main_domain_for_internal_urls(self):
self.env["website"].create({
"name": "Internal Website",
"domain": "https://shop.example.com",
})
web_page = self._create_web_page("https://blog.example.com/article")
self.assertIn("example.com", web_page._get_internal_domains())
self.assertFalse(web_page._should_check_robots_txt())

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import re
from odoo.tests import tagged
from odoo.addons.ai.tests.common import TestAICommon
from odoo.addons.ai_website.models.ai_website_service_snippets import (
_SNIPPET_GROUPS,
_SNIPPET_HINTS,
)
@tagged('post_install', '-at_install')
class TestAIWebsiteServiceSnippets(TestAICommon):
def test_only_curated_snippets_are_offered(self):
"""The list is an allowlist: anything the AI is offered must have a hint."""
result = self.env['ai.website.service']._create_snippets_list()
self.assertIn('# Available snippets', result)
offered = set(re.findall(r'^\| (s_\w+) \|', result, re.MULTILINE))
self.assertTrue(offered, "the snippet list should not be empty")
self.assertFalse(offered - set(_SNIPPET_HINTS),
"every offered snippet must be in the curated catalog")
# Each row carries the key, its label and its intent hint.
for key in offered:
hint = _SNIPPET_HINTS[key]
self.assertIn(f'| {key} | {hint.label} | {hint.intent} |', result)
groups = set(re.findall(r'^## (.+)$', result, re.MULTILINE))
self.assertFalse(groups - set(_SNIPPET_GROUPS.values()),
"snippets should only be grouped under the declared purposes")
def test_render_snippets(self):
snippets_tree = self.env['ai.website.service']._render_snippets()
self.assertTrue(snippets_tree.xpath('.//snippets[@id="snippet_structure"]'))
self.assertFalse(
snippets_tree.xpath('.//*[@data-oe-model="ir.ui.view"]'),
"Rendered snippets should not contain view-branding attributes.",
)
def test_get_snippet_html(self):
"""A curated key returns its hint and structure; an unknown key returns neither."""
hint, html = self.env['ai.website.service']._get_snippet_html('s_banner')
self.assertEqual(hint, _SNIPPET_HINTS['s_banner'])
self.assertIn('data-snippet="s_banner"', html)
hint, html = self.env['ai.website.service']._get_snippet_html('not_a_real_snippet')
self.assertIsNone(hint)
self.assertIsNone(html)

View File

@@ -0,0 +1,54 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged, HttpCase
from odoo.addons.ai.tests.common import mock_iap_results
from odoo.addons.base.tests.files import PNG_B64, JPG_B64, WEBP_B64
@tagged('post_install', '-at_install')
class TestAIImageGeneration(HttpCase):
def test_replace_image_with_ai_tour(self):
# Current image that will be replaced with AI
attachment = self.env['ir.attachment'].create({
'name': 'Website Image',
'type': 'binary',
'raw': PNG_B64,
'mimetype': 'image/png',
'public': True,
})
# Setup website with a dummy image for the tour to interact with
self.env['website.page'].create({
'name': 'AI Image Test',
'url': '/ai_image_test',
'type': 'qweb',
'key': 'ai_website.ai_image_test',
'arch': f'<t t-call="website.layout"><div><img id="test_image" src="/web/image/ir.attachment/{attachment.id}/raw"/></div></t>',
'website_id': self.env['website'].search([], limit=1).id,
})
image_data = [
("AI Generated 1", JPG_B64, "image/jpeg"),
("AI Generated 2", WEBP_B64, "image/webp"),
]
iap_results = []
for image_name, base64_data, mimetype in image_data:
attachment = self.env['ir.attachment'].create({
'name': image_name,
'type': 'binary',
'raw': base64_data,
'mimetype': mimetype,
'public': True,
})
iap_results.append([
{'type': 'text', 'text': image_name},
{
'type': 'inline_data',
'metadata': {'attachment_id': attachment.id},
'data': base64_data,
'mimetype': mimetype,
},
])
with mock_iap_results(self.env, iap_results):
self.start_tour(self.env["website"].get_client_action_url("/ai_image_test", True), "replace_website_image_with_ai_tour", login="admin")