Commit 7ec49c4c authored by Stefan H. Holek's avatar Stefan H. Holek

Ported r29693 from the trunk:

__builtin__.get_transaction() is officially deprecated in ZODB 3.4.
parent 2ca1aff5
...@@ -91,11 +91,11 @@ What You Get ...@@ -91,11 +91,11 @@ What You Get
Hooks for controlling transactions: Hooks for controlling transactions:
- **'beforeSetUp'** is called before the ZODB connection is opened, at the start of setUp. - **'beforeSetUp'** is called before the ZODB connection is opened, at the start of setUp.
The default behaviour of this hook is to call 'get_transaction().begin()'. The default behaviour of this hook is to call 'transaction.begin()'.
You will rarely want to override this. You will rarely want to override this.
- **'beforeClose'** is called before the ZODB connection is closed, at the end of - **'beforeClose'** is called before the ZODB connection is closed, at the end of
tearDown. By default this method calls 'get_transaction().abort()' to discard tearDown. By default this method calls 'transaction.abort()' to discard
any changes made by the test. In some situations you may need to override any changes made by the test. In some situations you may need to override
this hook and commit the transaction instead. Make sure you really know what this hook and commit the transaction instead. Make sure you really know what
you are doing though. you are doing though.
......
...@@ -26,6 +26,8 @@ import os, sys ...@@ -26,6 +26,8 @@ import os, sys
if __name__ == '__main__': if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py')) execfile(os.path.join(sys.path[0], 'framework.py'))
import transaction
from Testing.ZopeTestCase import base from Testing.ZopeTestCase import base
from Testing.ZopeTestCase import utils from Testing.ZopeTestCase import utils
...@@ -146,7 +148,7 @@ class TestTestCase(HookTest): ...@@ -146,7 +148,7 @@ class TestTestCase(HookTest):
def getObjectsInTransaction(self): def getObjectsInTransaction(self):
# Lets us spy into the transaction # Lets us spy into the transaction
t = get_transaction() t = transaction.get()
if hasattr(t, '_objects'): # Zope < 2.8 if hasattr(t, '_objects'): # Zope < 2.8
return t._objects return t._objects
elif hasattr(t, '_resources'): # Zope >= 2.8 elif hasattr(t, '_resources'): # Zope >= 2.8
......
...@@ -41,6 +41,8 @@ from Testing import ZopeTestCase ...@@ -41,6 +41,8 @@ from Testing import ZopeTestCase
from AccessControl import Unauthorized from AccessControl import Unauthorized
import urllib import urllib
import transaction
# Create the error_log object # Create the error_log object
ZopeTestCase.utils.setupSiteErrorLog() ZopeTestCase.utils.setupSiteErrorLog()
...@@ -84,11 +86,11 @@ class TestWebserver(ZopeTestCase.ZopeTestCase): ...@@ -84,11 +86,11 @@ class TestWebserver(ZopeTestCase.ZopeTestCase):
self.folder.change_title.changeOwnership(manager) self.folder.change_title.changeOwnership(manager)
# Commit so the ZServer threads can see the changes # Commit so the ZServer threads can see the changes
get_transaction().commit() transaction.commit()
def beforeClose(self): def beforeClose(self):
# Commit after cleanup # Commit after cleanup
get_transaction().commit() transaction.commit()
def testAccessPublicObject(self): def testAccessPublicObject(self):
# Test access to a public resource # Test access to a public resource
...@@ -188,9 +190,9 @@ class TestSandboxedWebserver(ZopeTestCase.Sandboxed, TestWebserver): ...@@ -188,9 +190,9 @@ class TestSandboxedWebserver(ZopeTestCase.Sandboxed, TestWebserver):
# Additionally, it allows us to commit transactions without # Additionally, it allows us to commit transactions without
# harming the test ZODB. # harming the test ZODB.
self.folder.foo = 1 self.folder.foo = 1
get_transaction().commit() transaction.commit()
self.folder.foo = 2 self.folder.foo = 2
get_transaction().commit() transaction.commit()
def test_suite(): def test_suite():
......
...@@ -25,6 +25,8 @@ if __name__ == '__main__': ...@@ -25,6 +25,8 @@ if __name__ == '__main__':
from Testing import ZopeTestCase from Testing import ZopeTestCase
import transaction
from AccessControl.Permissions import add_documents_images_and_files from AccessControl.Permissions import add_documents_images_and_files
from AccessControl.Permissions import delete_objects from AccessControl.Permissions import delete_objects
import tempfile import tempfile
...@@ -40,7 +42,7 @@ class TestCopyPaste(ZopeTestCase.ZopeTestCase): ...@@ -40,7 +42,7 @@ class TestCopyPaste(ZopeTestCase.ZopeTestCase):
self.folder.addDTMLMethod('doc', file='foo') self.folder.addDTMLMethod('doc', file='foo')
# _p_oids are None until we commit a subtransaction # _p_oids are None until we commit a subtransaction
self.assertEqual(self.folder._p_oid, None) self.assertEqual(self.folder._p_oid, None)
get_transaction().commit(1) transaction.commit(1)
self.failIfEqual(self.folder._p_oid, None) self.failIfEqual(self.folder._p_oid, None)
def testCutPaste(self): def testCutPaste(self):
...@@ -91,7 +93,7 @@ class TestImportExport(ZopeTestCase.ZopeTestCase): ...@@ -91,7 +93,7 @@ class TestImportExport(ZopeTestCase.ZopeTestCase):
self.folder.addDTMLMethod('doc', file='foo') self.folder.addDTMLMethod('doc', file='foo')
# _p_oids are None until we commit a subtransaction # _p_oids are None until we commit a subtransaction
self.assertEqual(self.folder._p_oid, None) self.assertEqual(self.folder._p_oid, None)
get_transaction().commit(1) transaction.commit(1)
self.failIfEqual(self.folder._p_oid, None) self.failIfEqual(self.folder._p_oid, None)
def testExport(self): def testExport(self):
...@@ -169,7 +171,7 @@ class DummyObject(SimpleItem): ...@@ -169,7 +171,7 @@ class DummyObject(SimpleItem):
app = ZopeTestCase.app() app = ZopeTestCase.app()
app._setObject('dummy1', DummyObject()) app._setObject('dummy1', DummyObject())
app._setObject('dummy2', DummyObject()) app._setObject('dummy2', DummyObject())
get_transaction().commit() transaction.commit()
ZopeTestCase.close(app) ZopeTestCase.close(app)
...@@ -306,45 +308,45 @@ class TestTransactionAbort(ZopeTestCase.ZopeTestCase): ...@@ -306,45 +308,45 @@ class TestTransactionAbort(ZopeTestCase.ZopeTestCase):
def testTransactionAbort(self): def testTransactionAbort(self):
self.folder.foo = 1 self.folder.foo = 1
self.failUnless(hasattr(self.folder, 'foo')) self.failUnless(hasattr(self.folder, 'foo'))
get_transaction().abort() transaction.abort()
# The foo attribute is still present # The foo attribute is still present
self.failUnless(hasattr(self.folder, 'foo')) self.failUnless(hasattr(self.folder, 'foo'))
def testSubTransactionAbort(self): def testSubTransactionAbort(self):
self.folder.foo = 1 self.folder.foo = 1
self.failUnless(hasattr(self.folder, 'foo')) self.failUnless(hasattr(self.folder, 'foo'))
get_transaction().commit(1) transaction.commit(1)
get_transaction().abort() transaction.abort()
# This time the abort nukes the foo attribute... # This time the abort nukes the foo attribute...
self.failIf(hasattr(self.folder, 'foo')) self.failIf(hasattr(self.folder, 'foo'))
def testTransactionAbortPersistent(self): def testTransactionAbortPersistent(self):
self.folder._p_foo = 1 self.folder._p_foo = 1
self.failUnless(hasattr(self.folder, '_p_foo')) self.failUnless(hasattr(self.folder, '_p_foo'))
get_transaction().abort() transaction.abort()
# The _p_foo attribute is still present # The _p_foo attribute is still present
self.failUnless(hasattr(self.folder, '_p_foo')) self.failUnless(hasattr(self.folder, '_p_foo'))
def testSubTransactionAbortPersistent(self): def testSubTransactionAbortPersistent(self):
self.folder._p_foo = 1 self.folder._p_foo = 1
self.failUnless(hasattr(self.folder, '_p_foo')) self.failUnless(hasattr(self.folder, '_p_foo'))
get_transaction().commit(1) transaction.commit(1)
get_transaction().abort() transaction.abort()
# This time the abort nukes the _p_foo attribute... # This time the abort nukes the _p_foo attribute...
self.failIf(hasattr(self.folder, '_p_foo')) self.failIf(hasattr(self.folder, '_p_foo'))
def testTransactionAbortVolatile(self): def testTransactionAbortVolatile(self):
self.folder._v_foo = 1 self.folder._v_foo = 1
self.failUnless(hasattr(self.folder, '_v_foo')) self.failUnless(hasattr(self.folder, '_v_foo'))
get_transaction().abort() transaction.abort()
# The _v_foo attribute is still present # The _v_foo attribute is still present
self.failUnless(hasattr(self.folder, '_v_foo')) self.failUnless(hasattr(self.folder, '_v_foo'))
def testSubTransactionAbortVolatile(self): def testSubTransactionAbortVolatile(self):
self.folder._v_foo = 1 self.folder._v_foo = 1
self.failUnless(hasattr(self.folder, '_v_foo')) self.failUnless(hasattr(self.folder, '_v_foo'))
get_transaction().commit(1) transaction.commit(1)
get_transaction().abort() transaction.abort()
# This time the abort nukes the _v_foo attribute... # This time the abort nukes the _v_foo attribute...
self.failIf(hasattr(self.folder, '_v_foo')) self.failIf(hasattr(self.folder, '_v_foo'))
......
...@@ -18,6 +18,8 @@ module level to add functionality to the test environment. ...@@ -18,6 +18,8 @@ module level to add functionality to the test environment.
$Id: utils.py,v 1.21 2005/02/11 09:00:21 shh42 Exp $ $Id: utils.py,v 1.21 2005/02/11 09:00:21 shh42 Exp $
""" """
import transaction
def setupCoreSessions(app=None): def setupCoreSessions(app=None):
'''Sets up the session_data_manager e.a.''' '''Sets up the session_data_manager e.a.'''
from Acquisition import aq_base from Acquisition import aq_base
...@@ -57,7 +59,8 @@ def setupCoreSessions(app=None): ...@@ -57,7 +59,8 @@ def setupCoreSessions(app=None):
app._setObject('session_data_manager', sdm) app._setObject('session_data_manager', sdm)
commit = 1 commit = 1
if commit: get_transaction().commit() if commit:
transaction.commit()
def setupZGlobals(app=None): def setupZGlobals(app=None):
...@@ -69,7 +72,7 @@ def setupZGlobals(app=None): ...@@ -69,7 +72,7 @@ def setupZGlobals(app=None):
if not root.has_key('ZGlobals'): if not root.has_key('ZGlobals'):
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
root['ZGlobals'] = OOBTree() root['ZGlobals'] = OOBTree()
get_transaction().commit() transaction.commit()
def setupSiteErrorLog(app=None): def setupSiteErrorLog(app=None):
...@@ -84,7 +87,7 @@ def setupSiteErrorLog(app=None): ...@@ -84,7 +87,7 @@ def setupSiteErrorLog(app=None):
pass pass
else: else:
app._setObject('error_log', SiteErrorLog()) app._setObject('error_log', SiteErrorLog())
get_transaction().commit() transaction.commit()
import os, time import os, time
...@@ -95,7 +98,7 @@ def importObjectFromFile(container, filename, quiet=0): ...@@ -95,7 +98,7 @@ def importObjectFromFile(container, filename, quiet=0):
start = time.time() start = time.time()
if not quiet: _print("Importing %s ... " % os.path.basename(filename)) if not quiet: _print("Importing %s ... " % os.path.basename(filename))
container._importObjectFromFile(filename, verify=0) container._importObjectFromFile(filename, verify=0)
get_transaction().commit() transaction.commit()
if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) if not quiet: _print('done (%.3fs)\n' % (time.time() - start))
......
...@@ -17,6 +17,7 @@ $Id: functional.py,v 1.2 2005/03/26 18:07:08 shh42 Exp $ ...@@ -17,6 +17,7 @@ $Id: functional.py,v 1.2 2005/03/26 18:07:08 shh42 Exp $
import sys, re, base64 import sys, re, base64
import warnings import warnings
import transaction
from zope.testing import doctest from zope.testing import doctest
...@@ -126,7 +127,7 @@ def http(request_string, handle_errors=True): ...@@ -126,7 +127,7 @@ def http(request_string, handle_errors=True):
old_sm = getSecurityManager() old_sm = getSecurityManager()
# Commit work done by previous python code. # Commit work done by previous python code.
get_transaction().commit() transaction.commit()
# Discard leading white space to make call layout simpler # Discard leading white space to make call layout simpler
request_string = request_string.lstrip() request_string = request_string.lstrip()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment