1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
# 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.modules.currency.tests import create_currency
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_account_rec_name_without_number(self):
"Test account record name without number"
pool = Pool()
Account = pool.get('bank.account')
account = Account()
account.save()
self.assertEqual(account.rec_name, "(%s)" % account.id)
@with_transaction()
def test_account_rec_name_with_number(self):
"Test account record name with number"
pool = Pool()
Account = pool.get('bank.account')
Number = pool.get('bank.account.number')
account = Account(numbers=[
Number(type='other', number="1234")])
account.save()
self.assertEqual(account.rec_name, "1234")
@with_transaction()
def test_account_rec_name_with_bank(self):
"Test account record name with bank"
pool = Pool()
Account = pool.get('bank.account')
Bank = pool.get('bank')
Number = pool.get('bank.account.number')
Party = pool.get('party.party')
party = Party(name="Bank")
party.save()
bank = Bank(party=party)
bank.save()
account = Account(
numbers=[Number(type='other', number="1234")],
bank=bank)
account.save()
self.assertEqual(account.rec_name, "1234 @ Bank")
@with_transaction()
def test_account_rec_name_with_currency(self):
"Test account record name with currency"
pool = Pool()
Account = pool.get('bank.account')
Number = pool.get('bank.account.number')
currency = create_currency("USD")
account = Account(
numbers=[Number(type='other', number="1234")],
currency=currency)
account.save()
self.assertEqual(account.rec_name, "1234 [USD]")
@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)
@with_transaction()
def test_guess_bank_without_iban(self):
"Test guess bank without IBAN"
pool = Pool()
Account = pool.get('bank.account')
Number = pool.get('bank.account.number')
account = Account(numbers=[
Number(type='other', number="123456")])
account.save()
self.assertIsNone(account.bank)
del ModuleTestCase
|