Commit 32c773ec authored by Vincent Pelletier's avatar Vincent Pelletier

Add a getter for App's db so it can be tested.

Update handler to use this accessor.
Update handler test to follow API change.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@356 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 04c84a2e
......@@ -281,6 +281,9 @@ class Application(object):
def registerDB(self, db, limit):
self._db = db
def getDB(self):
return self._db
def new_oid(self):
"""Get a new OID."""
self._oid_lock_acquire()
......
......@@ -297,8 +297,9 @@ class ClientEventHandler(BaseClientEventHandler):
del app.mq_cache[oid]
except KeyError:
pass
if app._db is not None:
app._db.invalidate(tid, oids)
db = app.getDB()
if db is not None:
db.invalidate(tid, oids)
finally:
app._cache_lock_release()
......
......@@ -864,7 +864,12 @@ class ClientEventHandlerTest(unittest.TestCase):
def _cache_lock_release(self):
pass
_db = Mock({'invalidate': None})
def registerDB(self, db, limit):
self.db = db
def getDB(self):
return self.db
mq_cache = Mock({'__delitem__': None})
app = App()
dispatcher = self.getDispatcher()
......@@ -872,9 +877,13 @@ class ClientEventHandlerTest(unittest.TestCase):
conn = self.getConnection()
test_tid = 1
test_oid_list = ['\x00\x00\x00\x00\x00\x00\x00\x01', '\x00\x00\x00\x00\x00\x00\x00\x02']
test_db = Mock({'invalidate': None})
app.registerDB(test_db, None)
client_handler.handleInvalidateObjects(conn, None, test_oid_list[:], test_tid)
# 'invalidate' is called just once
invalidate_call_list = app._db.mockGetNamedCalls('invalidate')
db = app.getDB()
self.assertTrue(db is test_db)
invalidate_call_list = db.mockGetNamedCalls('invalidate')
self.assertEquals(len(invalidate_call_list), 1)
invalidate_call = invalidate_call_list[0]
invalidate_tid = invalidate_call.getParam(0)
......
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