Skip to content
Snippets Groups Projects
Commit 731b9f60 authored by Christophe Simonis's avatar Christophe Simonis
Browse files

[FIX] account: skip tests using `skipTest` method

parent 6016b16a
No related branches found
No related tags found
No related merge requests found
import logging
# -*- coding: utf-8 -*-
from openerp.tests.common import TransactionCase
from openerp import SUPERUSER_ID
from openerp import api
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 SKIP TESTS and return a success if
it cannot find an already configured accounting (which means no localization
module has been installed).
the installation of all modules, and will SKIP TESTS ifit 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.
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
def setUp(self):
super(AccountingTestCase, self).setUp()
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():
# 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
super(AccountingTestCase, self).run(result=result)
if not self.env['account.account'].search_count(domain):
self.skipTest("No Chart of account found")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment