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'))