[MERGE] added single transaction unit test base case.
bzr revid: vmt@openerp.com-20121029145723-ov1efsnh5b834cy4
This commit is contained in:
commit
d45e2db49b
|
@ -9,6 +9,7 @@ See the :ref:`test-framework` section in the :ref:`features` list.
|
|||
"""
|
||||
|
||||
from . import test_expression, test_html_sanitize, test_ir_sequence, test_orm,\
|
||||
test_per_class_teardown, \
|
||||
test_view_validation, test_uninstall, test_misc, test_db_cursor
|
||||
|
||||
fast_suite = [
|
||||
|
@ -20,6 +21,7 @@ checks = [
|
|||
test_html_sanitize,
|
||||
test_db_cursor,
|
||||
test_orm,
|
||||
test_per_class_teardown,
|
||||
test_view_validation,
|
||||
test_misc,
|
||||
]
|
||||
|
|
|
@ -40,10 +40,25 @@ def stop_openerp():
|
|||
"""
|
||||
openerp.service.stop_services()
|
||||
|
||||
class TransactionCase(unittest2.TestCase):
|
||||
|
||||
class BaseCase(unittest2.TestCase):
|
||||
"""
|
||||
Subclass of TestCase with a single transaction, rolled-back at the end of
|
||||
the tests.
|
||||
Subclass of TestCase for common OpenERP-specific code.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def cursor(self):
|
||||
return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
|
||||
|
||||
@classmethod
|
||||
def registry(self, model):
|
||||
return openerp.modules.registry.RegistryManager.get(DB)[model]
|
||||
|
||||
|
||||
class TransactionCase(BaseCase):
|
||||
"""
|
||||
Subclass of BaseCase with a single transaction, rolled-back at the end of
|
||||
each test (method).
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
|
@ -54,11 +69,23 @@ class TransactionCase(unittest2.TestCase):
|
|||
self.cr.rollback()
|
||||
self.cr.close()
|
||||
|
||||
def cursor(self):
|
||||
return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
|
||||
|
||||
def registry(self, model):
|
||||
return openerp.modules.registry.RegistryManager.get(DB)[model]
|
||||
class SingleTransactionCase(BaseCase):
|
||||
"""
|
||||
Subclass of BaseCase with a single transaction for the whole class,
|
||||
rolled-back after all the tests.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.cr = cls.cursor()
|
||||
cls.uid = openerp.SUPERUSER_ID
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.cr.rollback()
|
||||
cls.cr.close()
|
||||
|
||||
|
||||
class RpcCase(unittest2.TestCase):
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import unittest2
|
||||
|
||||
import openerp
|
||||
import common
|
||||
|
||||
class test_per_class_teardown(common.SingleTransactionCase):
|
||||
"""
|
||||
Check the whole-class transaction behavior of SingleTransactionCase.
|
||||
"""
|
||||
|
||||
def test_00(self):
|
||||
"""Create a partner."""
|
||||
cr, uid = self.cr, self.uid
|
||||
self.registry('res.partner').create(cr, uid, {'name': 'test_per_class_teardown_partner'})
|
||||
ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')])
|
||||
self.assertEqual(1, len(ids), "Test partner not found.")
|
||||
|
||||
def test_01(self):
|
||||
"""Find the created partner."""
|
||||
cr, uid = self.cr, self.uid
|
||||
ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')])
|
||||
self.assertEqual(1, len(ids), "Test partner not found.")
|
||||
|
||||
class test_per_method_teardown(common.TransactionCase):
|
||||
"""
|
||||
Check the per-method transaction behavior of TransactionCase.
|
||||
"""
|
||||
|
||||
def test_00(self):
|
||||
"""Create a partner."""
|
||||
cr, uid = self.cr, self.uid
|
||||
ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')])
|
||||
self.assertEqual(0, len(ids), "Test partner found.")
|
||||
self.registry('res.partner').create(cr, uid, {'name': 'test_per_class_teardown_partner'})
|
||||
ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')])
|
||||
self.assertEqual(1, len(ids), "Test partner not found.")
|
||||
|
||||
def test_01(self):
|
||||
"""Don't find the created partner."""
|
||||
cr, uid = self.cr, self.uid
|
||||
ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')])
|
||||
self.assertEqual(0, len(ids), "Test partner found.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
Loading…
Reference in New Issue