"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/App/tests/test_ApplicationManager.py" between
Zope-5.1.2.tar.gz and Zope-5.2.tar.gz

About: Zope Z Object Publishing Environment - web application platform used for building content management systems, intranets, portals, and custom applications.

test_ApplicationManager.py  (Zope-5.1.2):test_ApplicationManager.py  (Zope-5.2)
import os import os
import shutil import shutil
import sys import sys
import tempfile import tempfile
import time import time
import unittest import unittest
import Testing.testbrowser import Testing.testbrowser
import Testing.ZopeTestCase import Testing.ZopeTestCase
class DummyForm:
def __call__(self, *args, **kw):
return kw
class DummyConnection: class DummyConnection:
def __init__(self, db): def __init__(self, db):
self.__db = db self.__db = db
def db(self): def db(self):
return self.__db return self.__db
class DummyDBTab: class DummyDBTab:
def __init__(self, databases=None): def __init__(self, databases=None):
skipping to change at line 53 skipping to change at line 58
def getSize(self): def getSize(self):
return self._size return self._size
def getCacheSize(self): def getCacheSize(self):
return self._cache_size return self._cache_size
def pack(self, when): def pack(self, when):
self._packed = when self._packed = when
def undoInfo(self, first_transaction, last_transaction):
return [{'time': 1,
'description': 'Transaction 1',
'id': b'id1'}]
def undoMultiple(self, tids):
class DummyTransaction:
def __init__(self, raises=False):
self.raises = raises
self.aborted = False
def note(self, note):
self._note = note
def commit(self):
if self.raises:
raise RuntimeError('This did not work')
def abort(self):
self.aborted = True
class DummyTransactionModule:
def __init__(self, raises=False):
self.ts = DummyTransaction(raises=raises)
def get(self):
return self.ts
class ConfigTestBase: class ConfigTestBase:
def setUp(self): def setUp(self):
super().setUp() super().setUp()
import App.config import App.config
self._old_config = App.config._config self._old_config = App.config._config
def tearDown(self): def tearDown(self):
import App.config import App.config
App.config._config = self._old_config App.config._config = self._old_config
skipping to change at line 360 skipping to change at line 397
self.assertAlmostEqual(am._getDB()._packed, pack_to, delta=1) self.assertAlmostEqual(am._getDB()._packed, pack_to, delta=1)
self.assertAlmostEqual(packed_to, pack_to, delta=1) self.assertAlmostEqual(packed_to, pack_to, delta=1)
# Set the dummy storage pack indicator manually # Set the dummy storage pack indicator manually
am._getDB()._packed = None am._getDB()._packed = None
# Pass an invalid value # Pass an invalid value
self.assertIsNone(am.manage_pack(days='foo')) self.assertIsNone(am.manage_pack(days='foo'))
# The dummy storage value should not change because pack was not called # The dummy storage value should not change because pack was not called
self.assertIsNone(am._getDB()._packed) self.assertIsNone(am._getDB()._packed)
def test_manage_undoTransactions_raises(self):
# Patch in fake transaction module that will raise RuntimeError
# on transaction commit
import App.Undo
trs_module = App.Undo.transaction
App.Undo.transaction = DummyTransactionModule(raises=True)
am = self._makeOne()
am._p_jar = self._makeJar('foo', '')
am.manage_UndoForm = DummyForm()
undoable_tids = [x['id'] for x in am.undoable_transactions()]
current_transaction = App.Undo.transaction.get()
# If no REQUEST is passed in, the exception is re-raised unchanged
# and the current transaction is left unchanged.
# If a REQUEST is passed in, the transaction will be aborted and
# the exception is caught. The DummyForm instance shows the
# call arguments so the exception data is visible.
res = am.manage_undo_transactions(transaction_info=undoable_tids,
expected = {
'manage_tabs_message': 'RuntimeError: This did not work',
'manage_tabs_type': 'danger'}
self.assertDictEqual(res, expected)
# Cleanup
App.Undo.transaction = trs_module
class DebugManagerTests(unittest.TestCase): class DebugManagerTests(unittest.TestCase):
def setUp(self): def setUp(self):
import sys import sys
self._sys = sys self._sys = sys
self._old_sys_modules = sys.modules.copy() self._old_sys_modules = sys.modules.copy()
def tearDown(self): def tearDown(self):
self._sys.modules.clear() self._sys.modules.clear()
self._sys.modules.update(self._old_sys_modules) self._sys.modules.update(self._old_sys_modules)
 End of changes. 3 change blocks. 
0 lines changed or deleted 73 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)