changeset c1c389992e8b in modules/edocument_uncefact:default
details:
https://hg.tryton.org/modules/edocument_uncefact?cmd=changeset&node=c1c389992e8b
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 6 +-
tests/__init__.py | 8 --
tests/test_edocument_uncefact.py | 143 ---------------------------------------
tests/test_module.py | 137 +++++++++++++++++++++++++++++++++++++
tox.ini | 3 +-
5 files changed, 142 insertions(+), 155 deletions(-)
diffs (336 lines):
diff -r 19041f03b431 -r c1c389992e8b setup.py
--- a/setup.py Sun Apr 10 19:11:38 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:17 2022 +0200
@@ -142,13 +142,13 @@
license='GPL-3',
python_requires='>=3.7',
install_requires=requires,
+ extras_require={
+ 'test': tests_require,
+ },
dependency_links=dependency_links,
zip_safe=False,
entry_points="""
[trytond.modules]
edocument_uncefact = trytond.modules.edocument_uncefact
""",
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r 19041f03b431 -r c1c389992e8b tests/__init__.py
--- a/tests/__init__.py Sun Apr 10 19:11:38 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:17 2022 +0200
@@ -1,10 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
-
-try:
- from trytond.modules.edocument_uncefact.tests.test_edocument_uncefact
import \
- suite # noqa: E501
-except ImportError:
- from .test_edocument_uncefact import suite
-
-__all__ = ['suite']
diff -r 19041f03b431 -r c1c389992e8b tests/test_edocument_uncefact.py
--- a/tests/test_edocument_uncefact.py Sun Apr 10 19:11:38 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,143 +0,0 @@
-# This file is part of Tryton. The COPYRIGHT file at the top level of
-# this repository contains the full copyright notices and license terms.
-
-import datetime
-import os
-import unittest
-from decimal import Decimal
-from unittest.mock import MagicMock, Mock
-
-from lxml import etree
-
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase, activate_module
-from trytond.tests.test_tryton import suite as test_suite
-from trytond.tests.test_tryton import with_transaction
-
-
-def get_invoice():
- pool = Pool()
- Address = pool.get('party.address')
- Company = pool.get('company.company')
- Country = pool.get('country.country')
- Currency = pool.get('currency.currency')
- Invoice = pool.get('account.invoice')
- InvoiceLine = pool.get('account.invoice.line')
- InvoiceTax = pool.get('account.invoice.tax')
- MoveLine = pool.get('account.move.line')
- Party = pool.get('party.party')
- PaymentTerm = pool.get('account.invoice.payment_term')
- Product = pool.get('product.product')
- Tax = pool.get('account.tax')
- Uom = pool.get('product.uom')
-
- address = Mock(spec=Address,
- street="St sample, 15",
- city="Scranton",
- postal_code="1000",
- subdivision=None,
- country=Mock(spec=Country,
- code='US'),
- )
- address.name = "Building A"
- address.country.name = "United States"
- party = Mock(spec=Party, addresses=[address])
- party.name = "Michael Scott"
- company = Mock(spec=Company,
- party=Mock(spec=Party,
- addresses=[Mock(spec=Address,
- street="Main street, 42",
- country=Mock(spec=Country,
- code='US'))]))
- company.party.name = "Dunder Mifflin"
- company.party.address_get = Mock(return_value=company.party.addresses[0])
- taxes = [Mock(spec=InvoiceTax,
- tax=Mock(spec=Tax,
- unece_code='VAT',
- unece_category_code='S',
- legal_notice="Legal Notice",
- ),
- base=Decimal('100.00'),
- amount=Decimal('10.00'),
- legal_notice="Legal Notice",
- )]
- product = Mock(spec=Product,
- code="12345",
- type='service',
- )
- product.name = "Product"
- lines = [Mock(spec=InvoiceLine,
- type='line',
- product=product,
- unit=Mock(spec=Uom,
- unece_code='C62',
- ),
- quantity=1,
- unit_price=Decimal('100.0000'),
- amount=Decimal('100.00'),
- description="Description",
- invoice_taxes=taxes,
- )]
- invoice = MagicMock(spec=Invoice,
- id=-1,
- __int__=Mock(return_value=-1),
- type='out',
- number="001",
- party=party,
- party_lang='fr',
- invoice_address=party.addresses[0],
- company=company,
- currency=Mock(spec=Currency,
- code='USD',
- round=lambda a: a),
- invoice_date=datetime.date.today(),
- payment_term=Mock(spec=PaymentTerm, description="Direct"),
- lines=lines,
- taxes=taxes,
- untaxed_amount=Decimal('100.00'),
- tax_amount=Decimal('10.00'),
- total_amount=Decimal('110.00'),
- amount_to_pay=Decimal('110.00'),
- lines_to_pay=[Mock(spec=MoveLine,
- maturity_date=datetime.date.today(),
- amount_second_currency=None,
- debit=Decimal('110.00'),
- credit=0,
- )],
- sales=[],
- state='posted',
- )
- return invoice
-
-
-class EDocumentUNCEFACTTestCase(ModuleTestCase):
- 'Test EDocument UN/CEFACT module'
- module = 'edocument_uncefact'
-
- @classmethod
- def setUpClass(cls):
- super(EDocumentUNCEFACTTestCase, cls).setUpClass()
- activate_module('account_invoice')
-
- @with_transaction()
- def test_16B_CII_CrossIndustryInvoice(self):
- "Test 16B-CII CrossIndustryInvoice"
- pool = Pool()
- Template = pool.get('edocument.uncefact.invoice')
- invoice = get_invoice()
- template = Template(invoice)
-
- invoice_string = template.render('16B-CII')
- invoice_xml = etree.fromstring(invoice_string)
- schema_file = os.path.join(
- os.path.dirname(__file__),
- '16B-CII', 'data', 'standard', 'CrossIndustryInvoice_100pD16B.xsd')
- schema = etree.XMLSchema(etree.parse(schema_file))
- schema.assertValid(invoice_xml)
-
-
-def suite():
- suite = test_suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- EDocumentUNCEFACTTestCase))
- return suite
diff -r 19041f03b431 -r c1c389992e8b tests/test_module.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py Sat Apr 16 18:30:17 2022 +0200
@@ -0,0 +1,137 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+import datetime
+import os
+from decimal import Decimal
+from unittest.mock import MagicMock, Mock
+
+from lxml import etree
+
+from trytond.pool import Pool
+from trytond.tests.test_tryton import (
+ ModuleTestCase, activate_module, with_transaction)
+
+
+def get_invoice():
+ pool = Pool()
+ Address = pool.get('party.address')
+ Company = pool.get('company.company')
+ Country = pool.get('country.country')
+ Currency = pool.get('currency.currency')
+ Invoice = pool.get('account.invoice')
+ InvoiceLine = pool.get('account.invoice.line')
+ InvoiceTax = pool.get('account.invoice.tax')
+ MoveLine = pool.get('account.move.line')
+ Party = pool.get('party.party')
+ PaymentTerm = pool.get('account.invoice.payment_term')
+ Product = pool.get('product.product')
+ Tax = pool.get('account.tax')
+ Uom = pool.get('product.uom')
+
+ address = Mock(spec=Address,
+ street="St sample, 15",
+ city="Scranton",
+ postal_code="1000",
+ subdivision=None,
+ country=Mock(spec=Country,
+ code='US'),
+ )
+ address.name = "Building A"
+ address.country.name = "United States"
+ party = Mock(spec=Party, addresses=[address])
+ party.name = "Michael Scott"
+ company = Mock(spec=Company,
+ party=Mock(spec=Party,
+ addresses=[Mock(spec=Address,
+ street="Main street, 42",
+ country=Mock(spec=Country,
+ code='US'))]))
+ company.party.name = "Dunder Mifflin"
+ company.party.address_get = Mock(return_value=company.party.addresses[0])
+ taxes = [Mock(spec=InvoiceTax,
+ tax=Mock(spec=Tax,
+ unece_code='VAT',
+ unece_category_code='S',
+ legal_notice="Legal Notice",
+ ),
+ base=Decimal('100.00'),
+ amount=Decimal('10.00'),
+ legal_notice="Legal Notice",
+ )]
+ product = Mock(spec=Product,
+ code="12345",
+ type='service',
+ )
+ product.name = "Product"
+ lines = [Mock(spec=InvoiceLine,
+ type='line',
+ product=product,
+ unit=Mock(spec=Uom,
+ unece_code='C62',
+ ),
+ quantity=1,
+ unit_price=Decimal('100.0000'),
+ amount=Decimal('100.00'),
+ description="Description",
+ invoice_taxes=taxes,
+ )]
+ invoice = MagicMock(spec=Invoice,
+ id=-1,
+ __int__=Mock(return_value=-1),
+ type='out',
+ number="001",
+ party=party,
+ party_lang='fr',
+ invoice_address=party.addresses[0],
+ company=company,
+ currency=Mock(spec=Currency,
+ code='USD',
+ round=lambda a: a),
+ invoice_date=datetime.date.today(),
+ payment_term=Mock(spec=PaymentTerm, description="Direct"),
+ lines=lines,
+ taxes=taxes,
+ untaxed_amount=Decimal('100.00'),
+ tax_amount=Decimal('10.00'),
+ total_amount=Decimal('110.00'),
+ amount_to_pay=Decimal('110.00'),
+ lines_to_pay=[Mock(spec=MoveLine,
+ maturity_date=datetime.date.today(),
+ amount_second_currency=None,
+ debit=Decimal('110.00'),
+ credit=0,
+ )],
+ sales=[],
+ state='posted',
+ )
+ return invoice
+
+
+class EDocumentUNCEFACTTestCase(ModuleTestCase):
+ 'Test EDocument UN/CEFACT module'
+ module = 'edocument_uncefact'
+
+ @classmethod
+ def setUpClass(cls):
+ super(EDocumentUNCEFACTTestCase, cls).setUpClass()
+ activate_module('account_invoice')
+
+ @with_transaction()
+ def test_16B_CII_CrossIndustryInvoice(self):
+ "Test 16B-CII CrossIndustryInvoice"
+ pool = Pool()
+ Template = pool.get('edocument.uncefact.invoice')
+ invoice = get_invoice()
+ template = Template(invoice)
+
+ invoice_string = template.render('16B-CII')
+ invoice_xml = etree.fromstring(invoice_string)
+ schema_file = os.path.join(
+ os.path.dirname(__file__),
+ '16B-CII', 'data', 'standard', 'CrossIndustryInvoice_100pD16B.xsd')
+ schema = etree.XMLSchema(etree.parse(schema_file))
+ schema.assertValid(invoice_xml)
+
+
+del ModuleTestCase
diff -r 19041f03b431 -r c1c389992e8b tox.ini
--- a/tox.ini Sun Apr 10 19:11:38 2022 +0200
+++ b/tox.ini Sat Apr 16 18:30:17 2022 +0200
@@ -2,8 +2,9 @@
envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
[testenv]
+extras = test
commands =
- coverage run --include=.*/edocument_uncefact/* setup.py test
+ coverage run --include=.*/edocument_uncefact/* -m unittest discover -s
tests
coverage report --include=.*/edocument_uncefact/* --omit=*/tests/*
deps =
coverage