Commit ae9a146d authored by Grégory Wisniewski's avatar Grégory Wisniewski

Use realistic values in tests.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2199 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 4b96a7b5
...@@ -80,7 +80,8 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -80,7 +80,8 @@ class StorageClientHandlerTests(NeoTestBase):
def test_18_askTransactionInformation2(self): def test_18_askTransactionInformation2(self):
# answer # answer
conn = self._getConnection() conn = self._getConnection()
dm = Mock({ "getTransaction": (INVALID_TID, 'user', 'desc', '', False), }) oid_list = [self.getOID(1), self.getOID(2)]
dm = Mock({ "getTransaction": (oid_list, 'user', 'desc', '', False), })
self.app.dm = dm self.app.dm = dm
self.operation.askTransactionInformation(conn, INVALID_TID) self.operation.askTransactionInformation(conn, INVALID_TID)
self.checkAnswerTransactionInformation(conn) self.checkAnswerTransactionInformation(conn)
...@@ -113,11 +114,14 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -113,11 +114,14 @@ class StorageClientHandlerTests(NeoTestBase):
def test_24_askObject3(self): def test_24_askObject3(self):
# object found => answer # object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', None)}) serial = self.getNextTID()
next_serial = self.getNextTID()
oid = self.getOID(1)
tid = self.getNextTID()
self.app.dm = Mock({'getObject': (serial, next_serial, 0, 0, '', None)})
conn = self._getConnection() conn = self._getConnection()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID, self.operation.askObject(conn, oid=oid, serial=serial, tid=tid)
serial=INVALID_SERIAL, tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn) self.checkAnswerObject(conn)
...@@ -169,15 +173,17 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -169,15 +173,17 @@ class StorageClientHandlerTests(NeoTestBase):
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_askObjectHistory2(self): def test_26_askObjectHistory2(self):
oid1, oid2 = self.getOID(1), self.getOID(2)
# first case: empty history # first case: empty history
conn = self._getConnection() conn = self._getConnection()
self.app.dm = Mock({'getObjectHistory': None}) self.app.dm = Mock({'getObjectHistory': None})
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, oid1, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
# second case: not empty history # second case: not empty history
conn = self._getConnection() conn = self._getConnection()
self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]}) serial = self.getNextTID()
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2) self.app.dm = Mock({'getObjectHistory': [(serial, 0, ), ]})
self.operation.askObjectHistory(conn, oid2, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
def test_askStoreTransaction(self): def test_askStoreTransaction(self):
......
...@@ -63,20 +63,24 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -63,20 +63,24 @@ class StorageStorageHandlerTests(NeoTestBase):
def test_18_askTransactionInformation2(self): def test_18_askTransactionInformation2(self):
# answer # answer
conn = self.getFakeConnection() conn = self.getFakeConnection()
dm = Mock({"getTransaction": (INVALID_TID, 'user', 'desc', '', False), }) tid = self.getNextTID()
oid_list = [self.getOID(1), self.getOID(2)]
dm = Mock({"getTransaction": (oid_list, 'user', 'desc', '', False), })
self.app.dm = dm self.app.dm = dm
self.operation.askTransactionInformation(conn, INVALID_TID) self.operation.askTransactionInformation(conn, tid)
self.checkAnswerTransactionInformation(conn) self.checkAnswerTransactionInformation(conn)
def test_24_askObject1(self): def test_24_askObject1(self):
# delayed response # delayed response
conn = self.getFakeConnection() conn = self.getFakeConnection()
oid = self.getOID(1)
tid = self.getNextTID()
serial = self.getNextTID()
self.app.dm = Mock() self.app.dm = Mock()
self.app.tm = Mock({'loadLocked': True}) self.app.tm = Mock({'loadLocked': True})
self.app.load_lock_dict[INVALID_OID] = object() self.app.load_lock_dict[oid] = object()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID, self.operation.askObject(conn, oid=oid, serial=serial, tid=tid)
serial=INVALID_SERIAL, tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 1) self.assertEquals(len(self.app.event_queue), 1)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
self.assertEquals(len(self.app.dm.mockGetNamedCalls('getObject')), 0) self.assertEquals(len(self.app.dm.mockGetNamedCalls('getObject')), 0)
...@@ -85,23 +89,27 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -85,23 +89,27 @@ class StorageStorageHandlerTests(NeoTestBase):
# invalid serial / tid / packet not found # invalid serial / tid / packet not found
self.app.dm = Mock({'getObject': None}) self.app.dm = Mock({'getObject': None})
conn = self.getFakeConnection() conn = self.getFakeConnection()
oid = self.getOID(1)
tid = self.getNextTID()
serial = self.getNextTID()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID, self.operation.askObject(conn, oid=oid, serial=serial, tid=tid)
serial=INVALID_SERIAL, tid=INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('getObject') calls = self.app.dm.mockGetNamedCalls('getObject')
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
calls[0].checkArgs(INVALID_OID, INVALID_TID, INVALID_TID, calls[0].checkArgs(oid, serial, tid, resolve_data=False)
resolve_data=False)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
def test_24_askObject3(self): def test_24_askObject3(self):
oid = self.getOID(1)
tid = self.getNextTID()
serial = self.getNextTID()
next_serial = self.getNextTID()
# object found => answer # object found => answer
self.app.dm = Mock({'getObject': ('', '', 0, 0, '', None)}) self.app.dm = Mock({'getObject': (serial, next_serial, 0, 0, '', None)})
conn = self.getFakeConnection() conn = self.getFakeConnection()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID, self.operation.askObject(conn, oid=oid, serial=serial, tid=tid)
serial=INVALID_SERIAL, tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn) self.checkAnswerObject(conn)
...@@ -153,15 +161,18 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -153,15 +161,18 @@ class StorageStorageHandlerTests(NeoTestBase):
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0) self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_askObjectHistory2(self): def test_26_askObjectHistory2(self):
oid1 = self.getOID(1)
oid2 = self.getOID(2)
tid = self.getNextTID()
# first case: empty history # first case: empty history
conn = self.getFakeConnection() conn = self.getFakeConnection()
self.app.dm = Mock({'getObjectHistory': None}) self.app.dm = Mock({'getObjectHistory': None})
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, oid1, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
# second case: not empty history # second case: not empty history
conn = self.getFakeConnection() conn = self.getFakeConnection()
self.app.dm = Mock({'getObjectHistory': [('', 0, ), ]}) self.app.dm = Mock({'getObjectHistory': [(tid, 0, ), ]})
self.operation.askObjectHistory(conn, INVALID_OID, 1, 2) self.operation.askObjectHistory(conn, oid2, 1, 2)
self.checkAnswerObjectHistory(conn) self.checkAnswerObjectHistory(conn)
def test_25_askOIDs1(self): def test_25_askOIDs1(self):
......
...@@ -80,8 +80,8 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -80,8 +80,8 @@ class StorageVerificationHandlerTests(NeoTestBase):
def test_07_askLastIDs(self): def test_07_askLastIDs(self):
conn = self.getClientConnection() conn = self.getClientConnection()
last_ptid = '\x01' * 8 last_ptid = self.getPTID(1)
last_oid = '\x02' * 8 last_oid = self.getOID(2)
self.app.pt = Mock({'getID': last_ptid}) self.app.pt = Mock({'getID': last_ptid})
self.verification.askLastIDs(conn) self.verification.askLastIDs(conn)
oid, tid, ptid = self.checkAnswerLastIDs(conn, decode=True) oid, tid, ptid = self.checkAnswerLastIDs(conn, decode=True)
......
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