Commit 6ec521d6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove duplicate check methods, add getFakeConnection() to base test class and

use it in some tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@544 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 5e061ed5
...@@ -149,28 +149,7 @@ class ClientApplicationTest(NeoTestBase): ...@@ -149,28 +149,7 @@ class ClientApplicationTest(NeoTestBase):
def checkDispatcherRegisterCalled(self, app, conn): def checkDispatcherRegisterCalled(self, app, conn):
calls = app.dispatcher.mockGetNamedCalls('register') calls = app.dispatcher.mockGetNamedCalls('register')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
self.assertTrue(calls[0].getParam(0) is conn) calls[0].checkArgs(conn, None, app.local_var.queue)
self.assertEquals(calls[0].getParam(2), app.local_var.queue)
def checkPacketSent(self, conn, packet_type, method='_addPacket'):
calls = conn.mockGetNamedCalls(method)
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet._type, packet_type)
def checkAsk(self, conn, packet_type):
self.checkPacketSent(conn, packet_type, 'ask')
def checkNotify(self, conn, packet_type):
self.checkPacketSent(conn, packet_type, 'notify')
def checkNoPacketSent(self, conn):
self.assertEquals(len(conn.mockGetNamedCalls('notify')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('answer')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('ask')), 0)
# tests
def test_getQueue(self): def test_getQueue(self):
app = self.getApp() app = self.getApp()
...@@ -568,9 +547,9 @@ class ClientApplicationTest(NeoTestBase): ...@@ -568,9 +547,9 @@ class ClientApplicationTest(NeoTestBase):
app.local_var.data_dict = {oid1: '', oid2: ''} app.local_var.data_dict = {oid1: '', oid2: ''}
app.tpc_abort(txn) app.tpc_abort(txn)
# will check if there was just one call/packet : # will check if there was just one call/packet :
self.checkNotify(conn1, ABORT_TRANSACTION) self.checkNotifyPacket(conn1, ABORT_TRANSACTION)
self.checkNotify(conn2, ABORT_TRANSACTION) self.checkNotifyPacket(conn2, ABORT_TRANSACTION)
self.checkNotify(app.master_conn, ABORT_TRANSACTION) self.checkNotifyPacket(app.master_conn, ABORT_TRANSACTION)
self.assertEquals(app.local_var.tid, None) self.assertEquals(app.local_var.tid, None)
self.assertEquals(app.local_var.txn, None) self.assertEquals(app.local_var.txn, None)
self.assertEquals(app.local_var.data_dict, {}) self.assertEquals(app.local_var.data_dict, {})
......
...@@ -566,12 +566,8 @@ class ClientEventHandlerTest(NeoTestBase): ...@@ -566,12 +566,8 @@ class ClientEventHandlerTest(NeoTestBase):
# Check that partition table cell got added # Check that partition table cell got added
setCell_call_list = app.pt.mockGetNamedCalls('setCell') setCell_call_list = app.pt.mockGetNamedCalls('setCell')
self.assertEquals(len(setCell_call_list), 1) self.assertEquals(len(setCell_call_list), 1)
offset = setCell_call_list[0].getParam(0) setCell_call_list[0].checkArgs(test_row_list[0][0], created_node,
node = setCell_call_list[0].getParam(1) test_row_list[0][1][0][1])
state = setCell_call_list[0].getParam(2)
self.assertEqual(offset, test_row_list[0][0])
self.assertTrue(node is created_node)
self.assertEqual(state, test_row_list[0][1][0][1])
def test_knownNodeSendPartitionTable(self): def test_knownNodeSendPartitionTable(self):
test_node = Mock({'getNodeType': MASTER_NODE_TYPE}) test_node = Mock({'getNodeType': MASTER_NODE_TYPE})
...@@ -592,12 +588,8 @@ class ClientEventHandlerTest(NeoTestBase): ...@@ -592,12 +588,8 @@ class ClientEventHandlerTest(NeoTestBase):
# Check that partition table cell got added # Check that partition table cell got added
setCell_call_list = app.pt.mockGetNamedCalls('setCell') setCell_call_list = app.pt.mockGetNamedCalls('setCell')
self.assertEquals(len(setCell_call_list), 1) self.assertEquals(len(setCell_call_list), 1)
offset = setCell_call_list[0].getParam(0) setCell_call_list[0].checkArgs(test_row_list[0][0], test_node,
node = setCell_call_list[0].getParam(1) test_row_list[0][1][0][1])
state = setCell_call_list[0].getParam(2)
self.assertEqual(offset, test_row_list[0][0])
self.assertTrue(node is test_node)
self.assertEqual(state, test_row_list[0][1][0][1])
def test_initialNotifyNodeInformation(self): def test_initialNotifyNodeInformation(self):
client_handler = PrimaryBoostrapEventHandler(None, self.getDispatcher()) client_handler = PrimaryBoostrapEventHandler(None, self.getDispatcher())
...@@ -811,13 +803,8 @@ class ClientEventHandlerTest(NeoTestBase): ...@@ -811,13 +803,8 @@ class ClientEventHandlerTest(NeoTestBase):
# Check that partition got updated # Check that partition got updated
self.assertEqual(app.ptid, test_ptid + 1) self.assertEqual(app.ptid, test_ptid + 1)
setCell_call_list = app.pt.mockGetNamedCalls('setCell') setCell_call_list = app.pt.mockGetNamedCalls('setCell')
self.assertEqual(len(setCell_call_list), 1) setCell_call_list[0].checkArgs(test_cell_list[0][0], added_node,
offset = setCell_call_list[0].getParam(0) test_cell_list[0][2])
node = setCell_call_list[0].getParam(1)
state = setCell_call_list[0].getParam(2)
self.assertEqual(offset, test_cell_list[0][0])
self.assertTrue(node is added_node)
self.assertEqual(state, test_cell_list[0][2])
# TODO: confirm condition under which an unknown node should be added with a TEMPORARILY_DOWN_STATE (implementation is unclear) # TODO: confirm condition under which an unknown node should be added with a TEMPORARILY_DOWN_STATE (implementation is unclear)
......
...@@ -39,6 +39,12 @@ class NeoTestBase(unittest.TestCase): ...@@ -39,6 +39,12 @@ class NeoTestBase(unittest.TestCase):
return min(ptids), max(ptids) return min(ptids), max(ptids)
ptid = min(ptids) ptid = min(ptids)
def getFakeConnection(self, uuid=None, address=('127.0.0.1', 10000)):
return Mock({
'getUUID': uuid,
'getAddress': address,
})
def checkProtocolErrorRaised(self, method, *args, **kwargs): def checkProtocolErrorRaised(self, method, *args, **kwargs):
""" Check if the ProtocolError exception was raised """ """ Check if the ProtocolError exception was raised """
self.assertRaises(protocol.ProtocolError, method, *args, **kwargs) self.assertRaises(protocol.ProtocolError, method, *args, **kwargs)
...@@ -194,6 +200,9 @@ class NeoTestBase(unittest.TestCase): ...@@ -194,6 +200,9 @@ class NeoTestBase(unittest.TestCase):
def checkAskNewTid(self, conn, **kw): def checkAskNewTid(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_NEW_TID, **kw) return self.checkAskPacket(conn, protocol.ASK_NEW_TID, **kw)
def checkAskLastIDs(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_LAST_IDS, **kw)
def checkAcceptNodeIdentification(self, conn, **kw): def checkAcceptNodeIdentification(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ACCEPT_NODE_IDENTIFICATION, **kw) return self.checkAnswerPacket(conn, protocol.ACCEPT_NODE_IDENTIFICATION, **kw)
......
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