diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-07-04 17:35:07 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-07-04 17:35:07 +0200 |
| commit | 1debaa89f14cf662c43744b5cefb476f10eb8a93 (patch) | |
| tree | b23925966cbcb713e3adec503ad4f4926cdfa8cf /odoo/addons/test_rpc/tests/test_error.py | |
| parent | 79ef03d4cc07a7e75eba2ca0f9231d841ecf7b8e (diff) | |
| parent | 56ce29e71f75a657d4b518d86c1d7084891e898e (diff) | |
[MERGE] forward port branch 11.0 up to 56ce29e71f7
Diffstat (limited to 'odoo/addons/test_rpc/tests/test_error.py')
| -rw-r--r-- | odoo/addons/test_rpc/tests/test_error.py | 67 |
1 files changed, 67 insertions, 0 deletions
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 + ) |
