[FIX] test_rpc: adapt test to version 12
In version 12, user 1 is deactivated. Use `base.user_admin` instead.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from functools import partial
|
||||
|
||||
from odoo.tests import common
|
||||
from odoo.tools.misc import mute_logger
|
||||
|
||||
@@ -7,17 +9,18 @@ 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()
|
||||
uid = self.ref("base.user_admin")
|
||||
self.rpc = partial(self.xmlrpc_object.execute, common.get_db_name(), uid, "admin")
|
||||
|
||||
# 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})
|
||||
self.rpc("res.users", "write", [uid], {"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"})
|
||||
self.rpc("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", {})
|
||||
self.rpc("test_rpc.model_b", "create", {})
|
||||
raise
|
||||
except Exception as e:
|
||||
self.assertIn("The operation cannot be completed:", e.faultString)
|
||||
@@ -30,18 +33,16 @@ class TestError(common.HttpCase):
|
||||
|
||||
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}
|
||||
)
|
||||
b1 = self.rpc("test_rpc.model_b", "create", {"name": "B1"})
|
||||
b2 = self.rpc("test_rpc.model_b", "create", {"name": "B2"})
|
||||
self.rpc("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)
|
||||
self.rpc("test_rpc.model_b", "unlink", b1)
|
||||
raise
|
||||
except Exception as e:
|
||||
self.assertIn("The operation cannot be completed:", e.faultString)
|
||||
@@ -50,18 +51,22 @@ class TestError(common.HttpCase):
|
||||
"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)
|
||||
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)
|
||||
self.rpc("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
|
||||
" 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
|
||||
"Model: Model A (test_rpc.model_a), Constraint: test_rpc_model_a_field_b2_fkey",
|
||||
e.faultString,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user