Make TestCase create and drop its database
and use with_transaction decorator. issue5263 review20711002
This commit is contained in:
1 parent
c3b6648204
commit
1c7b0aa606
2 files changed
+79
-71
No files matched your search
+2
-2
@@ -1,6 +1,6 @@
|
||||
# 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 .test_account_invoice import suite
|
||||
from .test_account_invoice import suite, set_invoice_sequences
|
||||
|
||||
__all__ = ['suite']
|
||||
__all__ = ['suite', 'set_invoice_sequences']
|
||||
@@ -5,84 +5,92 @@ import doctest
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
|
||||
from trytond.modules.currency.tests import create_currency
|
||||
|
||||
|
||||
def set_invoice_sequences(fiscalyear):
|
||||
pool = Pool()
|
||||
Sequence = pool.get('ir.sequence.strict')
|
||||
|
||||
sequence = Sequence(name=fiscalyear.name, code='account.invoice')
|
||||
sequence.company = fiscalyear.company
|
||||
sequence.save()
|
||||
for type_ in ['out', 'in']:
|
||||
for invoice in ['invoice', 'credit_note']:
|
||||
name = '%s_%s_sequence' % (type_, invoice)
|
||||
setattr(fiscalyear, name, sequence)
|
||||
return fiscalyear
|
||||
|
||||
|
||||
class AccountInvoiceTestCase(ModuleTestCase):
|
||||
'Test AccountInvoice module'
|
||||
module = 'account_invoice'
|
||||
|
||||
def setUp(self):
|
||||
super(AccountInvoiceTestCase, self).setUp()
|
||||
self.payment_term = POOL.get('account.invoice.payment_term')
|
||||
self.currency = POOL.get('currency.currency')
|
||||
|
||||
def test0010payment_term(self):
|
||||
@with_transaction()
|
||||
def test_payment_term(self):
|
||||
'Test payment_term'
|
||||
with Transaction().start(DB_NAME, USER, context=CONTEXT):
|
||||
cu1, = self.currency.create([{
|
||||
'name': 'cu1',
|
||||
'symbol': 'cu1',
|
||||
'code': 'cu1'
|
||||
}])
|
||||
pool = Pool()
|
||||
PaymentTerm = pool.get('account.invoice.payment_term')
|
||||
|
||||
term, = self.payment_term.create([{
|
||||
'name': '30 days, 1 month, 1 month + 15 days',
|
||||
'lines': [
|
||||
('create', [{
|
||||
'sequence': 0,
|
||||
'type': 'percent',
|
||||
'divisor': 4,
|
||||
'ratio': Decimal('.25'),
|
||||
'relativedeltas': [('create', [{
|
||||
'days': 30,
|
||||
},
|
||||
]),
|
||||
],
|
||||
}, {
|
||||
'sequence': 1,
|
||||
'type': 'percent_on_total',
|
||||
'divisor': 4,
|
||||
'ratio': Decimal('.25'),
|
||||
'relativedeltas': [('create', [{
|
||||
'months': 1,
|
||||
},
|
||||
]),
|
||||
],
|
||||
}, {
|
||||
'sequence': 2,
|
||||
'type': 'fixed',
|
||||
'amount': Decimal('396.84'),
|
||||
'currency': cu1.id,
|
||||
'relativedeltas': [('create', [{
|
||||
'months': 1,
|
||||
'days': 30,
|
||||
},
|
||||
]),
|
||||
],
|
||||
}, {
|
||||
'sequence': 3,
|
||||
'type': 'remainder',
|
||||
'relativedeltas': [('create', [{
|
||||
'months': 2,
|
||||
'days': 30,
|
||||
'day': 15,
|
||||
},
|
||||
]),
|
||||
],
|
||||
}])]
|
||||
}])
|
||||
terms = term.compute(Decimal('1587.35'), cu1,
|
||||
date=datetime.date(2011, 10, 1))
|
||||
self.assertEqual(terms, [
|
||||
(datetime.date(2011, 10, 31), Decimal('396.84')),
|
||||
(datetime.date(2011, 11, 01), Decimal('396.84')),
|
||||
(datetime.date(2011, 12, 01), Decimal('396.84')),
|
||||
(datetime.date(2012, 01, 14), Decimal('396.83')),
|
||||
])
|
||||
cu1 = create_currency('cu1')
|
||||
term, = PaymentTerm.create([{
|
||||
'name': '30 days, 1 month, 1 month + 15 days',
|
||||
'lines': [
|
||||
('create', [{
|
||||
'sequence': 0,
|
||||
'type': 'percent',
|
||||
'divisor': 4,
|
||||
'ratio': Decimal('.25'),
|
||||
'relativedeltas': [('create', [{
|
||||
'days': 30,
|
||||
},
|
||||
]),
|
||||
],
|
||||
}, {
|
||||
'sequence': 1,
|
||||
'type': 'percent_on_total',
|
||||
'divisor': 4,
|
||||
'ratio': Decimal('.25'),
|
||||
'relativedeltas': [('create', [{
|
||||
'months': 1,
|
||||
},
|
||||
]),
|
||||
],
|
||||
}, {
|
||||
'sequence': 2,
|
||||
'type': 'fixed',
|
||||
'amount': Decimal('396.84'),
|
||||
'currency': cu1.id,
|
||||
'relativedeltas': [('create', [{
|
||||
'months': 1,
|
||||
'days': 30,
|
||||
},
|
||||
]),
|
||||
],
|
||||
}, {
|
||||
'sequence': 3,
|
||||
'type': 'remainder',
|
||||
'relativedeltas': [('create', [{
|
||||
'months': 2,
|
||||
'days': 30,
|
||||
'day': 15,
|
||||
},
|
||||
]),
|
||||
],
|
||||
}])]
|
||||
}])
|
||||
terms = term.compute(Decimal('1587.35'), cu1,
|
||||
date=datetime.date(2011, 10, 1))
|
||||
self.assertEqual(terms, [
|
||||
(datetime.date(2011, 10, 31), Decimal('396.84')),
|
||||
(datetime.date(2011, 11, 01), Decimal('396.84')),
|
||||
(datetime.date(2011, 12, 01), Decimal('396.84')),
|
||||
(datetime.date(2012, 01, 14), Decimal('396.83')),
|
||||
])
|
||||
|
||||
|
||||
def suite():
|
||||
|
||||
Reference in new issue
Block a user