[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
This commit is contained in:
Brice bib Bartoletti
2023-09-19 16:37:12 +00:00
committed by Yosua Nicolaus
parent e24058b14d
commit d68367b9c4
6 changed files with 16 additions and 15 deletions
@@ -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,
@@ -182,7 +182,7 @@ class TestCIIFR(TestUBLCommon):
<PaymentReference>___ignore___</PaymentReference>
</xpath>
''',
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):
<IssuerAssignedID>___ignore___</IssuerAssignedID>
</xpath>
''',
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):
<IssuerAssignedID>___ignore___</IssuerAssignedID>
</xpath>
''',
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):
@@ -109,7 +109,7 @@ class TestUBLAU(TestUBLCommon):
<attribute name="filename">{invoice.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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):
<attribute name="filename">{refund.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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)
@@ -139,7 +139,7 @@ class TestUBLBE(TestUBLCommon, TestAccountMoveSendCommon):
<attribute name="filename">{invoice.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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):
<attribute name="filename">{refund.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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):
<attribute name="filename">{invoice.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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):
@@ -121,7 +121,7 @@ class TestUBLDE(TestUBLCommon):
<attribute name="filename">{invoice.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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):
<attribute name="filename">{refund.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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)
@@ -138,7 +138,7 @@ class TestUBLNL(TestUBLCommon):
<attribute name="filename">{invoice.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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):
<attribute name="filename">{refund.invoice_pdf_report_id.name}</attribute>
</xpath>
''',
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)