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