From d0f3341f8d2ad00dc83c09f377c44ebce7576f12 Mon Sep 17 00:00:00 2001 From: "Rmi Rahir (rar)" Date: Tue, 6 Jun 2023 10:37:00 +0000 Subject: [PATCH] [FIX] spreadsheet: move test to dedicated module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test added in #120818 was relying on a model that does not depend on module `spreadsheet, rather the opposite. This information was probably lost during the forwardport process. Since the fix concerns `spreadsheet.mixin` and not just `spreadsheet.dashboard`, it makes sense to test it globally, in a dedicated test module. Fixes runbot build errors 20966 and 20968 closes odoo/odoo#123947 X-original-commit: 7205e3b26eb3de3f53d6984cd07ec3e4b3fbcfdd Signed-off-by: Lucas Lefèvre (lul) Signed-off-by: Rémi Rahir (rar) --- .../tests/validate_spreadsheet_data.py | 11 ----------- addons/test_spreadsheet/__init__.py | 1 + addons/test_spreadsheet/__manifest__.py | 18 ++++++++++++++++++ addons/test_spreadsheet/models/__init__.py | 1 + .../models/spreadsheet_mixin_test.py | 9 +++++++++ .../security/ir.model.access.csv | 2 ++ addons/test_spreadsheet/tests/__init__.py | 1 + .../test_spreadsheet/tests/test_spreadsheet.py | 12 ++++++++++++ 8 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 addons/test_spreadsheet/__init__.py create mode 100644 addons/test_spreadsheet/__manifest__.py create mode 100644 addons/test_spreadsheet/models/__init__.py create mode 100644 addons/test_spreadsheet/models/spreadsheet_mixin_test.py create mode 100644 addons/test_spreadsheet/security/ir.model.access.csv create mode 100644 addons/test_spreadsheet/tests/__init__.py create mode 100644 addons/test_spreadsheet/tests/test_spreadsheet.py diff --git a/addons/spreadsheet/tests/validate_spreadsheet_data.py b/addons/spreadsheet/tests/validate_spreadsheet_data.py index e78371f55c6..265370bb792 100644 --- a/addons/spreadsheet/tests/validate_spreadsheet_data.py +++ b/addons/spreadsheet/tests/validate_spreadsheet_data.py @@ -218,14 +218,3 @@ class ValidateSpreadsheetData(TransactionCase): raise AssertionError( f"xml id '{xml_id}' used in spreadsheet '{spreadsheet_name}' does not exist" ) - - def test_onchange_json_data(self): - group = self.env["spreadsheet.dashboard.group"].create( - {"name": "a group"} - ) - spreadsheet_form = Form(self.env['spreadsheet.dashboard']) - spreadsheet_form.name = 'Test spreadsheet' - spreadsheet_form.dashboard_group_id = group - spreadsheet_form.spreadsheet_binary_data = base64.b64encode(json.dumps({'key': 'value'}).encode('utf-8')) - with self.assertRaises(ValidationError, msg='Invalid JSON Data'): - spreadsheet_form.spreadsheet_binary_data = base64.b64encode('invalid json'.encode('utf-8')) diff --git a/addons/test_spreadsheet/__init__.py b/addons/test_spreadsheet/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/addons/test_spreadsheet/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/addons/test_spreadsheet/__manifest__.py b/addons/test_spreadsheet/__manifest__.py new file mode 100644 index 00000000000..c9c96b67d17 --- /dev/null +++ b/addons/test_spreadsheet/__manifest__.py @@ -0,0 +1,18 @@ +# -*- encoding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Spreadsheet Test', + 'version': '1.0', + 'category': 'Hidden', + 'summary': 'Spreadsheet Test, mainly to test the mixin behavior', + 'description': """This module contains tests related to spreadsheet. + The modules exposes some mixin that are only implemented in other functional modules. + When trying to test a global behavior of the mixin, it makes no sense to test it in + each module implementing the mixin but rather test a dummy implementation of the later, + hence the need for this test module. + """, + 'depends': ['spreadsheet'], + 'license': 'LGPL-3', + 'data': ['security/ir.model.access.csv'], +} diff --git a/addons/test_spreadsheet/models/__init__.py b/addons/test_spreadsheet/models/__init__.py new file mode 100644 index 00000000000..efeaf6c1263 --- /dev/null +++ b/addons/test_spreadsheet/models/__init__.py @@ -0,0 +1 @@ +from . import spreadsheet_mixin_test diff --git a/addons/test_spreadsheet/models/spreadsheet_mixin_test.py b/addons/test_spreadsheet/models/spreadsheet_mixin_test.py new file mode 100644 index 00000000000..fc39e6a8677 --- /dev/null +++ b/addons/test_spreadsheet/models/spreadsheet_mixin_test.py @@ -0,0 +1,9 @@ +from odoo import models + + +class SpreadsheetDummy(models.Model): + """ A very simple model only inheriting from spreadsheet.mixin to test + its model functioning.""" + _description = 'Dummy Spreadsheet' + _name = 'spreadsheet.test' + _inherit = ['spreadsheet.mixin'] diff --git a/addons/test_spreadsheet/security/ir.model.access.csv b/addons/test_spreadsheet/security/ir.model.access.csv new file mode 100644 index 00000000000..ffc692a80b0 --- /dev/null +++ b/addons/test_spreadsheet/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_spreadsheet_test_all,access.spreadsheet.test.all,model_spreadsheet_test,,1,1,1,1 diff --git a/addons/test_spreadsheet/tests/__init__.py b/addons/test_spreadsheet/tests/__init__.py new file mode 100644 index 00000000000..f0bcd73627a --- /dev/null +++ b/addons/test_spreadsheet/tests/__init__.py @@ -0,0 +1 @@ +from . import test_spreadsheet diff --git a/addons/test_spreadsheet/tests/test_spreadsheet.py b/addons/test_spreadsheet/tests/test_spreadsheet.py new file mode 100644 index 00000000000..245172a7c7a --- /dev/null +++ b/addons/test_spreadsheet/tests/test_spreadsheet.py @@ -0,0 +1,12 @@ +import base64 +import json +from odoo.tests.common import TransactionCase, Form +from odoo.exceptions import ValidationError + +class ValidateSpreadsheetMixinData(TransactionCase): + def test_onchange_json_data(self): + spreadsheet_form = Form(self.env["spreadsheet.test"]) + + spreadsheet_form.spreadsheet_binary_data = base64.b64encode(json.dumps({'key': 'value'}).encode('utf-8')) + with self.assertRaises(ValidationError, msg='Invalid JSON Data'): + spreadsheet_form.spreadsheet_binary_data = base64.b64encode('invalid json'.encode('utf-8'))