-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[18.0][ADD] edi_exchange_template_oca_json - unit tests
- Loading branch information
ilo
committed
Jan 23, 2025
1 parent
361cc09
commit df9e01a
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_edi_backend_output_json |
65 changes: 65 additions & 0 deletions
65
edi_exchange_template_oca_json/tests/test_edi_backend_output_json.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2025 Camptocamp SA | ||
# @author Italo LOPES <[email protected]> | ||
# 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": [ | ||
{ | ||
"name": "name" | ||
}, | ||
{ | ||
"name": "ref" | ||
} | ||
] | ||
} | ||
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"[{{'name': '{self.partner.name}', 'ref': '{self.partner.ref}'}}]" | ||
file_content = self.record_json._get_file_content() | ||
self.assertEqual(file_content.strip(), expected) |