diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-07-04 11:39:07 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-07-04 11:39:07 +0200 |
| commit | 2c81916f5d65b60f5a5c7b8475dc147e101879af (patch) | |
| tree | 3c1c27fec24875b046ea304efcc4d7fa5f218b83 /odoo/addons/test_rpc | |
| parent | 59c663ae4252d140d83662e63ee4b6562a98e962 (diff) | |
| parent | aaaf32fedd2a3a4e307d765c7fd8b9ddcd2bd5e0 (diff) | |
[MERGE] forward port branch saas-15 up to aaaf32fedd2
Diffstat (limited to 'odoo/addons/test_rpc')
| -rw-r--r-- | odoo/addons/test_rpc/__init__.py | 2 | ||||
| -rw-r--r-- | odoo/addons/test_rpc/__manifest__.py | 11 | ||||
| -rw-r--r-- | odoo/addons/test_rpc/ir.model.access.csv | 3 | ||||
| -rw-r--r-- | odoo/addons/test_rpc/models.py | 20 | ||||
| -rw-r--r-- | odoo/addons/test_rpc/tests/__init__.py | 3 | ||||
| -rw-r--r-- | odoo/addons/test_rpc/tests/test_error.py | 67 |
6 files changed, 106 insertions, 0 deletions
diff --git a/odoo/addons/test_rpc/__init__.py b/odoo/addons/test_rpc/__init__.py new file mode 100644 index 00000000000..89d26e2f597 --- /dev/null +++ b/odoo/addons/test_rpc/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import models diff --git a/odoo/addons/test_rpc/__manifest__.py b/odoo/addons/test_rpc/__manifest__.py new file mode 100644 index 00000000000..6e8e68926f9 --- /dev/null +++ b/odoo/addons/test_rpc/__manifest__.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +{ + "name": "Test RPC", + "version": "1.0", + "category": "Tests", + "description": """A module to test the RPC requests.""", + "depends": ["base", "web"], + "installable": True, + "auto_install": False, + "data": ["ir.model.access.csv"], +} diff --git a/odoo/addons/test_rpc/ir.model.access.csv b/odoo/addons/test_rpc/ir.model.access.csv new file mode 100644 index 00000000000..5e48e2fedc6 --- /dev/null +++ b/odoo/addons/test_rpc/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_test_rpc_model_a,access_test_rpc_model_a,model_test_rpc_model_a,,1,1,1,1 +access_test_rpc_model_b,access_test_rpc_model_b,model_test_rpc_model_b,,1,1,1,1 diff --git a/odoo/addons/test_rpc/models.py b/odoo/addons/test_rpc/models.py new file mode 100644 index 00000000000..2d547a9947e --- /dev/null +++ b/odoo/addons/test_rpc/models.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class ModelA(models.Model): + _name = "test_rpc.model_a" + _description = "Model A" + + name = fields.Char(required=True) + field_b1 = fields.Many2one("test_rpc.model_b", string="required field", required=True) + field_b2 = fields.Many2one("test_rpc.model_b", string="restricted field", ondelete="restrict") + + +class ModelB(models.Model): + _name = "test_rpc.model_b" + _description = "Model B" + + name = fields.Char(required=True) diff --git a/odoo/addons/test_rpc/tests/__init__.py b/odoo/addons/test_rpc/tests/__init__.py new file mode 100644 index 00000000000..bf0757101fa --- /dev/null +++ b/odoo/addons/test_rpc/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_error diff --git a/odoo/addons/test_rpc/tests/test_error.py b/odoo/addons/test_rpc/tests/test_error.py new file mode 100644 index 00000000000..6896b1f180d --- /dev/null +++ b/odoo/addons/test_rpc/tests/test_error.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- + +from odoo.tests import common +from odoo.tools.misc import mute_logger + + +class TestError(common.HttpCase): + def setUp(self): + super(TestError, self).setUp() + self.o = self.xmlrpc_object + self.db_name = common.get_db_name() + # Reset the admin's lang to avoid breaking tests due to admin not in English + self.o.execute(self.db_name, 1, "admin", "res.users", "write", [1], {"lang": False}) + + def test_01_create(self): + """ Create: mandatory field not provided """ + self.o.execute(self.db_name, 1, "admin", "test_rpc.model_b", "create", {"name": "B1"}) + try: + with mute_logger("odoo.sql_db"): + self.o.execute(self.db_name, 1, "admin", "test_rpc.model_b", "create", {}) + raise + except Exception as e: + self.assertIn("The operation cannot be completed:", e.faultString) + self.assertIn("Create/update: a mandatory field is not set.", e.faultString) + self.assertIn( + "Delete: another model requires the record being deleted. If possible, archive it instead.", + e.faultString, + ) + self.assertIn("Model: Model B (test_rpc.model_b), Field: Name (name)", e.faultString) + + def test_02_delete(self): + """ Delete: NOT NULL and ON DELETE RESTRICT constraints """ + b1 = self.o.execute(self.db_name, 1, "admin", "test_rpc.model_b", "create", {"name": "B1"}) + b2 = self.o.execute(self.db_name, 1, "admin", "test_rpc.model_b", "create", {"name": "B2"}) + self.o.execute( + self.db_name, 1, "admin", "test_rpc.model_a", "create", {"name": "A1", "field_b1": b1, "field_b2": b2} + ) + + # Unlink b1 => NOT NULL constraint raises + # FORWARD-PORT: in master, `required=True` implies `ondelete="restrict"` + # => the message should be the same than 'Unlink b2' case. + try: + with mute_logger("odoo.sql_db"): + self.o.execute(self.db_name, 1, "admin", "test_rpc.model_b", "unlink", b1) + raise + except Exception as e: + self.assertIn("The operation cannot be completed:", e.faultString) + self.assertIn("Create/update: a mandatory field is not set.", e.faultString) + self.assertIn( + "Delete: another model requires the record being deleted. If possible, archive it instead.", + e.faultString, + ) + self.assertIn("Model: Model A (test_rpc.model_a), Field: required field (field_b1)", e.faultString) + + # Unlink b2 => ON DELETE RESTRICT constraint raises + try: + with mute_logger("odoo.sql_db"): + self.o.execute(self.db_name, 1, "admin", "test_rpc.model_b", "unlink", b2) + raise + except Exception as e: + self.assertIn("The operation cannot be completed:", e.faultString) + self.assertIn( + " another model requires the record being deleted. If possible, archive it instead.", e.faultString + ) + self.assertIn( + "Model: Model A (test_rpc.model_a), Constraint: test_rpc_model_a_field_b2_fkey", e.faultString + ) |
