ai*
This commit is contained in:
6
ai_website/tests/__init__.py
Normal file
6
ai_website/tests/__init__.py
Normal 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
|
||||
21
ai_website/tests/test_ai_web_page.py
Normal file
21
ai_website/tests/test_ai_web_page.py
Normal 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())
|
||||
1752
ai_website/tests/test_ai_website_builder.py
Normal file
1752
ai_website/tests/test_ai_website_builder.py
Normal file
File diff suppressed because it is too large
Load Diff
52
ai_website/tests/test_ai_website_service_snippets.py
Normal file
52
ai_website/tests/test_ai_website_service_snippets.py
Normal 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)
|
||||
54
ai_website/tests/test_replace_website_image_with_ai_tour.py
Normal file
54
ai_website/tests/test_replace_website_image_with_ai_tour.py
Normal 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")
|
||||
Reference in New Issue
Block a user