Skip to content

Commit

Permalink
edi_xml: improve base test class
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Feb 6, 2025
1 parent ef7e589 commit 8fcec94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
14 changes: 14 additions & 0 deletions edi_xml_oca/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import xmlunittest

from odoo.addons.component.tests.common import SavepointComponentCase


class XMLTestCaseMixin(xmlunittest.XmlTestMixin):
def _dev_write_example_file(self, test_file, filename, content):
Expand All @@ -22,3 +24,15 @@ def read_test_file(self, filename):
path = os.path.join(os.path.dirname(__file__), "examples", filename)
with open(path, "r") as thefile:
return thefile.read()


class XMLComponentTestCase(SavepointComponentCase, XMLTestCaseMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.backend = cls.env.ref("edi_oca.demo_edi_backend")
cls.handler = cls.backend._find_component(
cls.backend._name,
["edi.xml"],
work_ctx={"schema_path": "edi_xml_oca:tests/fixtures/Test.xsd"},
)
15 changes: 2 additions & 13 deletions edi_xml_oca/tests/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
# @author: Simone Orsi <simahawk@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo.addons.component.tests.common import SavepointComponentCase

from .common import XMLTestCaseMixin
from .common import XMLComponentTestCase

TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
<xs:element
Expand All @@ -15,17 +14,7 @@
"""


class XMLTestCase(SavepointComponentCase, XMLTestCaseMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.backend = cls.env.ref("edi_oca.demo_edi_backend")
cls.handler = cls.backend._find_component(
cls.backend._name,
["edi.xml"],
work_ctx={"schema_path": "edi_xml_oca:tests/fixtures/Test.xsd"},
)

class XMLTestCase(XMLComponentTestCase):
def test_xml_schema_fail(self):
with self.assertRaises(ValueError):
self.backend._find_component(
Expand Down

0 comments on commit 8fcec94

Please sign in to comment.