Reviewers: ,


Please review this at http://codereview.tryton.org/168003/

Affected files:
  A trytond/tests/test_transaction.py
  M trytond/transaction.py


Index: trytond/tests/test_transaction.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/trytond/tests/test_transaction.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#This file is part of Tryton.  The COPYRIGHT file at the top level of
+#this repository contains the full copyright notices and license terms.
+from __future__ import with_statement
+import unittest
+from trytond.tests.test_tryton import DB_NAME, USER, CONTEXT
+from trytond.transaction import Transaction
+
+
+def empty_transaction(*args):
+    '''
+    Just starts a transaction in the context manager and returns `True`
+    and stops transaction for the given arguments.
+
+    All positional arguments are passed to `start` method of transaction
+    '''
+    with Transaction().start(*args):
+        return True
+
+
+class TransactionTestCase(unittest.TestCase):
+    '''
+    Test the Transaction Context manager
+    '''
+
+    def test0010nonexistdb(self):
+        '''
+ Attempt opening a transaction with a non existant DB and ensure that
+        it stops cleanly and allows starting of next transaction
+        '''
+        self.assertRaises(
+            Exception, empty_transaction, "Non existant DB", USER, CONTEXT
+        )
+        self.assertTrue(empty_transaction(DB_NAME, USER, CONTEXT))
+
+
+def suite():
+    return unittest.TestLoader().loadTestsFromTestCase(TransactionTestCase)
+
+if __name__ == '__main__':
+    suite = suite()
+    unittest.TextTestRunner(verbosity=2).run(suite)
+
Index: trytond/transaction.py
===================================================================
--- a/trytond/transaction.py
+++ b/trytond/transaction.py
@@ -70,9 +70,9 @@
         assert self.user is None
         assert self.cursor is None
         assert self.context is None
-        self.user = user
         database = Database(database_name).connect()
         self.cursor = database.cursor()
+        self.user = user
         self.context = context or {}
         self.create_records = {}
         self.delete_records = {}


--
[email protected] mailing list

Reply via email to