mirror of
https://github.com/bringout/oca-ocb-test.git
synced 2026-04-23 15:42:06 +02:00
19.0 vanilla
This commit is contained in:
parent
38c6088dcc
commit
d9452d2060
243 changed files with 30797 additions and 10815 deletions
|
|
@ -2,3 +2,5 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_flow
|
||||
from . import test_server_actions
|
||||
from . import test_tour
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,77 @@
|
|||
# # Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo.addons.base.models.ir_actions import ServerActionWithWarningsError
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.addons.base.tests.test_ir_actions import TestServerActionsBase
|
||||
|
||||
|
||||
class TestServerActionsValidation(TestServerActionsBase):
|
||||
def test_multi_action_children_warnings(self):
|
||||
self.action.write({
|
||||
'state': 'multi',
|
||||
'child_ids': [self.test_server_action.id]
|
||||
})
|
||||
self.assertEqual(self.action.model_id.model, "res.partner")
|
||||
self.assertEqual(self.test_server_action.model_id.model, "ir.actions.server")
|
||||
self.assertEqual(self.action.warning, "Following child actions should have the same model (Contact): TestDummyServerAction")
|
||||
|
||||
new_action = self.action.copy()
|
||||
with self.assertRaises(ValidationError) as ve:
|
||||
new_action.write({
|
||||
'child_ids': [self.action.id]
|
||||
})
|
||||
self.assertEqual(ve.exception.args[0], "Following child actions have warnings: TestAction")
|
||||
|
||||
def test_webhook_payload_includes_group_restricted_fields(self):
|
||||
self.test_server_action.write({
|
||||
'state': 'webhook',
|
||||
'webhook_field_ids': [self.env['ir.model.fields']._get('ir.actions.server', 'code').id],
|
||||
})
|
||||
self.assertEqual(self.test_server_action.warning, "Group-restricted fields cannot be included in "
|
||||
"webhook payloads, as it could allow any user to "
|
||||
"accidentally leak sensitive information. You will "
|
||||
"have to remove the following fields from the webhook payload:\n"
|
||||
"- Python Code")
|
||||
|
||||
def test_recursion_in_child(self):
|
||||
new_action = self.action.copy()
|
||||
self.action.write({
|
||||
'state': 'multi',
|
||||
'child_ids': [new_action.id]
|
||||
})
|
||||
with self.assertRaises(ValidationError) as ve:
|
||||
new_action.write({
|
||||
'child_ids': [self.action.id]
|
||||
})
|
||||
self.assertEqual(ve.exception.args[0], "Recursion found in child server actions")
|
||||
|
||||
def test_non_relational_field_traversal(self):
|
||||
self.action.write({
|
||||
'state': 'object_write',
|
||||
'update_path': 'parent_id.name',
|
||||
'value': 'TestNew',
|
||||
})
|
||||
with self.assertRaises(ValidationError) as ve:
|
||||
self.action.write({'update_path': 'parent_id.name.something_else'})
|
||||
self.assertEqual(ve.exception.args[0], "The path contained by the field "
|
||||
"'Field to Update Path' contains a non-relational field"
|
||||
" (Name) that is not the last field in the path. You "
|
||||
"can't traverse non-relational fields (even in the quantum"
|
||||
" realm). Make sure only the last field in the path is non-relational.")
|
||||
|
||||
def test_python_bad_expr(self):
|
||||
with self.assertRaises(ValidationError) as ve:
|
||||
self.test_server_action.write({'code': 'this is invalid python code'})
|
||||
self.assertEqual(
|
||||
ve.exception.args[0],
|
||||
"SyntaxError : invalid syntax at line 1\n"
|
||||
"this is invalid python code\n")
|
||||
|
||||
def test_cannot_run_if_warnings(self):
|
||||
self.action.write({
|
||||
'state': 'multi',
|
||||
'child_ids': [self.test_server_action.id]
|
||||
})
|
||||
self.assertTrue(self.action.warning)
|
||||
with self.assertRaises(ServerActionWithWarningsError) as e:
|
||||
self.action.run()
|
||||
self.assertEqual(e.exception.args[0], "Server action TestAction has one or more warnings, address them first.")
|
||||
|
|
@ -0,0 +1,304 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from urllib.parse import urlencode
|
||||
import ast
|
||||
|
||||
from odoo import Command
|
||||
|
||||
from odoo.tests import HttpCase, tagged
|
||||
|
||||
|
||||
def _urlencode_kwargs(**kwargs):
|
||||
return urlencode(kwargs)
|
||||
|
||||
|
||||
@tagged("post_install_l10n", "post_install", "-at_install")
|
||||
class BaseAutomationTestUi(HttpCase):
|
||||
def _neutralize_preexisting_automations(self, neutralize_action=True):
|
||||
self.env["base.automation"].with_context(active_test=False).search([]).write({"active": False})
|
||||
if neutralize_action:
|
||||
context = ast.literal_eval(self.env.ref("base_automation.base_automation_act").context)
|
||||
del context["search_default_inactive"]
|
||||
self.env.ref("base_automation.base_automation_act").context = str(context)
|
||||
|
||||
def test_01_base_automation_tour(self):
|
||||
self._neutralize_preexisting_automations()
|
||||
self.start_tour("/odoo/action-base_automation.base_automation_act?debug=tests", "test_base_automation", login="admin")
|
||||
base_automation = self.env["base.automation"].search([])
|
||||
self.assertEqual(base_automation.model_id.model, "res.partner")
|
||||
self.assertEqual(base_automation.trigger, "on_create_or_write")
|
||||
self.assertEqual(base_automation.action_server_ids.state, "object_write") # only one action
|
||||
self.assertEqual(base_automation.action_server_ids.model_name, "res.partner")
|
||||
self.assertEqual(base_automation.action_server_ids.update_field_id.name, "function")
|
||||
self.assertEqual(base_automation.action_server_ids.value, "Test")
|
||||
|
||||
def test_base_automation_on_tag_added(self):
|
||||
self._neutralize_preexisting_automations()
|
||||
self.env["test_base_automation.tag"].create({"name": "test"})
|
||||
self.start_tour("/odoo/action-base_automation.base_automation_act?debug=tests", "test_base_automation_on_tag_added", login="admin")
|
||||
|
||||
def test_open_automation_from_grouped_kanban(self):
|
||||
self._neutralize_preexisting_automations()
|
||||
|
||||
test_view = self.env["ir.ui.view"].create(
|
||||
{
|
||||
"name": "test_view",
|
||||
"model": "test_base_automation.project",
|
||||
"type": "kanban",
|
||||
"arch": """
|
||||
<kanban default_group_by="tag_ids">
|
||||
<templates>
|
||||
<t t-name="card">
|
||||
<field name="name" />
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>
|
||||
""",
|
||||
}
|
||||
)
|
||||
test_action = self.env["ir.actions.act_window"].create(
|
||||
{
|
||||
"name": "test action",
|
||||
"res_model": "test_base_automation.project",
|
||||
"view_ids": [Command.create({"view_id": test_view.id, "view_mode": "kanban"})],
|
||||
}
|
||||
)
|
||||
tag = self.env["test_base_automation.tag"].create({"name": "test tag"})
|
||||
self.env["test_base_automation.project"].create({"name": "test", "tag_ids": [Command.link(tag.id)]})
|
||||
|
||||
self.start_tour(f"/odoo/action-{test_action.id}?debug=0", "test_open_automation_from_grouped_kanban", login="admin")
|
||||
base_auto = self.env["base.automation"].search([])
|
||||
self.assertEqual(base_auto.name, "From Tour")
|
||||
self.assertEqual(base_auto.model_name, "test_base_automation.project")
|
||||
self.assertEqual(base_auto.trigger_field_ids.name, "tag_ids")
|
||||
self.assertEqual(base_auto.trigger, "on_tag_set")
|
||||
self.assertEqual(base_auto.trg_field_ref_model_name, "test_base_automation.tag")
|
||||
self.assertEqual(base_auto.trg_field_ref, tag.id)
|
||||
|
||||
def test_kanban_automation_view_stage_trigger(self):
|
||||
self._neutralize_preexisting_automations()
|
||||
|
||||
project_model = self.env.ref('test_base_automation.model_test_base_automation_project')
|
||||
stage_field = self.env['ir.model.fields'].search([
|
||||
('model_id', '=', project_model.id),
|
||||
('name', '=', 'stage_id'),
|
||||
])
|
||||
test_stage = self.env['test_base_automation.stage'].create({'name': 'Stage value'})
|
||||
|
||||
automation = self.env["base.automation"].create({
|
||||
"name": "Test Stage",
|
||||
"trigger": "on_stage_set",
|
||||
"model_id": project_model.id,
|
||||
"trigger_field_ids": [stage_field.id],
|
||||
"trg_field_ref": test_stage,
|
||||
})
|
||||
|
||||
action = {
|
||||
"name": "Set Active To False",
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_write",
|
||||
"update_path": "user_ids.active",
|
||||
"value": False,
|
||||
"model_id": project_model.id
|
||||
}
|
||||
automation.write({"action_server_ids": [Command.create(action)]})
|
||||
|
||||
self.start_tour(
|
||||
"/odoo/action-base_automation.base_automation_act",
|
||||
"test_kanban_automation_view_stage_trigger", login="admin"
|
||||
)
|
||||
|
||||
def test_kanban_automation_view_time_trigger(self):
|
||||
self._neutralize_preexisting_automations()
|
||||
model = self.env['ir.model']._get("base.automation.lead.test")
|
||||
|
||||
date_field = self.env['ir.model.fields'].search([
|
||||
('model_id', '=', model.id),
|
||||
('name', '=', 'date_automation_last'),
|
||||
])
|
||||
|
||||
self.env["base.automation"].create({
|
||||
"name": "Test Date",
|
||||
"trigger": "on_time",
|
||||
"model_id": model.id,
|
||||
"trg_date_range": 1,
|
||||
"trg_date_range_type": "hour",
|
||||
"trg_date_id": date_field.id,
|
||||
})
|
||||
|
||||
self.start_tour(
|
||||
"/odoo/action-base_automation.base_automation_act",
|
||||
"test_kanban_automation_view_time_trigger", login="admin"
|
||||
)
|
||||
|
||||
def test_kanban_automation_view_time_updated_trigger(self):
|
||||
self._neutralize_preexisting_automations()
|
||||
model = self.env.ref("base.model_res_partner")
|
||||
|
||||
self.env["base.automation"].create({
|
||||
"name": "Test Date",
|
||||
"trigger": "on_time_updated",
|
||||
"model_id": model.id,
|
||||
"trg_date_range": 1,
|
||||
"trg_date_range_type": "hour",
|
||||
})
|
||||
|
||||
self.start_tour(
|
||||
"/odoo/action-base_automation.base_automation_act",
|
||||
"test_kanban_automation_view_time_updated_trigger", login="admin"
|
||||
)
|
||||
|
||||
def test_kanban_automation_view_create_action(self):
|
||||
self._neutralize_preexisting_automations()
|
||||
model = self.env.ref("base.model_res_partner")
|
||||
|
||||
automation = self.env["base.automation"].create({
|
||||
"name": "Test",
|
||||
"trigger": "on_create_or_write",
|
||||
"model_id": model.id,
|
||||
})
|
||||
|
||||
action = {
|
||||
"name": "Create Contact with name NameX",
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_create",
|
||||
"value": "NameX",
|
||||
"model_id": model.id
|
||||
}
|
||||
|
||||
automation.write({"action_server_ids": [Command.create(action)]})
|
||||
|
||||
self.start_tour(
|
||||
"/odoo/action-base_automation.base_automation_act",
|
||||
"test_kanban_automation_view_create_action", login="admin"
|
||||
)
|
||||
|
||||
def test_resize_kanban(self):
|
||||
self._neutralize_preexisting_automations()
|
||||
model = self.env.ref("base.model_res_partner")
|
||||
|
||||
automation = self.env["base.automation"].create(
|
||||
{
|
||||
"name": "Test",
|
||||
"trigger": "on_create_or_write",
|
||||
"model_id": model.id,
|
||||
}
|
||||
)
|
||||
|
||||
action = {
|
||||
"name": "Set Active To False",
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_write",
|
||||
"update_path": "active",
|
||||
"value": False,
|
||||
"model_id": model.id,
|
||||
}
|
||||
automation.write({"action_server_ids": [Command.create(action) for i in range(3)]})
|
||||
|
||||
self.start_tour(
|
||||
"/odoo/action-base_automation.base_automation_act",
|
||||
"test_resize_kanban",
|
||||
login="admin",
|
||||
)
|
||||
|
||||
def test_form_view(self):
|
||||
model = self.env.ref("base.model_res_partner")
|
||||
automation = self.env["base.automation"].create(
|
||||
{
|
||||
"name": "Test",
|
||||
"trigger": "on_create_or_write",
|
||||
"model_id": model.id,
|
||||
}
|
||||
)
|
||||
action = {
|
||||
"name": "Update Active",
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_write",
|
||||
"update_path": "active",
|
||||
"update_boolean_value": "false",
|
||||
"model_id": model.id,
|
||||
}
|
||||
automation.write(
|
||||
{"action_server_ids": [Command.create(dict(action, name=action["name"] + f" {i}", sequence=i)) for i in range(3)]}
|
||||
)
|
||||
self.assertEqual(
|
||||
automation.action_server_ids.mapped("name"),
|
||||
["Update Active 0", "Update Active 1", "Update Active 2"],
|
||||
)
|
||||
|
||||
onchange_link_passes = 0
|
||||
origin_link_onchange = type(self.env["ir.actions.server"]).onchange
|
||||
|
||||
def _onchange_base_auto_link(self_model, *args):
|
||||
nonlocal onchange_link_passes
|
||||
onchange_link_passes += 1
|
||||
res = origin_link_onchange(self_model, *args)
|
||||
if onchange_link_passes == 1:
|
||||
default_keys = {k: v for k, v in self_model.env.context.items() if k.startswith("default_")}
|
||||
self.assertEqual(
|
||||
default_keys,
|
||||
{"default_model_id": model.id, "default_usage": "base_automation"},
|
||||
)
|
||||
if onchange_link_passes == 2:
|
||||
self.assertEqual(res["value"]["name"], "Add Followers")
|
||||
|
||||
return res
|
||||
|
||||
self.patch(type(self.env["ir.actions.server"]), "onchange", _onchange_base_auto_link)
|
||||
|
||||
self.start_tour(
|
||||
(
|
||||
f"/odoo/action-base_automation.base_automation_act/{automation.id}?debug=0"
|
||||
),
|
||||
"test_form_view_resequence_actions",
|
||||
login="admin",
|
||||
)
|
||||
self.assertEqual(onchange_link_passes, 2)
|
||||
self.assertEqual(
|
||||
automation.action_server_ids.mapped("name"),
|
||||
["Update Active 2", "Update Active 0", "Update Active 1"],
|
||||
)
|
||||
|
||||
def test_form_view_model_id(self):
|
||||
self.start_tour(
|
||||
(
|
||||
"/odoo/action-base_automation.base_automation_act/new?view_type='form'&debug=0)"
|
||||
),
|
||||
"test_form_view_model_id",
|
||||
login="admin",
|
||||
)
|
||||
|
||||
def test_form_view_custom_reference_field(self):
|
||||
self.env["test_base_automation.stage"].create({"name": "test stage"})
|
||||
self.env["test_base_automation.tag"].create({"name": "test tag"})
|
||||
self.start_tour(
|
||||
(
|
||||
"/odoo/action-base_automation.base_automation_act/new?view_type='form'&debug=0)"
|
||||
),
|
||||
"test_form_view_custom_reference_field",
|
||||
login="admin",
|
||||
)
|
||||
|
||||
def test_form_view_mail_triggers(self):
|
||||
self.start_tour(
|
||||
(
|
||||
"/odoo/action-base_automation.base_automation_act/new?view_type='form'&debug=0)"
|
||||
),
|
||||
"test_form_view_mail_triggers",
|
||||
login="admin",
|
||||
)
|
||||
|
||||
def test_on_change_rule_creation(self):
|
||||
""" test on_change rule creation from the UI """
|
||||
self.start_tour("/odoo/action-base_automation.base_automation_act", 'base_automation.on_change_rule_creation', login="admin")
|
||||
|
||||
rule = self.env['base.automation'].search([], order="create_date desc", limit=1)[0]
|
||||
view_model = self.env['ir.model']._get("ir.ui.view")
|
||||
active_field = self.env['ir.model.fields'].search([
|
||||
('name', '=', 'active'),
|
||||
('model', '=', 'ir.ui.view'),
|
||||
])[0]
|
||||
self.assertEqual(rule.name, "Test rule")
|
||||
self.assertEqual(rule.model_id, view_model)
|
||||
self.assertEqual(rule.trigger, 'on_change')
|
||||
self.assertEqual(len(rule.on_change_field_ids), 1)
|
||||
self.assertEqual(rule.on_change_field_ids[0], active_field)
|
||||
Loading…
Add table
Add a link
Reference in a new issue