changeset 2fd04f978180 in modules/sale_credit_limit:default
details: 
https://hg.tryton.org/modules/sale_credit_limit?cmd=changeset&node=2fd04f978180
description:
        Replace test setuptools command by unittest discover

        issue9215
        review389851002
diffstat:

 setup.py                        |    2 -
 tests/__init__.py               |    8 --
 tests/test_module.py            |  126 ++++++++++++++++++++++++++++++++++++++
 tests/test_sale_credit_limit.py |  131 ----------------------------------------
 tox.ini                         |    2 +-
 5 files changed, 127 insertions(+), 142 deletions(-)

diffs (301 lines):

diff -r eae84932558b -r 2fd04f978180 setup.py
--- a/setup.py  Sun Apr 10 19:11:39 2022 +0200
+++ b/setup.py  Sat Apr 16 18:30:18 2022 +0200
@@ -142,6 +142,4 @@
     [trytond.modules]
     sale_credit_limit = trytond.modules.sale_credit_limit
     """,
-    test_suite='tests',
-    test_loader='trytond.test_loader:Loader',
     )
diff -r eae84932558b -r 2fd04f978180 tests/__init__.py
--- a/tests/__init__.py Sun Apr 10 19:11:39 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:18 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.sale_credit_limit.tests.test_sale_credit_limit import 
\
-        suite  # noqa: E501
-except ImportError:
-    from .test_sale_credit_limit import suite
-
-__all__ = ['suite']
diff -r eae84932558b -r 2fd04f978180 tests/test_module.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py      Sat Apr 16 18:30:18 2022 +0200
@@ -0,0 +1,126 @@
+# This file is part of Tryton.  The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+from decimal import Decimal
+
+from trytond.exceptions import UserWarning
+from trytond.modules.account.tests import create_chart, get_fiscalyear
+from trytond.modules.account_invoice.tests import set_invoice_sequences
+from trytond.modules.company.tests import (
+    CompanyTestMixin, create_company, set_company)
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class SaleCreditLimitTestCase(CompanyTestMixin, ModuleTestCase):
+    'Test SaleCreditLimit module'
+    module = 'sale_credit_limit'
+
+    @with_transaction()
+    def test_check_credit_limit(self):
+        'Test check_credit_limit'
+        pool = Pool()
+        Account = pool.get('account.account')
+        Move = pool.get('account.move')
+        Journal = pool.get('account.journal')
+        Party = pool.get('party.party')
+        Sale = pool.get('sale.sale')
+        PaymentTerm = pool.get('account.invoice.payment_term')
+        Configuration = pool.get('account.configuration')
+        FiscalYear = pool.get('account.fiscalyear')
+        Invoice = pool.get('account.invoice')
+
+        company = create_company()
+        with set_company(company):
+            create_chart(company)
+            fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+            fiscalyear.save()
+            FiscalYear.create_period([fiscalyear])
+            period = fiscalyear.periods[0]
+
+            receivable, = Account.search([
+                    ('type.receivable', '=', True),
+                    ])
+            revenue, = Account.search([
+                    ('type.revenue', '=', True),
+                    ])
+            journal, = Journal.search([], limit=1)
+            party, = Party.create([{
+                        'name': 'Party',
+                        'addresses': [
+                            ('create', [{}]),
+                            ],
+                        'credit_limit_amount': Decimal('100'),
+                        }])
+            Move.create([{
+                        'journal': journal.id,
+                        'period': period.id,
+                        'date': period.start_date,
+                        'lines': [
+                            ('create', [{
+                                        'debit': Decimal('100'),
+                                        'account': receivable.id,
+                                        'party': party.id,
+                                        }, {
+                                        'credit': Decimal('100'),
+                                        'account': revenue.id,
+                                        }]),
+                            ],
+                        }])
+            payment_term, = PaymentTerm.create([{
+                        'name': 'Test',
+                        'lines': [
+                            ('create', [{
+                                        'type': 'remainder',
+                                        }])
+                            ],
+                        }])
+            config = Configuration(1)
+            config.default_category_account_revenue = revenue
+            config.save()
+            sale, = Sale.create([{
+                        'party': party.id,
+                        'company': company.id,
+                        'payment_term': payment_term.id,
+                        'currency': company.currency.id,
+                        'invoice_address': party.addresses[0].id,
+                        'shipment_address': party.addresses[0].id,
+                        'lines': [
+                            ('create', [{
+                                        'description': 'Test',
+                                        'quantity': 1,
+                                        'unit_price': Decimal('50'),
+                                        }]),
+                            ],
+                        }])
+            self.assertEqual(party.credit_amount, Decimal('100'))
+            Sale.quote([sale])
+            # Test limit reaches
+            self.assertRaises(UserWarning, Sale.confirm, [sale])
+            self.assertEqual(party.credit_amount, Decimal('100'))
+            # Increase limit
+            party.credit_limit_amount = Decimal('200')
+            party.save()
+            # process should work
+            Sale.confirm([sale])
+            self.assertEqual(sale.state, 'confirmed')
+            self.assertEqual(party.credit_amount, Decimal('150'))
+
+            # Process
+            Sale.process([sale])
+            # Decrease limit
+            party.credit_limit_amount = Decimal('100')
+            party.save()
+            # process should still work as sale is already processing
+            Sale.process([sale])
+
+            # Increase quantity invoiced does not change the credit amount
+            invoice, = sale.invoices
+            invoice_line, = invoice.lines
+            invoice_line.quantity += 1
+            invoice_line.save()
+            Invoice.post([invoice])
+            self.assertEqual(party.credit_amount, Decimal('150'))
+
+
+del ModuleTestCase
diff -r eae84932558b -r 2fd04f978180 tests/test_sale_credit_limit.py
--- a/tests/test_sale_credit_limit.py   Sun Apr 10 19:11:39 2022 +0200
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +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 unittest
-from decimal import Decimal
-
-import trytond.tests.test_tryton
-from trytond.exceptions import UserWarning
-from trytond.modules.account.tests import create_chart, get_fiscalyear
-from trytond.modules.account_invoice.tests import set_invoice_sequences
-from trytond.modules.company.tests import (
-    CompanyTestMixin, create_company, set_company)
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase, with_transaction
-
-
-class SaleCreditLimitTestCase(CompanyTestMixin, ModuleTestCase):
-    'Test SaleCreditLimit module'
-    module = 'sale_credit_limit'
-
-    @with_transaction()
-    def test_check_credit_limit(self):
-        'Test check_credit_limit'
-        pool = Pool()
-        Account = pool.get('account.account')
-        Move = pool.get('account.move')
-        Journal = pool.get('account.journal')
-        Party = pool.get('party.party')
-        Sale = pool.get('sale.sale')
-        PaymentTerm = pool.get('account.invoice.payment_term')
-        Configuration = pool.get('account.configuration')
-        FiscalYear = pool.get('account.fiscalyear')
-        Invoice = pool.get('account.invoice')
-
-        company = create_company()
-        with set_company(company):
-            create_chart(company)
-            fiscalyear = set_invoice_sequences(get_fiscalyear(company))
-            fiscalyear.save()
-            FiscalYear.create_period([fiscalyear])
-            period = fiscalyear.periods[0]
-
-            receivable, = Account.search([
-                    ('type.receivable', '=', True),
-                    ])
-            revenue, = Account.search([
-                    ('type.revenue', '=', True),
-                    ])
-            journal, = Journal.search([], limit=1)
-            party, = Party.create([{
-                        'name': 'Party',
-                        'addresses': [
-                            ('create', [{}]),
-                            ],
-                        'credit_limit_amount': Decimal('100'),
-                        }])
-            Move.create([{
-                        'journal': journal.id,
-                        'period': period.id,
-                        'date': period.start_date,
-                        'lines': [
-                            ('create', [{
-                                        'debit': Decimal('100'),
-                                        'account': receivable.id,
-                                        'party': party.id,
-                                        }, {
-                                        'credit': Decimal('100'),
-                                        'account': revenue.id,
-                                        }]),
-                            ],
-                        }])
-            payment_term, = PaymentTerm.create([{
-                        'name': 'Test',
-                        'lines': [
-                            ('create', [{
-                                        'type': 'remainder',
-                                        }])
-                            ],
-                        }])
-            config = Configuration(1)
-            config.default_category_account_revenue = revenue
-            config.save()
-            sale, = Sale.create([{
-                        'party': party.id,
-                        'company': company.id,
-                        'payment_term': payment_term.id,
-                        'currency': company.currency.id,
-                        'invoice_address': party.addresses[0].id,
-                        'shipment_address': party.addresses[0].id,
-                        'lines': [
-                            ('create', [{
-                                        'description': 'Test',
-                                        'quantity': 1,
-                                        'unit_price': Decimal('50'),
-                                        }]),
-                            ],
-                        }])
-            self.assertEqual(party.credit_amount, Decimal('100'))
-            Sale.quote([sale])
-            # Test limit reaches
-            self.assertRaises(UserWarning, Sale.confirm, [sale])
-            self.assertEqual(party.credit_amount, Decimal('100'))
-            # Increase limit
-            party.credit_limit_amount = Decimal('200')
-            party.save()
-            # process should work
-            Sale.confirm([sale])
-            self.assertEqual(sale.state, 'confirmed')
-            self.assertEqual(party.credit_amount, Decimal('150'))
-
-            # Process
-            Sale.process([sale])
-            # Decrease limit
-            party.credit_limit_amount = Decimal('100')
-            party.save()
-            # process should still work as sale is already processing
-            Sale.process([sale])
-
-            # Increase quantity invoiced does not change the credit amount
-            invoice, = sale.invoices
-            invoice_line, = invoice.lines
-            invoice_line.quantity += 1
-            invoice_line.save()
-            Invoice.post([invoice])
-            self.assertEqual(party.credit_amount, Decimal('150'))
-
-
-def suite():
-    suite = trytond.tests.test_tryton.suite()
-    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
-        SaleCreditLimitTestCase))
-    return suite
diff -r eae84932558b -r 2fd04f978180 tox.ini
--- a/tox.ini   Sun Apr 10 19:11:39 2022 +0200
+++ b/tox.ini   Sat Apr 16 18:30:18 2022 +0200
@@ -3,7 +3,7 @@
 
 [testenv]
 commands =
-    coverage run --include=.*/sale_credit_limit/* setup.py test
+    coverage run --include=.*/sale_credit_limit/* -m unittest discover -s tests
     coverage report --include=.*/sale_credit_limit/* --omit=*/tests/*
 deps =
     coverage

Reply via email to