From d68367b9c46b2b627d054828e52e3b7710ce41cb Mon Sep 17 00:00:00 2001 From: Brice bib Bartoletti Date: Mon, 10 Jul 2023 12:49:18 +0200 Subject: [PATCH] [REF] l10n_account_edi_ubl_cii_tests: _assert_invoice_attachment The aim of this commit is to: 1) ensure the expected file exist or make the test fail if it doesn't 2) file and file_path: switch variables names 3) allows using that method from other module Context: 1) When the expected_file_path doesn't point to any existing file 2) There is an ambiguity with those variable names 3) run the method from a test in another module Before this commit: 1) The test fail with an obscure error `can't convert Boolean`. 2) `expected_file` is a path and `expected_file_path` is the file. 3) The method was always looking in `l10n_account_edi_ubl_cii_tests` to get its files. After this commit: 1) The failing test clearly states the file doesn't exist. 2) `expected_file` is the file and `expected_file_path` is the file path. 3) The test method is now looking in the module from which it gets run to get its test files. Task-id: 3326977 Part-of: odoo/odoo#130617 --- addons/l10n_account_edi_ubl_cii_tests/tests/common.py | 7 ++++--- .../tests/test_xml_cii_fr.py | 6 +++--- .../tests/test_xml_ubl_au.py | 4 ++-- .../tests/test_xml_ubl_be.py | 6 +++--- .../tests/test_xml_ubl_de.py | 4 ++-- .../tests/test_xml_ubl_nl.py | 4 ++-- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/common.py b/addons/l10n_account_edi_ubl_cii_tests/tests/common.py index 1109706c9d3..bf0504f3a5b 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/common.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/common.py @@ -225,7 +225,7 @@ class TestUBLCommon(AccountTestInvoicingCommon): account_move._generate_pdf_and_send_invoice(self.move_template) return account_move - def _assert_invoice_attachment(self, attachment, xpaths, expected_file): + def _assert_invoice_attachment(self, attachment, xpaths, expected_file_path): """ Get attachment from a posted account.move, and asserts it's the same as the expected xml file. """ @@ -234,8 +234,9 @@ class TestUBLCommon(AccountTestInvoicingCommon): xml_content = base64.b64decode(attachment.with_context(bin_size=False).datas) xml_etree = self.get_xml_tree_from_string(xml_content) - expected_file_path = get_resource_path('l10n_account_edi_ubl_cii_tests', 'tests/test_files', expected_file) - expected_etree = etree.parse(expected_file_path).getroot() + expected_file = get_resource_path(self.test_module, 'tests/test_files', expected_file_path) + self.assertTrue(expected_file, "expected file not found") + expected_etree = etree.parse(expected_file).getroot() modified_etree = self.with_applied_xpath( expected_etree, diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_cii_fr.py b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_cii_fr.py index 6c40fa4103e..69c731f5ee5 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_cii_fr.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_cii_fr.py @@ -182,7 +182,7 @@ class TestCIIFR(TestUBLCommon): ___ignore___ ''', - expected_file='from_odoo/facturx_out_invoice.xml', + expected_file_path='from_odoo/facturx_out_invoice.xml', ) self.assertEqual(attachment.name, "factur-x.xml") self._assert_imported_invoice_from_etree(invoice, attachment) @@ -227,7 +227,7 @@ class TestCIIFR(TestUBLCommon): ___ignore___ ''', - expected_file='from_odoo/facturx_out_refund.xml' + expected_file_path='from_odoo/facturx_out_refund.xml' ) self.assertEqual(attachment.name, "factur-x.xml") self._assert_imported_invoice_from_etree(refund, attachment) @@ -280,7 +280,7 @@ class TestCIIFR(TestUBLCommon): ___ignore___ ''', - expected_file='from_odoo/facturx_out_invoice_tax_incl.xml' + expected_file_path='from_odoo/facturx_out_invoice_tax_incl.xml' ) def test_encoding_in_attachment_facturx(self): diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_au.py b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_au.py index 594d9a393bd..21d1c8a1bac 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_au.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_au.py @@ -109,7 +109,7 @@ class TestUBLAU(TestUBLCommon): {invoice.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/a_nz_out_invoice.xml', + expected_file_path='from_odoo/a_nz_out_invoice.xml', ) self.assertEqual(attachment.name[-8:], "a_nz.xml") self._assert_imported_invoice_from_etree(invoice, attachment) @@ -167,7 +167,7 @@ class TestUBLAU(TestUBLCommon): {refund.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/a_nz_out_refund.xml', + expected_file_path='from_odoo/a_nz_out_refund.xml', ) self.assertEqual(attachment.name[-8:], "a_nz.xml") self._assert_imported_invoice_from_etree(refund, attachment) diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py index ad675079684..bf66d37ff82 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py @@ -139,7 +139,7 @@ class TestUBLBE(TestUBLCommon, TestAccountMoveSendCommon): {invoice.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/bis3_out_invoice.xml', + expected_file_path='from_odoo/bis3_out_invoice.xml', ) self.assertEqual(attachment.name[-12:], "ubl_bis3.xml") self._assert_imported_invoice_from_etree(invoice, attachment) @@ -197,7 +197,7 @@ class TestUBLBE(TestUBLCommon, TestAccountMoveSendCommon): {refund.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/bis3_out_refund.xml', + expected_file_path='from_odoo/bis3_out_refund.xml', ) self.assertEqual(attachment.name[-12:], "ubl_bis3.xml") self._assert_imported_invoice_from_etree(refund, attachment) @@ -252,7 +252,7 @@ class TestUBLBE(TestUBLCommon, TestAccountMoveSendCommon): {invoice.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/bis3_out_invoice_public_admin.xml', + expected_file_path='from_odoo/bis3_out_invoice_public_admin.xml', ) def test_rounding_price_unit(self): diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_de.py b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_de.py index e21ebd24d60..9adc376ed1a 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_de.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_de.py @@ -121,7 +121,7 @@ class TestUBLDE(TestUBLCommon): {invoice.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/xrechnung_ubl_out_invoice.xml', + expected_file_path='from_odoo/xrechnung_ubl_out_invoice.xml', ) self.assertEqual(attachment.name[-10:], "ubl_de.xml") self._assert_imported_invoice_from_etree(invoice, attachment) @@ -179,7 +179,7 @@ class TestUBLDE(TestUBLCommon): {refund.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/xrechnung_ubl_out_refund.xml', + expected_file_path='from_odoo/xrechnung_ubl_out_refund.xml', ) self.assertEqual(attachment.name[-10:], "ubl_de.xml") self._assert_imported_invoice_from_etree(refund, attachment) diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_nl.py b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_nl.py index f01c5fb9900..784753fe5fb 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_nl.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_nl.py @@ -138,7 +138,7 @@ class TestUBLNL(TestUBLCommon): {invoice.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/nlcius_out_invoice.xml', + expected_file_path='from_odoo/nlcius_out_invoice.xml', ) self.assertEqual(attachment.name[-10:], "nlcius.xml") self._assert_imported_invoice_from_etree(invoice, attachment) @@ -196,7 +196,7 @@ class TestUBLNL(TestUBLCommon): {refund.invoice_pdf_report_id.name} ''', - expected_file='from_odoo/nlcius_out_refund.xml', + expected_file_path='from_odoo/nlcius_out_refund.xml', ) self.assertEqual(attachment.name[-10:], "nlcius.xml") self._assert_imported_invoice_from_etree(refund, attachment)