[IMP] account: improve doc and add warning on post-install tests

This commit is contained in:
Raphael Collet
2015-09-17 11:59:03 +02:00
parent 3659c0113b
commit d4a24f3663
+19 -11
View File
@@ -1,3 +1,5 @@
import logging
from openerp.tests.common import TransactionCase
from openerp import SUPERUSER_ID
from openerp import api
@@ -5,32 +7,38 @@ from openerp.modules.registry import RegistryManager
from openerp.tools import config
DB = config['db_name']
_logger = logging.getLogger(__name__)
class AccountingTestCase(TransactionCase):
"""
This class extends the base TransactionCase, in order to test the accounting with localization setups.
It is configured to run the tests after the installation of all modules, and will always return a success
if it cannot find an already configured accounting (which means no localization module has been installed).
""" This class extends the base TransactionCase, in order to test the
accounting with localization setups. It is configured to run the tests after
the installation of all modules, and will SKIP TESTS and return a success if
it cannot find an already configured accounting (which means no localization
module has been installed).
"""
post_install = True
at_install = False
def _check_accounting_configured(self):
#minimal setUp() similar to the one of TransactionCase, although we can't use the regular setUp()
#because we want to assume the accounting is already configured when making the setUp of tests.
# minimal setUp() similar to the one of TransactionCase, although we
# can't use the regular setUp() because we want to assume the accounting
# is already configured when making the setUp of tests.
self.registry = RegistryManager.get(DB)
self.cr = self.cursor()
self.uid = SUPERUSER_ID
self.env = api.Environment(self.cr, self.uid, {})
#having at least one account created means the accounting is ready to be tested
res = bool(self.env['account.account'].search([('company_id', '=', self.env.ref('base.main_company').id)]))
#close the cursor, eventually rolleback and reset the environment
# having at least one account created means the accounting is ready to be tested
domain = [('company_id', '=', self.env.ref('base.main_company').id)]
res = bool(self.env['account.account'].search_count(domain))
# rollback and close the cursor, and reset the environment
self.tearDown()
return res
def run(self, result=None):
if not self._check_accounting_configured():
#if the accounting if not ready to be tested, consider this test as a success
# no chart of account is available, so skip the tests and consider
# it as a success
_logger.warning("No chart of account, skip %s", self)
return
#once at least one localization is installed, we can run the tests
super(AccountingTestCase, self).run(result=result)