# Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.tests import tagged from odoo.addons.test_mail_enterprise.tests.common_ai import MailCommonAI @tagged("post_install", "-at_install") class TestMailTemplateAI(MailCommonAI): def setUp(self): super().setUp() self.template.write({ "model_id": self.env.ref("test_mail.model_mail_test_simple").id, "body_html": False, }) def test_prompt_empty_content(self): test_record = self.env["mail.test.simple"].create({"name": "name_A", "email_from": "name_B"}) with self._patch_agent_generate_response( body_html=f"""

Test

{self._wrap_prompt("")}
""", ): rendered = self.template._render_field("body_html", [test_record.id]) self.assertEqual( rendered[test_record.id], "

Test

", msg="Empty prompt should be removed.", ) def test_prompt_sanitized_content(self): test_record = self.env["mail.test.simple"].create({"name": "name_A", "email_from": "name_B"}) with self._patch_agent_generate_response( response=["foo"], body_html=f"""
{self._wrap_prompt("Test")}
""", ): rendered = self.template._render_field("body_html", [test_record.id]) self.assertEqual( rendered[test_record.id], '

foo

', msg="Should sanitize the prompt content.", )