Commit bfd3fe2f authored by Vincent Pelletier's avatar Vincent Pelletier

Drop unneeded glue.

sed is your friend.
Also, factorise setUp definition.
Also, use "super" to call methods on superclasses.
parent 6be12fff
...@@ -25,16 +25,17 @@ from neo.client.handlers.master import PrimaryNotificationsHandler, \ ...@@ -25,16 +25,17 @@ from neo.client.handlers.master import PrimaryNotificationsHandler, \
from neo.client.exception import NEOStorageError from neo.client.exception import NEOStorageError
class MasterHandlerTests(NeoUnitTestBase): class MasterHandlerTests(NeoUnitTestBase):
def setUp(self):
def getConnection(self): super(MasterHandlerTests, self).setUp()
return self.getFakeConnection() self.db = Mock()
self.app = Mock({'getDB': self.db})
self.app.nm = Mock()
self.app.dispatcher = Mock()
class MasterBootstrapHandlerTests(MasterHandlerTests): class MasterBootstrapHandlerTests(MasterHandlerTests):
def setUp(self): def setUp(self):
NeoUnitTestBase.setUp(self) super(MasterBootstrapHandlerTests, self).setUp()
self.app = Mock()
self.handler = PrimaryBootstrapHandler(self.app) self.handler = PrimaryBootstrapHandler(self.app)
def checkCalledOnApp(self, method, index=0): def checkCalledOnApp(self, method, index=0):
...@@ -43,13 +44,13 @@ class MasterBootstrapHandlerTests(MasterHandlerTests): ...@@ -43,13 +44,13 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
return calls[index].params return calls[index].params
def test_notReady(self): def test_notReady(self):
conn = self.getConnection() conn = self.getFakeConnection()
self.handler.notReady(conn, 'message') self.handler.notReady(conn, 'message')
self.assertEqual(self.app.trying_master_node, None) self.assertEqual(self.app.trying_master_node, None)
def test_acceptIdentification1(self): def test_acceptIdentification1(self):
""" Non-master node """ """ Non-master node """
conn = self.getConnection() conn = self.getFakeConnection()
uuid = self.getNewUUID() uuid = self.getNewUUID()
self.handler.acceptIdentification(conn, NodeTypes.CLIENT, self.handler.acceptIdentification(conn, NodeTypes.CLIENT,
uuid, 100, 0, None, None, []) uuid, 100, 0, None, None, [])
...@@ -57,7 +58,7 @@ class MasterBootstrapHandlerTests(MasterHandlerTests): ...@@ -57,7 +58,7 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
def test_acceptIdentification2(self): def test_acceptIdentification2(self):
""" No UUID supplied """ """ No UUID supplied """
conn = self.getConnection() conn = self.getFakeConnection()
uuid = self.getNewUUID() uuid = self.getNewUUID()
node = Mock() node = Mock()
self.app.nm = Mock({'getByAddress': node, 'getByUUID': node}) self.app.nm = Mock({'getByAddress': node, 'getByUUID': node})
...@@ -69,7 +70,7 @@ class MasterBootstrapHandlerTests(MasterHandlerTests): ...@@ -69,7 +70,7 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
def test_acceptIdentification3(self): def test_acceptIdentification3(self):
""" identification accepted """ """ identification accepted """
node = Mock() node = Mock()
conn = self.getConnection() conn = self.getFakeConnection()
uuid = self.getNewUUID() uuid = self.getNewUUID()
your_uuid = self.getNewUUID() your_uuid = self.getNewUUID()
partitions = 100 partitions = 100
...@@ -90,7 +91,7 @@ class MasterBootstrapHandlerTests(MasterHandlerTests): ...@@ -90,7 +91,7 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
return master_list return master_list
def test_answerPartitionTable(self): def test_answerPartitionTable(self):
conn = self.getConnection() conn = self.getFakeConnection()
self.app.pt = Mock() self.app.pt = Mock()
ptid = 0 ptid = 0
row_list = ([], []) row_list = ([], [])
...@@ -103,15 +104,11 @@ class MasterBootstrapHandlerTests(MasterHandlerTests): ...@@ -103,15 +104,11 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
class MasterNotificationsHandlerTests(MasterHandlerTests): class MasterNotificationsHandlerTests(MasterHandlerTests):
def setUp(self): def setUp(self):
NeoUnitTestBase.setUp(self) super(MasterNotificationsHandlerTests, self).setUp()
self.db = Mock()
self.app = Mock({'getDB': self.db})
self.app.nm = Mock()
self.app.dispatcher = Mock()
self.handler = PrimaryNotificationsHandler(self.app) self.handler = PrimaryNotificationsHandler(self.app)
def test_connectionClosed(self): def test_connectionClosed(self):
conn = self.getConnection() conn = self.getFakeConnection()
node = Mock() node = Mock()
self.app.master_conn = conn self.app.master_conn = conn
self.app.primary_master_node = node self.app.primary_master_node = node
...@@ -120,7 +117,7 @@ class MasterNotificationsHandlerTests(MasterHandlerTests): ...@@ -120,7 +117,7 @@ class MasterNotificationsHandlerTests(MasterHandlerTests):
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
def test_invalidateObjects(self): def test_invalidateObjects(self):
conn = self.getConnection() conn = self.getFakeConnection()
tid = self.getNextTID() tid = self.getNextTID()
oid1, oid2, oid3 = self.getOID(1), self.getOID(2), self.getOID(3) oid1, oid2, oid3 = self.getOID(1), self.getOID(2), self.getOID(3)
self.app._cache = Mock({ self.app._cache = Mock({
...@@ -136,7 +133,7 @@ class MasterNotificationsHandlerTests(MasterHandlerTests): ...@@ -136,7 +133,7 @@ class MasterNotificationsHandlerTests(MasterHandlerTests):
invalidation_calls[0].checkArgs(tid, [oid1, oid3]) invalidation_calls[0].checkArgs(tid, [oid1, oid3])
def test_notifyPartitionChanges(self): def test_notifyPartitionChanges(self):
conn = self.getConnection() conn = self.getFakeConnection()
self.app.pt = Mock({'filled': True}) self.app.pt = Mock({'filled': True})
ptid = 0 ptid = 0
cell_list = (Mock(), Mock()) cell_list = (Mock(), Mock())
...@@ -149,26 +146,25 @@ class MasterNotificationsHandlerTests(MasterHandlerTests): ...@@ -149,26 +146,25 @@ class MasterNotificationsHandlerTests(MasterHandlerTests):
class MasterAnswersHandlerTests(MasterHandlerTests): class MasterAnswersHandlerTests(MasterHandlerTests):
def setUp(self): def setUp(self):
NeoUnitTestBase.setUp(self) super(MasterAnswersHandlerTests, self).setUp()
self.app = Mock()
self.handler = PrimaryAnswersHandler(self.app) self.handler = PrimaryAnswersHandler(self.app)
def test_answerBeginTransaction(self): def test_answerBeginTransaction(self):
tid = self.getNextTID() tid = self.getNextTID()
conn = self.getConnection() conn = self.getFakeConnection()
self.handler.answerBeginTransaction(conn, tid) self.handler.answerBeginTransaction(conn, tid)
calls = self.app.mockGetNamedCalls('setHandlerData') calls = self.app.mockGetNamedCalls('setHandlerData')
self.assertEqual(len(calls), 1) self.assertEqual(len(calls), 1)
calls[0].checkArgs(tid) calls[0].checkArgs(tid)
def test_answerNewOIDs(self): def test_answerNewOIDs(self):
conn = self.getConnection() conn = self.getFakeConnection()
oid1, oid2, oid3 = self.getOID(0), self.getOID(1), self.getOID(2) oid1, oid2, oid3 = self.getOID(0), self.getOID(1), self.getOID(2)
self.handler.answerNewOIDs(conn, [oid1, oid2, oid3]) self.handler.answerNewOIDs(conn, [oid1, oid2, oid3])
self.assertEqual(self.app.new_oid_list, [oid1, oid2, oid3]) self.assertEqual(self.app.new_oid_list, [oid1, oid2, oid3])
def test_answerTransactionFinished(self): def test_answerTransactionFinished(self):
conn = self.getConnection() conn = self.getFakeConnection()
ttid2 = self.getNextTID() ttid2 = self.getNextTID()
tid2 = self.getNextTID() tid2 = self.getNextTID()
self.handler.answerTransactionFinished(conn, ttid2, tid2) self.handler.answerTransactionFinished(conn, ttid2, tid2)
......
...@@ -31,22 +31,19 @@ MARKER = [] ...@@ -31,22 +31,19 @@ MARKER = []
class StorageBootstrapHandlerTests(NeoUnitTestBase): class StorageBootstrapHandlerTests(NeoUnitTestBase):
def setUp(self): def setUp(self):
NeoUnitTestBase.setUp(self) super(NeoUnitTestBase, self).setUp()
self.app = Mock() self.app = Mock()
self.handler = StorageBootstrapHandler(self.app) self.handler = StorageBootstrapHandler(self.app)
def getConnection(self):
return self.getFakeConnection()
def test_notReady(self): def test_notReady(self):
conn = self.getConnection() conn = self.getFakeConnection()
self.assertRaises(NodeNotReady, self.handler.notReady, conn, 'message') self.assertRaises(NodeNotReady, self.handler.notReady, conn, 'message')
def test_acceptIdentification1(self): def test_acceptIdentification1(self):
""" Not a storage node """ """ Not a storage node """
uuid = self.getNewUUID() uuid = self.getNewUUID()
node_uuid = self.getNewUUID() node_uuid = self.getNewUUID()
conn = self.getConnection() conn = self.getFakeConnection()
self.app.primary_master_node = node = Mock({'getUUID': node_uuid}) self.app.primary_master_node = node = Mock({'getUUID': node_uuid})
self.app.nm = Mock({'getByAddress': node}) self.app.nm = Mock({'getByAddress': node})
self.handler.acceptIdentification(conn, NodeTypes.CLIENT, uuid, self.handler.acceptIdentification(conn, NodeTypes.CLIENT, uuid,
...@@ -56,7 +53,7 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase): ...@@ -56,7 +53,7 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase):
def test_acceptIdentification2(self): def test_acceptIdentification2(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
node_uuid = self.getNewUUID() node_uuid = self.getNewUUID()
conn = self.getConnection() conn = self.getFakeConnection()
self.app.primary_master_node = node = Mock({'getConnection': conn, self.app.primary_master_node = node = Mock({'getConnection': conn,
'getUUID': node_uuid}) 'getUUID': node_uuid})
self.app.nm = Mock({'getByAddress': node}) self.app.nm = Mock({'getByAddress': node})
...@@ -68,20 +65,17 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase): ...@@ -68,20 +65,17 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase):
class StorageAnswerHandlerTests(NeoUnitTestBase): class StorageAnswerHandlerTests(NeoUnitTestBase):
def setUp(self): def setUp(self):
NeoUnitTestBase.setUp(self) super(StorageAnswerHandlerTests, self).setUp()
self.app = Mock() self.app = Mock()
self.handler = StorageAnswersHandler(self.app) self.handler = StorageAnswersHandler(self.app)
def getConnection(self):
return self.getFakeConnection()
def _checkHandlerData(self, ref): def _checkHandlerData(self, ref):
calls = self.app.mockGetNamedCalls('setHandlerData') calls = self.app.mockGetNamedCalls('setHandlerData')
self.assertEqual(len(calls), 1) self.assertEqual(len(calls), 1)
calls[0].checkArgs(ref) calls[0].checkArgs(ref)
def test_answerObject(self): def test_answerObject(self):
conn = self.getConnection() conn = self.getFakeConnection()
oid = self.getOID(0) oid = self.getOID(0)
tid1 = self.getNextTID() tid1 = self.getNextTID()
tid2 = self.getNextTID(tid1) tid2 = self.getNextTID(tid1)
...@@ -101,7 +95,7 @@ class StorageAnswerHandlerTests(NeoUnitTestBase): ...@@ -101,7 +95,7 @@ class StorageAnswerHandlerTests(NeoUnitTestBase):
return StorageAnswersHandler(app) return StorageAnswersHandler(app)
def test_answerStoreObject_1(self): def test_answerStoreObject_1(self):
conn = self.getConnection() conn = self.getFakeConnection()
oid = self.getOID(0) oid = self.getOID(0)
tid = self.getNextTID() tid = self.getNextTID()
# conflict # conflict
...@@ -120,7 +114,7 @@ class StorageAnswerHandlerTests(NeoUnitTestBase): ...@@ -120,7 +114,7 @@ class StorageAnswerHandlerTests(NeoUnitTestBase):
conn, 1, oid, tid) conn, 1, oid, tid)
def test_answerStoreObject_2(self): def test_answerStoreObject_2(self):
conn = self.getConnection() conn = self.getFakeConnection()
oid = self.getOID(0) oid = self.getOID(0)
tid = self.getNextTID() tid = self.getNextTID()
tid_2 = self.getNextTID() tid_2 = self.getNextTID()
...@@ -144,7 +138,7 @@ class StorageAnswerHandlerTests(NeoUnitTestBase): ...@@ -144,7 +138,7 @@ class StorageAnswerHandlerTests(NeoUnitTestBase):
).answerStoreObject(conn, 1, oid, tid_2) ).answerStoreObject(conn, 1, oid, tid_2)
def test_answerStoreObject_3(self): def test_answerStoreObject_3(self):
conn = self.getConnection() conn = self.getFakeConnection()
oid = self.getOID(0) oid = self.getOID(0)
tid = self.getNextTID() tid = self.getNextTID()
tid_2 = self.getNextTID() tid_2 = self.getNextTID()
...@@ -184,7 +178,7 @@ class StorageAnswerHandlerTests(NeoUnitTestBase): ...@@ -184,7 +178,7 @@ class StorageAnswerHandlerTests(NeoUnitTestBase):
self.assertEqual(object_stored_counter_dict[oid], {tid: set([uuid])}) self.assertEqual(object_stored_counter_dict[oid], {tid: set([uuid])})
def test_answerTransactionInformation(self): def test_answerTransactionInformation(self):
conn = self.getConnection() conn = self.getFakeConnection()
tid = self.getNextTID() tid = self.getNextTID()
user = 'USER' user = 'USER'
desc = 'DESC' desc = 'DESC'
...@@ -203,17 +197,17 @@ class StorageAnswerHandlerTests(NeoUnitTestBase): ...@@ -203,17 +197,17 @@ class StorageAnswerHandlerTests(NeoUnitTestBase):
}, ext)) }, ext))
def test_oidNotFound(self): def test_oidNotFound(self):
conn = self.getConnection() conn = self.getFakeConnection()
self.assertRaises(NEOStorageNotFoundError, self.handler.oidNotFound, self.assertRaises(NEOStorageNotFoundError, self.handler.oidNotFound,
conn, 'message') conn, 'message')
def test_oidDoesNotExist(self): def test_oidDoesNotExist(self):
conn = self.getConnection() conn = self.getFakeConnection()
self.assertRaises(NEOStorageDoesNotExistError, self.assertRaises(NEOStorageDoesNotExistError,
self.handler.oidDoesNotExist, conn, 'message') self.handler.oidDoesNotExist, conn, 'message')
def test_tidNotFound(self): def test_tidNotFound(self):
conn = self.getConnection() conn = self.getFakeConnection()
self.assertRaises(NEOStorageNotFoundError, self.handler.tidNotFound, self.assertRaises(NEOStorageNotFoundError, self.handler.tidNotFound,
conn, 'message') conn, 'message')
......
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