From cc0001869a7c7b3bb6abc548e8ecf8231a83e6f7 Mon Sep 17 00:00:00 2001 From: ilo Date: Thu, 23 Jan 2025 15:14:09 -0300 Subject: [PATCH] [18.0][ADD] edi_exchange_template_oca_json - unit tests --- .../tests/__init__.py | 1 + .../tests/test_edi_backend_output_json.py | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 edi_exchange_template_oca_json/tests/__init__.py create mode 100644 edi_exchange_template_oca_json/tests/test_edi_backend_output_json.py diff --git a/edi_exchange_template_oca_json/tests/__init__.py b/edi_exchange_template_oca_json/tests/__init__.py new file mode 100644 index 000000000..9041c54e7 --- /dev/null +++ b/edi_exchange_template_oca_json/tests/__init__.py @@ -0,0 +1 @@ +from . import test_edi_backend_output_json diff --git a/edi_exchange_template_oca_json/tests/test_edi_backend_output_json.py b/edi_exchange_template_oca_json/tests/test_edi_backend_output_json.py new file mode 100644 index 000000000..1a14315c8 --- /dev/null +++ b/edi_exchange_template_oca_json/tests/test_edi_backend_output_json.py @@ -0,0 +1,65 @@ +# Copyright 2025 Camptocamp SA +# @author Italo LOPES +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + + +from odoo.addons.edi_exchange_template_oca.tests.test_edi_backend_output import ( + TestEDIBackendOutputBase, +) + + +class TestEDIBackendOutputJsonBase(TestEDIBackendOutputBase): + @classmethod + def _setup_records(cls): + res = super()._setup_records() + cls.type_out_json = cls._create_exchange_type( + name="Template output JSON", + direction="output", + code="test_type_out_json", + exchange_file_ext="txt", + exchange_filename_pattern="{record.ref}-{type.code}-{dt}", + ) + model = cls.env["edi.exchange.template.output"] + cls.tmpl_out_json = model.create( + { + "generator": "json", + "name": "Out JSON", + "backend_type_id": cls.backend.backend_type_id.id, + "code": "test_type_out_json", + "type_id": cls.type_out_json.id, + "output_type": "json", + "code_snippet": """ +field_list = { + "fields": [ + { + "display_name": "mapKeyField" + }, + { + "ref": "mapKeyField2" + } + ] +} +result = field_list + """, + } + ) + vals = { + "model": cls.partner._name, + "res_id": cls.partner.id, + "type_id": cls.tmpl_out_json.id, + } + cls.record_json = cls.backend.create_record("test_type_out_json", vals) + return res + + +class TestEDIBackendOutputJson(TestEDIBackendOutputJsonBase): + def test_00_get_template_json(self): + self.assertEqual( + self.backend._get_output_template(self.record_json), self.tmpl_out_json + ) + + def test_01_generate_json(self): + self.backend.exchange_generate(self.record_json) + expected = f"{self.partner.ref} - {self.partner.name}" + file_content = self.record_json._get_file_content() + self.assertEqual(file_content.strip(), expected)