Vo Minh Thu (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-server/trunk-per-class-teardown-vmt into 
lp:openobject-server.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-per-class-teardown-vmt/+merge/131917
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-per-class-teardown-vmt/+merge/131917
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/trunk-per-class-teardown-vmt.
=== modified file 'openerp/tests/__init__.py'
--- openerp/tests/__init__.py	2012-10-15 10:18:49 +0000
+++ openerp/tests/__init__.py	2012-10-29 14:21:20 +0000
@@ -9,6 +9,7 @@
 """
 
 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 @@
     test_html_sanitize,
     test_db_cursor,
     test_orm,
+    test_per_class_teardown,
     test_view_validation,
     test_misc,
 ]

=== modified file 'openerp/tests/common.py'
--- openerp/tests/common.py	2012-09-13 14:29:20 +0000
+++ openerp/tests/common.py	2012-10-29 14:21:20 +0000
@@ -40,10 +40,25 @@
     """
     openerp.service.stop_services()
 
-class TransactionCase(unittest2.TestCase):
-    """
-    Subclass of TestCase with a single transaction, rolled-back at the end of
-    the tests.
+
+class BaseCase(unittest2.TestCase):
+    """
+    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 @@
         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):
     """

=== added file 'openerp/tests/test_per_class_teardown.py'
--- openerp/tests/test_per_class_teardown.py	1970-01-01 00:00:00 +0000
+++ openerp/tests/test_per_class_teardown.py	2012-10-29 14:21:20 +0000
@@ -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:

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to