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