-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
edi_exchange_template: imp test cov for tmpl lookup
- Loading branch information
Showing
3 changed files
with
111 additions
and
12 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import test_edi_backend_output | ||
from . import test_nswrapper | ||
from . import test_backend_and_type |
110 changes: 110 additions & 0 deletions
110
edi_exchange_template_oca/tests/test_backend_and_type.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,110 @@ | ||
# Copyright 2025 Camptocamp SA | ||
# @author: Simone Orsi <simone.orsi@camptocamp.com> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
|
||
from odoo.tests.common import SavepointCase | ||
|
||
|
||
class TestExchangeType(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.backend_type = cls.env.ref("edi_oca.demo_edi_backend_type") | ||
cls.backend = cls.env.ref("edi_oca.demo_edi_backend") | ||
cls.type_out1 = cls.env["edi.exchange.type"].create( | ||
{ | ||
"name": "Type output 1", | ||
"direction": "output", | ||
"code": "test_type_out1", | ||
"exchange_file_ext": "txt", | ||
"backend_type_id": cls.backend_type.id, | ||
} | ||
) | ||
cls.type_out2 = cls.env["edi.exchange.type"].create( | ||
{ | ||
"name": "Type output 2", | ||
"direction": "output", | ||
"code": "test_type_out2", | ||
"exchange_file_ext": "txt", | ||
"backend_type_id": cls.backend_type.id, | ||
} | ||
) | ||
model = cls.env["edi.exchange.template.output"] | ||
qweb_tmpl = cls.env["ir.ui.view"].create( | ||
{ | ||
"type": "qweb", | ||
"key": "edi_exchange.test_output1", | ||
"arch": """ | ||
<t t-name="edi_exchange.test_output1"> | ||
TEST | ||
</t> | ||
""", | ||
} | ||
) | ||
cls.tmpl_out1 = model.create( | ||
{ | ||
"code": "tmpl_test_type_out1", | ||
"name": "Out 1", | ||
"backend_type_id": cls.backend_type.id, | ||
"type_id": cls.type_out1.id, | ||
"template_id": qweb_tmpl.id, | ||
"output_type": "txt", | ||
"allowed_type_ids": [(6, 0, [cls.type_out1.id, cls.type_out2.id])], | ||
} | ||
) | ||
cls.tmpl_out2 = model.create( | ||
{ | ||
"code": "tmpl_test_type_out2", | ||
"name": "Out 2", | ||
"backend_type_id": cls.env.ref("edi_oca.demo_edi_backend_type").id, | ||
"type_id": cls.type_out1.id, | ||
"template_id": qweb_tmpl.id, | ||
"output_type": "txt", | ||
"allowed_type_ids": [(6, 0, [cls.type_out2.id])], | ||
} | ||
) | ||
vals = { | ||
# doesn't matter what model we use | ||
"model": cls.env.user._name, | ||
"res_id": cls.env.user.id, | ||
"type_id": cls.type_out2.id, | ||
} | ||
cls.record1 = cls.backend.create_record("test_type_out1", vals) | ||
vals = { | ||
# doesn't matter what model we use | ||
"model": cls.env.user._name, | ||
"res_id": cls.env.user.id, | ||
"type_id": cls.type_out2.id, | ||
} | ||
cls.record2 = cls.backend.create_record("test_type_out2", vals) | ||
|
||
# TODO: getting a template via code is deprecated | ||
def test_get_template_by_code(self): | ||
self.assertEqual( | ||
self.backend._get_output_template(self.record2, code=self.tmpl_out1.code), | ||
self.tmpl_out1, | ||
) | ||
self.record1.type_id.code = self.tmpl_out1.code | ||
self.assertEqual( | ||
self.backend._get_output_template(self.record1), self.tmpl_out1 | ||
) | ||
self.record2.type_id.code = self.tmpl_out2.code | ||
self.assertEqual( | ||
self.backend._get_output_template(self.record2), self.tmpl_out2 | ||
) | ||
|
||
def test_get_template_by_fallback(self): | ||
self.assertEqual( | ||
self.backend._get_output_template(self.record2, code=self.tmpl_out1.code), | ||
self.tmpl_out1, | ||
) | ||
self.assertEqual( | ||
self.backend._get_output_template(self.record1), self.tmpl_out1 | ||
) | ||
# Here's is shown the limitation of the fallback lookup by backend type: | ||
# if you have more than one template allowed for the same type, | ||
# the first one is returned. | ||
self.assertEqual( | ||
self.backend._get_output_template(self.record2), self.tmpl_out1 | ||
) |
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