changeset 2c27c4206f4d in modules/bank:default
details: https://hg.tryton.org/modules/bank?cmd=changeset&node=2c27c4206f4d
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 4 +-
tests/__init__.py | 7 --
tests/test_bank.py | 164 ---------------------------------------------------
tests/test_module.py | 159 +++++++++++++++++++++++++++++++++++++++++++++++++
tox.ini | 3 +-
5 files changed, 162 insertions(+), 175 deletions(-)
diffs (377 lines):
diff -r e539fccedec0 -r 2c27c4206f4d setup.py
--- a/setup.py Mon Apr 11 23:47:18 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:17 2022 +0200
@@ -139,6 +139,7 @@
install_requires=requires,
extras_require={
'SWIFT': ['schwifty'],
+ 'test': tests_require,
},
dependency_links=dependency_links,
zip_safe=False,
@@ -146,7 +147,4 @@
[trytond.modules]
bank = trytond.modules.bank
""",
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r e539fccedec0 -r 2c27c4206f4d tests/__init__.py
--- a/tests/__init__.py Mon Apr 11 23:47:18 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:17 2022 +0200
@@ -1,9 +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.bank.tests.test_bank import suite
-except ImportError:
- from .test_bank import suite
-
-__all__ = ['suite']
diff -r e539fccedec0 -r 2c27c4206f4d tests/test_bank.py
--- a/tests/test_bank.py Mon Apr 11 23:47:18 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +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
-
-try:
- import schwifty
-except ImportError:
- schwifty = None
-
-import trytond.tests.test_tryton
-from trytond.model.exceptions import SQLConstraintError
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase, with_transaction
-
-from ..exceptions import InvalidBIC
-
-
-class BankTestCase(ModuleTestCase):
- 'Test Bank module'
- module = 'bank'
-
- @with_transaction()
- def test_bic_validation(self):
- "Test BIC validation"
- pool = Pool()
- Party = pool.get('party.party')
- Bank = pool.get('bank')
-
- party = Party(name='Test')
- party.save()
- bank = Bank(party=party)
- bank.save()
-
- bank.bic = 'ABNA BE 2A'
- bank.bic = bank.on_change_with_bic()
- self.assertEqual(bank.bic, 'ABNABE2A')
-
- bank.save()
-
- with self.assertRaises(InvalidBIC):
- bank.bic = 'foo'
- bank.save()
-
- @with_transaction()
- def test_iban_format(self):
- 'Test IBAN format'
- pool = Pool()
- Party = pool.get('party.party')
- Bank = pool.get('bank')
- Account = pool.get('bank.account')
- Number = pool.get('bank.account.number')
-
- party = Party(name='Test')
- party.save()
- bank = Bank(party=party)
- bank.save()
- account, = Account.create([{
- 'bank': bank.id,
- 'numbers': [('create', [{
- 'type': 'iban',
- 'number': 'BE82068896274468',
- }, {
- 'type': 'other',
- 'number': 'not IBAN',
- }])],
- }])
-
- iban_number, other_number = account.numbers
- self.assertEqual(iban_number.type, 'iban')
- self.assertEqual(other_number.type, 'other')
-
- # Test format on create
- self.assertEqual(iban_number.number, 'BE82 0688 9627 4468')
- self.assertEqual(other_number.number, 'not IBAN')
-
- # Test format on write
- iban_number.number = 'BE82068896274468'
- iban_number.type = 'iban'
- iban_number.save()
- self.assertEqual(iban_number.number, 'BE82 0688 9627 4468')
-
- other_number.number = 'still not IBAN'
- other_number.save()
- self.assertEqual(other_number.number, 'still not IBAN')
-
- Number.write([iban_number, other_number], {
- 'number': 'BE82068896274468',
- })
- self.assertEqual(iban_number.number, 'BE82 0688 9627 4468')
- self.assertEqual(other_number.number, 'BE82068896274468')
-
- @with_transaction()
- def test_number_single_iban(self):
- "Test number has single IBAN"
- pool = Pool()
- Account = pool.get('bank.account')
- Number = pool.get('bank.account.number')
-
- account = Account(numbers=[
- Number(type='iban', number="BE82 0688 9627 4468"),
- Number(type='iban', number="BE67 0682 4952 8887"),
- ])
-
- with self.assertRaises(SQLConstraintError):
- account.save()
-
- @with_transaction()
- def test_number_iban_unique(self):
- "Test number has single IBAN"
- pool = Pool()
- Account = pool.get('bank.account')
- Number = pool.get('bank.account.number')
-
- account = Account(numbers=[
- Number(type='iban', number="BE82 0688 9627 4468"),
- ])
- account.save()
- account = Account(numbers=[
- Number(type='iban', number="BE82 0688 9627 4468"),
- ])
-
- with self.assertRaises(SQLConstraintError):
- account.save()
-
- @unittest.skipIf(schwifty is None, "requires schwifty")
- @with_transaction()
- def test_guess_new_bank(self):
- "Test guess new bank"
- pool = Pool()
- Account = pool.get('bank.account')
- Number = pool.get('bank.account.number')
-
- account = Account(numbers=[
- Number(type='iban', number="BE82 0688 9627 4468")])
- account.save()
-
- self.assertTrue(account.bank)
- self.assertEqual(account.bank.bic, 'GKCCBEBB')
- self.assertEqual(account.bank.party.name, "BELFIUS BANK")
-
- @unittest.skipIf(schwifty is None, "requires schwifty")
- @with_transaction()
- def test_guess_existing_bank(self):
- "Test guess existing bank"
- pool = Pool()
- Account = pool.get('bank.account')
- Bank = pool.get('bank')
- Number = pool.get('bank.account.number')
-
- account1 = Account(numbers=[
- Number(type='iban', number="BE82 0688 9627 4468")])
- account1.save()
- account2 = Account(numbers=[
- Number(type='iban', number="BE67 0682 4952 8887")])
- account2.save()
-
- self.assertEqual(len(Bank.search([])), 1)
-
-
-def suite():
- suite = trytond.tests.test_tryton.suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- BankTestCase))
- return suite
diff -r e539fccedec0 -r 2c27c4206f4d 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,159 @@
+# 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
+
+try:
+ import schwifty
+except ImportError:
+ schwifty = None
+
+from trytond.model.exceptions import SQLConstraintError
+from trytond.modules.bank.exceptions import InvalidBIC
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class BankTestCase(ModuleTestCase):
+ 'Test Bank module'
+ module = 'bank'
+
+ @with_transaction()
+ def test_bic_validation(self):
+ "Test BIC validation"
+ pool = Pool()
+ Party = pool.get('party.party')
+ Bank = pool.get('bank')
+
+ party = Party(name='Test')
+ party.save()
+ bank = Bank(party=party)
+ bank.save()
+
+ bank.bic = 'ABNA BE 2A'
+ bank.bic = bank.on_change_with_bic()
+ self.assertEqual(bank.bic, 'ABNABE2A')
+
+ bank.save()
+
+ with self.assertRaises(InvalidBIC):
+ bank.bic = 'foo'
+ bank.save()
+
+ @with_transaction()
+ def test_iban_format(self):
+ 'Test IBAN format'
+ pool = Pool()
+ Party = pool.get('party.party')
+ Bank = pool.get('bank')
+ Account = pool.get('bank.account')
+ Number = pool.get('bank.account.number')
+
+ party = Party(name='Test')
+ party.save()
+ bank = Bank(party=party)
+ bank.save()
+ account, = Account.create([{
+ 'bank': bank.id,
+ 'numbers': [('create', [{
+ 'type': 'iban',
+ 'number': 'BE82068896274468',
+ }, {
+ 'type': 'other',
+ 'number': 'not IBAN',
+ }])],
+ }])
+
+ iban_number, other_number = account.numbers
+ self.assertEqual(iban_number.type, 'iban')
+ self.assertEqual(other_number.type, 'other')
+
+ # Test format on create
+ self.assertEqual(iban_number.number, 'BE82 0688 9627 4468')
+ self.assertEqual(other_number.number, 'not IBAN')
+
+ # Test format on write
+ iban_number.number = 'BE82068896274468'
+ iban_number.type = 'iban'
+ iban_number.save()
+ self.assertEqual(iban_number.number, 'BE82 0688 9627 4468')
+
+ other_number.number = 'still not IBAN'
+ other_number.save()
+ self.assertEqual(other_number.number, 'still not IBAN')
+
+ Number.write([iban_number, other_number], {
+ 'number': 'BE82068896274468',
+ })
+ self.assertEqual(iban_number.number, 'BE82 0688 9627 4468')
+ self.assertEqual(other_number.number, 'BE82068896274468')
+
+ @with_transaction()
+ def test_number_single_iban(self):
+ "Test number has single IBAN"
+ pool = Pool()
+ Account = pool.get('bank.account')
+ Number = pool.get('bank.account.number')
+
+ account = Account(numbers=[
+ Number(type='iban', number="BE82 0688 9627 4468"),
+ Number(type='iban', number="BE67 0682 4952 8887"),
+ ])
+
+ with self.assertRaises(SQLConstraintError):
+ account.save()
+
+ @with_transaction()
+ def test_number_iban_unique(self):
+ "Test number has single IBAN"
+ pool = Pool()
+ Account = pool.get('bank.account')
+ Number = pool.get('bank.account.number')
+
+ account = Account(numbers=[
+ Number(type='iban', number="BE82 0688 9627 4468"),
+ ])
+ account.save()
+ account = Account(numbers=[
+ Number(type='iban', number="BE82 0688 9627 4468"),
+ ])
+
+ with self.assertRaises(SQLConstraintError):
+ account.save()
+
+ @unittest.skipIf(schwifty is None, "requires schwifty")
+ @with_transaction()
+ def test_guess_new_bank(self):
+ "Test guess new bank"
+ pool = Pool()
+ Account = pool.get('bank.account')
+ Number = pool.get('bank.account.number')
+
+ account = Account(numbers=[
+ Number(type='iban', number="BE82 0688 9627 4468")])
+ account.save()
+
+ self.assertTrue(account.bank)
+ self.assertEqual(account.bank.bic, 'GKCCBEBB')
+ self.assertEqual(account.bank.party.name, "BELFIUS BANK")
+
+ @unittest.skipIf(schwifty is None, "requires schwifty")
+ @with_transaction()
+ def test_guess_existing_bank(self):
+ "Test guess existing bank"
+ pool = Pool()
+ Account = pool.get('bank.account')
+ Bank = pool.get('bank')
+ Number = pool.get('bank.account.number')
+
+ account1 = Account(numbers=[
+ Number(type='iban', number="BE82 0688 9627 4468")])
+ account1.save()
+ account2 = Account(numbers=[
+ Number(type='iban', number="BE67 0682 4952 8887")])
+ account2.save()
+
+ self.assertEqual(len(Bank.search([])), 1)
+
+
+del ModuleTestCase
diff -r e539fccedec0 -r 2c27c4206f4d tox.ini
--- a/tox.ini Mon Apr 11 23:47:18 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=.*/bank/* setup.py test
+ coverage run --include=.*/bank/* -m unittest discover -s tests
coverage report --include=.*/bank/* --omit=*/tests/*
deps =
coverage