From fb714566f2a7596ee9dc89ef4fe2d5e2aac5bba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 3 Dec 2024 19:06:33 +0100 Subject: [PATCH] Add generic test for the default value of ModelStorage.copy --- trytond/trytond/tests/test_tryton.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/trytond/trytond/tests/test_tryton.py b/trytond/trytond/tests/test_tryton.py index 3ca1c213f7..4113fa3dbb 100644 --- a/trytond/trytond/tests/test_tryton.py +++ b/trytond/trytond/tests/test_tryton.py @@ -887,6 +887,29 @@ class ModuleTestCase(_DBTestCase): if isinstance(state, StateAction): state.get_action() + @with_transaction() + def test_modelstorage_copy(self): + "Test copied default values" + with unittest.mock.patch.object(ModelStorage, 'copy') as copy: + for mname, model in Pool().iterobject(): + if not isregisteredby(model, self.module): + continue + if not issubclass(model, ModelStorage): + continue + with self.subTest(model=mname): + model.copy([]) + if copy.call_args: + args, kwargs = copy.call_args + if len(args) >= 2: + default = args[1] + else: + default = kwargs.get('default') + if default is not None: + fields = { + k.split('.', 1)[0] for k in default.keys()} + self.assertLessEqual(fields, model._fields.keys()) + copy.reset_mock() + @with_transaction() def test_selection_fields(self): 'Test selection values'