From 1266cc7bbf99f79c33f5ffe5a4419d0f1731f431 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse <yti@odoo.com> Date: Thu, 7 Nov 2019 10:45:39 +0000 Subject: [PATCH] [ADD] test_base_automation: Move tests and related models Purpose ======= This module contains tests related to base automation. It makes no sense as they have no business value. Specification ============= Move all the tests to a separate module as it contains models used only to perform tests independently to functional aspects of other models. --- addons/base_automation/__init__.py | 1 - .../security/ir.model.access.csv | 2 -- .../__init__.py | 3 +-- addons/test_base_automation/__manifest__.py | 19 ++++++++++++++ .../test_base_automation/models/__init__.py | 4 +++ .../models/test_base_automation.py} | 3 +-- .../security/ir.model.access.csv | 3 +++ addons/test_base_automation/tests/__init__.py | 4 +++ .../tests/test_flow.py} | 25 ++++++++++--------- 9 files changed, 45 insertions(+), 19 deletions(-) rename addons/{base_automation/tests => test_base_automation}/__init__.py (62%) create mode 100644 addons/test_base_automation/__manifest__.py create mode 100644 addons/test_base_automation/models/__init__.py rename addons/{base_automation/tests/test_models.py => test_base_automation/models/test_base_automation.py} (97%) create mode 100644 addons/test_base_automation/security/ir.model.access.csv create mode 100644 addons/test_base_automation/tests/__init__.py rename addons/{base_automation/tests/test_base_automation.py => test_base_automation/tests/test_flow.py} (91%) diff --git a/addons/base_automation/__init__.py b/addons/base_automation/__init__.py index 56990e4d8ee5..dc5e6b693d19 100644 --- a/addons/base_automation/__init__.py +++ b/addons/base_automation/__init__.py @@ -2,4 +2,3 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import models -from .tests import test_models diff --git a/addons/base_automation/security/ir.model.access.csv b/addons/base_automation/security/ir.model.access.csv index 2dc7103a91ba..6b1d50350d01 100644 --- a/addons/base_automation/security/ir.model.access.csv +++ b/addons/base_automation/security/ir.model.access.csv @@ -1,5 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_base_automation,base.automation,model_base_automation,,1,0,0,0 access_base_automation_config,base.automation config,model_base_automation,base.group_system,1,1,1,1 -access_base_automation_lead_test,access_base_automation_lead_test,model_base_automation_lead_test,base.group_system,1,1,1,1 -access_base_automation_line_test,access_base_automation_line_test,model_base_automation_line_test,base.group_system,1,1,1,1 \ No newline at end of file diff --git a/addons/base_automation/tests/__init__.py b/addons/test_base_automation/__init__.py similarity index 62% rename from addons/base_automation/tests/__init__.py rename to addons/test_base_automation/__init__.py index b0ebb370682d..dc5e6b693d19 100644 --- a/addons/base_automation/tests/__init__.py +++ b/addons/test_base_automation/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import test_models -from . import test_base_automation +from . import models diff --git a/addons/test_base_automation/__manifest__.py b/addons/test_base_automation/__manifest__.py new file mode 100644 index 000000000000..4cbc1d7f0ab8 --- /dev/null +++ b/addons/test_base_automation/__manifest__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Test - Base Automation', + 'version': '1.0', + 'category': 'Hidden', + 'sequence': 9877, + 'summary': 'Base Automation Tests: Ensure Flow Robustness', + 'description': """This module contains tests related to base automation. Those are +contained in a separate module as it contains models used only to perform +tests independently to functional aspects of other models.""", + 'depends': ['base_automation'], + 'data': [ + 'security/ir.model.access.csv', + ], + 'installable': True, + 'application': False, +} diff --git a/addons/test_base_automation/models/__init__.py b/addons/test_base_automation/models/__init__.py new file mode 100644 index 000000000000..5bf71275255c --- /dev/null +++ b/addons/test_base_automation/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_base_automation \ No newline at end of file diff --git a/addons/base_automation/tests/test_models.py b/addons/test_base_automation/models/test_base_automation.py similarity index 97% rename from addons/base_automation/tests/test_models.py rename to addons/test_base_automation/models/test_base_automation.py index c3b4ca4000fc..b2109f3185de 100644 --- a/addons/base_automation/tests/test_models.py +++ b/addons/test_base_automation/models/test_base_automation.py @@ -4,7 +4,7 @@ from dateutil import relativedelta from odoo import fields, models, api -# YTI TODO: Move this brol to a new test_base_automation module + class LeadTest(models.Model): _name = "base.automation.lead.test" _description = "Automated Rule Test" @@ -42,7 +42,6 @@ class LeadTest(models.Model): return result - class LineTest(models.Model): _name = "base.automation.line.test" _description = "Automated Rule Line Test" diff --git a/addons/test_base_automation/security/ir.model.access.csv b/addons/test_base_automation/security/ir.model.access.csv new file mode 100644 index 000000000000..cc380da05adb --- /dev/null +++ b/addons/test_base_automation/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_base_automation_lead_test,access_base_automation_lead_test,model_base_automation_lead_test,base.group_system,1,1,1,1 +access_base_automation_line_test,access_base_automation_line_test,model_base_automation_line_test,base.group_system,1,1,1,1 diff --git a/addons/test_base_automation/tests/__init__.py b/addons/test_base_automation/tests/__init__.py new file mode 100644 index 000000000000..b96c2ec87d51 --- /dev/null +++ b/addons/test_base_automation/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_flow diff --git a/addons/base_automation/tests/test_base_automation.py b/addons/test_base_automation/tests/test_flow.py similarity index 91% rename from addons/base_automation/tests/test_base_automation.py rename to addons/test_base_automation/tests/test_flow.py index c768bc7a141a..657add84892b 100644 --- a/addons/base_automation/tests/test_base_automation.py +++ b/addons/test_base_automation/tests/test_flow.py @@ -1,5 +1,6 @@ # # -*- coding: utf-8 -*- # # Part of Odoo. See LICENSE file for full copyright and licensing details. + from unittest.mock import patch from odoo.addons.base.tests.common import TransactionCaseWithUserDemo @@ -16,7 +17,7 @@ class BaseAutomationTest(TransactionCaseWithUserDemo): self.test_mail_template_automation = self.env['mail.template'].create({ 'name': 'Template Automation', - 'model_id': self.env.ref('base_automation.model_base_automation_lead_test').id, + 'model_id': self.env.ref('test_base_automation.model_base_automation_lead_test').id, 'body_html': """<div>Email automation</div>""", }) @@ -24,7 +25,7 @@ class BaseAutomationTest(TransactionCaseWithUserDemo): self.env['base.automation'].create([ { 'name': 'Base Automation: test rule on create', - 'model_id': self.env.ref('base_automation.model_base_automation_lead_test').id, + 'model_id': self.env.ref('test_base_automation.model_base_automation_lead_test').id, 'state': 'code', 'code': "records.write({'user_id': %s})" % (self.user_demo.id), 'trigger': 'on_create', @@ -32,7 +33,7 @@ class BaseAutomationTest(TransactionCaseWithUserDemo): 'filter_domain': "[('state', '=', 'draft')]", }, { 'name': 'Base Automation: test rule on write', - 'model_id': self.env.ref('base_automation.model_base_automation_lead_test').id, + 'model_id': self.env.ref('test_base_automation.model_base_automation_lead_test').id, 'state': 'code', 'code': "records.write({'user_id': %s})" % (self.user_demo.id), 'trigger': 'on_write', @@ -41,7 +42,7 @@ class BaseAutomationTest(TransactionCaseWithUserDemo): 'filter_pre_domain': "[('state', '=', 'open')]", }, { 'name': 'Base Automation: test rule on recompute', - 'model_id': self.env.ref('base_automation.model_base_automation_lead_test').id, + 'model_id': self.env.ref('test_base_automation.model_base_automation_lead_test').id, 'state': 'code', 'code': "records.write({'user_id': %s})" % (self.user_demo.id), 'trigger': 'on_write', @@ -49,7 +50,7 @@ class BaseAutomationTest(TransactionCaseWithUserDemo): 'filter_domain': "[('employee', '=', True)]", }, { 'name': 'Base Automation: test recursive rule', - 'model_id': self.env.ref('base_automation.model_base_automation_lead_test').id, + 'model_id': self.env.ref('test_base_automation.model_base_automation_lead_test').id, 'state': 'code', 'code': """ record = model.browse(env.context['active_id']) @@ -59,14 +60,14 @@ if 'partner_id' in env.context['old_values'][record.id]: 'active': True, }, { 'name': 'Base Automation: test rule on secondary model', - 'model_id': self.env.ref('base_automation.model_base_automation_line_test').id, + 'model_id': self.env.ref('test_base_automation.model_base_automation_line_test').id, 'state': 'code', 'code': "records.write({'user_id': %s})" % (self.user_demo.id), 'trigger': 'on_create', 'active': True, }, { 'name': 'Base Automation: test rule on write check context', - 'model_id': self.env.ref('base_automation.model_base_automation_lead_test').id, + 'model_id': self.env.ref('test_base_automation.model_base_automation_lead_test').id, 'state': 'code', 'code': """ record = model.browse(env.context['active_id']) @@ -76,8 +77,8 @@ if 'user_id' in env.context['old_values'][record.id]: 'active': True, }, { 'name': 'Base Automation: test rule with trigger', - 'model_id': self.env.ref('base_automation.model_base_automation_lead_test').id, - 'trigger_field_ids': [(4, self.env.ref('base_automation.field_base_automation_lead_test__state').id)], + 'model_id': self.env.ref('test_base_automation.model_base_automation_lead_test').id, + 'trigger_field_ids': [(4, self.env.ref('test_base_automation.field_base_automation_lead_test__state').id)], 'state': 'code', 'code': """ record = model.browse(env.context['active_id']) @@ -86,9 +87,9 @@ record['name'] = record.name + 'X'""", 'active': True, }, { 'name': 'Base Automation: test send an email', - 'model_id': self.env.ref('base_automation.model_base_automation_lead_test').id, + 'model_id': self.env.ref('test_base_automation.model_base_automation_lead_test').id, 'template_id': self.test_mail_template_automation.id, - 'trigger_field_ids': [(4, self.env.ref('base_automation.field_base_automation_lead_test__deadline').id)], + 'trigger_field_ids': [(4, self.env.ref('test_base_automation.field_base_automation_lead_test__deadline').id)], 'state': 'email', 'code': """ record = model.browse(env.context['active_id']) @@ -283,7 +284,7 @@ record['name'] = record.name + 'X'""", # change the rule to trigger on partner_id rule = self.env['base.automation'].search([('name', '=', 'Base Automation: test rule with trigger')]) - rule.write({'trigger_field_ids': [(6, 0, [self.env.ref('base_automation.field_base_automation_lead_test__partner_id').id])]}) + rule.write({'trigger_field_ids': [(6, 0, [self.env.ref('test_base_automation.field_base_automation_lead_test__partner_id').id])]}) partner2 = self.env['res.partner'].create({'name': 'A new partner'}) lead.name = 'X' -- GitLab