Merge pull request #122 from acsone/7.0-fix-async_move_line_importer-test-suite-sbi

[FIX] adapt test suite for 2015 year change
This commit is contained in:
Leonardo Pistone
2015-01-09 11:21:48 +01:00
2 changed files with 51 additions and 36 deletions

View File

@@ -99,43 +99,64 @@ def journal_period_draft(self, journal_period_id, context):
context=context)
def get_journal_copy_id(self, journal_id, context=None):
return self.registry('account.journal').copy(self.cr, self.uid,
journal_id, {}, context)
def create_fiscalyear(self, year, company_id):
fiscalyear_obj = self.registry('account.fiscalyear')
fiscalyear_id = fiscalyear_obj.create(self.cr, self.uid, {
'name': year,
'code': year,
'date_start': year + '-01-01',
'date_stop': year + '-12-31',
'company_id': company_id
})
fiscalyear_obj.create_period(self.cr, self.uid, [fiscalyear_id])
return fiscalyear_id
class TestAccountJournalPeriodClose(common.TransactionCase):
def setUp(self):
super(TestAccountJournalPeriodClose, self).setUp()
company_id = self.ref('base.main_company')
fiscalyear_id = create_fiscalyear(self, '2013', company_id)
journal_id = self.ref('account.sales_journal')
self.period_id = self.registry('account.period')\
.search(self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear_id)],
limit=1)[0]
self.journal_id = get_journal_copy_id(self, journal_id)
def test_close_period_open_journal(self):
context = {}
journal_id = self.ref('account.sales_journal')
period_id = self.ref('account.period_1')
close_period(self, period_id, context)
close_period(self, self.period_id, context)
journal_period_id = create_journal_period(self,
period_id,
journal_id,
self.period_id,
self.journal_id,
context)
journal_period_draft(self, journal_period_id, context)
self.registry('account.move')\
.create(self.cr,
self.uid,
get_simple_account_move_values(self,
period_id,
journal_id),
self.period_id,
self.journal_id),
context=context)
# Here, no exception should be raised because the journal's state is
# draft although the period is closed
def test_open_period_close_journal(self):
context = {}
journal_id = self.ref('account.sales_journal')
period_id = self.ref('account.period_1')
journal_period_id = create_journal_period(self,
period_id,
journal_id,
self.period_id,
self.journal_id,
context)
journal_period_done(self, journal_period_id, context)
move_values = get_simple_account_move_values(self,
period_id,
journal_id)
self.period_id,
self.journal_id)
# I check if the exception is correctly raised at create of an account
# move which is linked with a closed journal
self.assertRaises(osv.except_osv,
@@ -144,16 +165,14 @@ class TestAccountJournalPeriodClose(common.TransactionCase):
def test_change_journal_on_move(self):
context = {}
journal_id = self.ref('account.sales_journal')
journal_cash_id = self.ref('account.cash_journal')
period_id = self.ref('account.period_1')
journal_period_id = create_journal_period(self,
period_id,
journal_id,
self.period_id,
self.journal_id,
context)
journal_period_done(self, journal_period_id, context)
move_values = get_simple_account_move_values(self,
period_id,
self.period_id,
journal_cash_id)
self.registry('account.move').create(self.cr,
self.uid,
@@ -173,11 +192,9 @@ class TestAccountJournalPeriodClose(common.TransactionCase):
context = {}
jour_per_obj = self.registry('account.journal.period')
journal_id = self.ref('account.sales_journal')
period_id = self.ref('account.period_1')
move_values = get_simple_account_move_values(self,
period_id,
journal_id)
self.period_id,
self.journal_id)
self.registry('account.move').create(self.cr,
self.uid,
move_values,
@@ -185,8 +202,8 @@ class TestAccountJournalPeriodClose(common.TransactionCase):
journal_period_ids =\
jour_per_obj.search(self.cr,
self.uid,
[('period_id', '=', period_id),
('journal_id', '=', journal_id),
[('period_id', '=', self.period_id),
('journal_id', '=', self.journal_id),
],
context=context)
# I check if the exception is correctly raised at closing journal that
@@ -198,15 +215,13 @@ class TestAccountJournalPeriodClose(common.TransactionCase):
def test_duplicate_journal_period(self):
context = {}
journal_id = self.ref('account.sales_journal')
period_id = self.ref('account.period_1')
create_journal_period(self, period_id, journal_id, context)
create_journal_period(self, self.period_id, self.journal_id, context)
# I check if the exception is correctly raised at adding both same
# journal on a period
self.cr._default_log_exceptions = False
try:
self.assertRaises(IntegrityError,
create_journal_period,
self, period_id, journal_id, context)
self, self.period_id, self.journal_id, context)
finally:
self.cr._default_log_exceptions = True

View File

@@ -18,8 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import base64
import tempfile
import time
import openerp.tests.common as test_common
from openerp import addons
@@ -28,14 +27,15 @@ from openerp import addons
class TestMoveLineImporter(test_common.SingleTransactionCase):
def get_file(self, filename):
"""Retrive file from test data"""
"""Retrieve file from test data,
encode it as base64
and adjust it for current year
"""
path = addons.get_module_resource('async_move_line_importer',
'tests', 'data', filename)
with open(path) as test_data:
with tempfile.TemporaryFile() as out:
base64.encode(test_data, out)
out.seek(0)
return out.read()
test_data = open(path).read()
test_data = test_data.replace('2014', time.strftime('%Y'))
return test_data.encode("base64")
def setUp(self):
super(TestMoveLineImporter, self).setUp()