Commit 9697881e authored by Grégory Wisniewski's avatar Grégory Wisniewski

Split and fix connection tests.

- Allow a fine-grained test suite.
- Avoid shadow internal method definitions.
- Remove some meaningless checks

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1846 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 79469dae
...@@ -100,7 +100,7 @@ class ConnectionTests(NeoTestBase): ...@@ -100,7 +100,7 @@ class ConnectionTests(NeoTestBase):
conn = call.getParam(0) conn = call.getParam(0)
self.assertEquals(conn, bc) self.assertEquals(conn, bc)
def test_02_ListeningConnection(self): def test_02_ListeningConnection1(self):
# test init part # test init part
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -120,6 +120,7 @@ class ConnectionTests(NeoTestBase): ...@@ -120,6 +120,7 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1) self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1)
self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 1) self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 1)
def test_02_ListeningConnection2(self):
# test with exception raise when getting new connection # test with exception raise when getting new connection
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -139,7 +140,6 @@ class ConnectionTests(NeoTestBase): ...@@ -139,7 +140,6 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1) self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1)
self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 0) self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 0)
def test_03_Connection(self): def test_03_Connection(self):
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -176,7 +176,7 @@ class ConnectionTests(NeoTestBase): ...@@ -176,7 +176,7 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(bc.aborted, True) self.assertEqual(bc.aborted, True)
self.assertFalse(bc.isServer()) self.assertFalse(bc.isServer())
def test_04_Connection_pending(self): def test_Connection_pending(self):
em = Mock() em = Mock()
handler = Mock() handler = Mock()
bc = Connection(em, handler, connector_handler=DoNothingConnector, bc = Connection(em, handler, connector_handler=DoNothingConnector,
...@@ -200,10 +200,10 @@ class ConnectionTests(NeoTestBase): ...@@ -200,10 +200,10 @@ class ConnectionTests(NeoTestBase):
self.assertTrue(bc.pending()) self.assertTrue(bc.pending())
def test_05_Connection_recv(self): def test_Connection_recv1(self):
# patch receive method to return data
em = Mock() em = Mock()
handler = Mock() handler = Mock()
# patch receive method to return data
def receive(self): def receive(self):
return "testdata" return "testdata"
DoNothingConnector.receive = receive DoNothingConnector.receive = receive
...@@ -216,7 +216,10 @@ class ConnectionTests(NeoTestBase): ...@@ -216,7 +216,10 @@ class ConnectionTests(NeoTestBase):
bc._recv() bc._recv()
self.assertEqual(bc.read_buf, "testdata") self.assertEqual(bc.read_buf, "testdata")
def test_Connection_recv2(self):
# patch receive method to raise try again # patch receive method to raise try again
em = Mock()
handler = Mock()
def receive(self): def receive(self):
raise ConnectorTryAgainException raise ConnectorTryAgainException
DoNothingConnector.receive = receive DoNothingConnector.receive = receive
...@@ -229,7 +232,11 @@ class ConnectionTests(NeoTestBase): ...@@ -229,7 +232,11 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
def test_Connection_recv3(self):
# patch receive method to raise ConnectorConnectionRefusedException # patch receive method to raise ConnectorConnectionRefusedException
em = Mock()
handler = Mock()
def receive(self): def receive(self):
raise ConnectorConnectionRefusedException raise ConnectorConnectionRefusedException
DoNothingConnector.receive = receive DoNothingConnector.receive = receive
...@@ -244,7 +251,11 @@ class ConnectionTests(NeoTestBase): ...@@ -244,7 +251,11 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionFailed")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionFailed")), 1)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 1) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 1)
def test_Connection_recv4(self):
# patch receive method to raise any other connector error # patch receive method to raise any other connector error
em = Mock()
handler = Mock()
def receive(self): def receive(self):
raise ConnectorException raise ConnectorException
DoNothingConnector.receive = receive DoNothingConnector.receive = receive
...@@ -256,10 +267,10 @@ class ConnectionTests(NeoTestBase): ...@@ -256,10 +267,10 @@ class ConnectionTests(NeoTestBase):
self.assertRaises(ConnectorException, bc._recv) self.assertRaises(ConnectorException, bc._recv)
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 1)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 2) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 1)
def test_06_Connection_send(self): def test_Connection_send1(self):
# no data, nothing done # no data, nothing done
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -274,7 +285,10 @@ class ConnectionTests(NeoTestBase): ...@@ -274,7 +285,10 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
def test_Connection_send2(self):
# send all data # send all data
em = Mock()
handler = Mock()
def send(self, data): def send(self, data):
return len(data) return len(data)
DoNothingConnector.send = send DoNothingConnector.send = send
...@@ -293,7 +307,10 @@ class ConnectionTests(NeoTestBase): ...@@ -293,7 +307,10 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
def test_Connection_send3(self):
# send part of the data # send part of the data
em = Mock()
handler = Mock()
def send(self, data): def send(self, data):
return len(data)/2 return len(data)/2
DoNothingConnector.send = send DoNothingConnector.send = send
...@@ -312,7 +329,10 @@ class ConnectionTests(NeoTestBase): ...@@ -312,7 +329,10 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
def test_Connection_send4(self):
# send multiple packet # send multiple packet
em = Mock()
handler = Mock()
def send(self, data): def send(self, data):
return len(data) return len(data)
DoNothingConnector.send = send DoNothingConnector.send = send
...@@ -331,7 +351,10 @@ class ConnectionTests(NeoTestBase): ...@@ -331,7 +351,10 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
def test_Connection_send5(self):
# send part of multiple packet # send part of multiple packet
em = Mock()
handler = Mock()
def send(self, data): def send(self, data):
return len(data)/2 return len(data)/2
DoNothingConnector.send = send DoNothingConnector.send = send
...@@ -350,7 +373,10 @@ class ConnectionTests(NeoTestBase): ...@@ -350,7 +373,10 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
def test_Connection_send6(self):
# raise try again # raise try again
em = Mock()
handler = Mock()
def send(self, data): def send(self, data):
raise ConnectorTryAgainException raise ConnectorTryAgainException
DoNothingConnector.send = send DoNothingConnector.send = send
...@@ -369,7 +395,10 @@ class ConnectionTests(NeoTestBase): ...@@ -369,7 +395,10 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
def test_Connection_send7(self):
# raise other error # raise other error
em = Mock()
handler = Mock()
def send(self, data): def send(self, data):
raise ConnectorException raise ConnectorException
DoNothingConnector.send = send DoNothingConnector.send = send
...@@ -390,7 +419,6 @@ class ConnectionTests(NeoTestBase): ...@@ -390,7 +419,6 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(em.mockGetNamedCalls("removeReader")), 1) self.assertEquals(len(em.mockGetNamedCalls("removeReader")), 1)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 1) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 1)
def test_07_Connection_addPacket(self): def test_07_Connection_addPacket(self):
# no connector # no connector
p = Mock({"__call__" : "testdata"}) p = Mock({"__call__" : "testdata"})
...@@ -438,7 +466,7 @@ class ConnectionTests(NeoTestBase): ...@@ -438,7 +466,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(em.mockGetNamedCalls("addIdleEvent")), 1) self.assertEquals(len(em.mockGetNamedCalls("addIdleEvent")), 1)
def test_09_Connection_analyse(self): def test_Connection_analyse1(self):
# nothing to read, nothing is done # nothing to read, nothing is done
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -480,9 +508,11 @@ class ConnectionTests(NeoTestBase): ...@@ -480,9 +508,11 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
def test_Connection_analyse2(self):
# give multiple packet # give multiple packet
em = Mock() em = Mock()
handler = Mock() handler = Mock()
connector = DoNothingConnector()
bc = Connection(em, handler, connector_handler=DoNothingConnector, bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
bc._queue = Mock() bc._queue = Mock()
...@@ -533,9 +563,11 @@ class ConnectionTests(NeoTestBase): ...@@ -533,9 +563,11 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(len(bc.read_buf), 0) self.assertEqual(len(bc.read_buf), 0)
def test_Connection_analyse3(self):
# give a bad packet, won't be decoded # give a bad packet, won't be decoded
em = Mock() em = Mock()
handler = Mock() handler = Mock()
connector = DoNothingConnector()
bc = Connection(em, handler, connector_handler=DoNothingConnector, bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
bc._queue = Mock() bc._queue = Mock()
...@@ -547,9 +579,11 @@ class ConnectionTests(NeoTestBase): ...@@ -547,9 +579,11 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(bc._queue.mockGetNamedCalls("append")), 0) self.assertEquals(len(bc._queue.mockGetNamedCalls("append")), 0)
self.assertEquals(len(em.mockGetNamedCalls("removeIdleEvent")), 0) self.assertEquals(len(em.mockGetNamedCalls("removeIdleEvent")), 0)
def test_Connection_analyse4(self):
# give an expected packet # give an expected packet
em = Mock() em = Mock()
handler = Mock() handler = Mock()
connector = DoNothingConnector()
bc = Connection(em, handler, connector_handler=DoNothingConnector, bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
bc._queue = Mock() bc._queue = Mock()
...@@ -581,7 +615,7 @@ class ConnectionTests(NeoTestBase): ...@@ -581,7 +615,7 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
def test_10_Connection_writable(self): def test_Connection_writable1(self):
# with pending operation after send # with pending operation after send
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -613,7 +647,7 @@ class ConnectionTests(NeoTestBase): ...@@ -613,7 +647,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(connector.mockGetNamedCalls("shutdown")), 0) self.assertEquals(len(connector.mockGetNamedCalls("shutdown")), 0)
self.assertEquals(len(connector.mockGetNamedCalls("close")), 0) self.assertEquals(len(connector.mockGetNamedCalls("close")), 0)
def test_Connection_writable2(self):
# with no longer pending operation after send # with no longer pending operation after send
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -645,6 +679,7 @@ class ConnectionTests(NeoTestBase): ...@@ -645,6 +679,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(connector.mockGetNamedCalls("shutdown")), 0) self.assertEquals(len(connector.mockGetNamedCalls("shutdown")), 0)
self.assertEquals(len(connector.mockGetNamedCalls("close")), 0) self.assertEquals(len(connector.mockGetNamedCalls("close")), 0)
def test_Connection_writable3(self):
# with no longer pending operation after send and aborted set to true # with no longer pending operation after send and aborted set to true
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -677,8 +712,7 @@ class ConnectionTests(NeoTestBase): ...@@ -677,8 +712,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(connector.mockGetNamedCalls("shutdown")), 1) self.assertEquals(len(connector.mockGetNamedCalls("shutdown")), 1)
self.assertEquals(len(connector.mockGetNamedCalls("close")), 1) self.assertEquals(len(connector.mockGetNamedCalls("close")), 1)
def test_Connection_readable(self):
def test_11_Connection_readable(self):
# With aborted set to false # With aborted set to false
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -723,9 +757,7 @@ class ConnectionTests(NeoTestBase): ...@@ -723,9 +757,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(connector.mockGetNamedCalls("shutdown")), 0) self.assertEquals(len(connector.mockGetNamedCalls("shutdown")), 0)
self.assertEquals(len(connector.mockGetNamedCalls("close")), 0) self.assertEquals(len(connector.mockGetNamedCalls("close")), 0)
def test_ClientConnection_init1(self):
def test_12_ClientConnection_init(self):
makeClientConnection_org = DoNothingConnector.makeClientConnection
# create a good client connection # create a good client connection
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -750,7 +782,9 @@ class ConnectionTests(NeoTestBase): ...@@ -750,7 +782,9 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(em.mockGetNamedCalls("addReader")), 1) self.assertEquals(len(em.mockGetNamedCalls("addReader")), 1)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0)
def test_ClientConnection_init2(self):
# raise connection in progress # raise connection in progress
makeClientConnection_org = DoNothingConnector.makeClientConnection
def makeClientConnection(self, *args, **kw): def makeClientConnection(self, *args, **kw):
raise ConnectorInProgressException raise ConnectorInProgressException
em = Mock() em = Mock()
...@@ -780,7 +814,9 @@ class ConnectionTests(NeoTestBase): ...@@ -780,7 +814,9 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(em.mockGetNamedCalls("addReader")), 0) self.assertEquals(len(em.mockGetNamedCalls("addReader")), 0)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 1) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 1)
def test_ClientConnection_init3(self):
# raise another error, connection must fail # raise another error, connection must fail
makeClientConnection_org = DoNothingConnector.makeClientConnection
def makeClientConnection(self, *args, **kw): def makeClientConnection(self, *args, **kw):
raise ConnectorException raise ConnectorException
em = Mock() em = Mock()
...@@ -793,17 +829,14 @@ class ConnectionTests(NeoTestBase): ...@@ -793,17 +829,14 @@ class ConnectionTests(NeoTestBase):
DoNothingConnector.makeClientConnection = makeClientConnection_org DoNothingConnector.makeClientConnection = makeClientConnection_org
# since the exception was raised, the connection is not created # since the exception was raised, the connection is not created
# check call to handler # check call to handler
self.assertNotEqual(bc.getHandler(), None)
self.assertEquals(len(handler.mockGetNamedCalls("connectionStarted")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionStarted")), 1)
self.assertEquals(len(handler.mockGetNamedCalls("connectionCompleted")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionCompleted")), 0)
self.assertEquals(len(handler.mockGetNamedCalls("connectionFailed")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionFailed")), 1)
# check call to event manager # check call to event manager
self.assertNotEqual(bc.getEventManager(), None)
self.assertEquals(len(em.mockGetNamedCalls("addReader")), 0) self.assertEquals(len(em.mockGetNamedCalls("addReader")), 0)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0)
def test_ClientConnection_writable1(self):
def test_13_ClientConnection_writable(self):
# with a non connecting connection, will call parent's method # with a non connecting connection, will call parent's method
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -812,14 +845,12 @@ class ConnectionTests(NeoTestBase): ...@@ -812,14 +845,12 @@ class ConnectionTests(NeoTestBase):
def send(self, data): def send(self, data):
return len(data) return len(data)
makeClientConnection_org = DoNothingConnector.makeClientConnection makeClientConnection_org = DoNothingConnector.makeClientConnection
send_org = DoNothingConnector.send
DoNothingConnector.send = send DoNothingConnector.send = send
DoNothingConnector.makeClientConnection = makeClientConnection DoNothingConnector.makeClientConnection = makeClientConnection
try: try:
bc = ClientConnection(em, handler, connector_handler=DoNothingConnector, bc = ClientConnection(em, handler, connector_handler=DoNothingConnector,
addr=("127.0.0.7", 93413)) addr=("127.0.0.7", 93413))
finally: finally:
DoNothingConnector.send = send_org
DoNothingConnector.makeClientConnection = makeClientConnection_org DoNothingConnector.makeClientConnection = makeClientConnection_org
# check connector created and connection initialize # check connector created and connection initialize
self.assertFalse(bc.connecting) self.assertFalse(bc.connecting)
...@@ -855,7 +886,7 @@ class ConnectionTests(NeoTestBase): ...@@ -855,7 +886,7 @@ class ConnectionTests(NeoTestBase):
data = call.getParam(0) data = call.getParam(0)
self.assertEquals(data, "testdata") self.assertEquals(data, "testdata")
def test_ClientConnection_writable2(self):
# with a connecting connection, must not call parent's method # with a connecting connection, must not call parent's method
# with no error, just complete connection # with no error, just complete connection
em = Mock() em = Mock()
...@@ -892,6 +923,7 @@ class ConnectionTests(NeoTestBase): ...@@ -892,6 +923,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("shutdown")), 0) self.assertEquals(len(conn.mockGetNamedCalls("shutdown")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("close")), 0) self.assertEquals(len(conn.mockGetNamedCalls("close")), 0)
def test_ClientConnection_writable3(self):
# with a connecting connection, must not call parent's method # with a connecting connection, must not call parent's method
# with errors, close connection # with errors, close connection
em = Mock() em = Mock()
...@@ -925,7 +957,6 @@ class ConnectionTests(NeoTestBase): ...@@ -925,7 +957,6 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(em.mockGetNamedCalls("removeWriter")), 1) self.assertEquals(len(em.mockGetNamedCalls("removeWriter")), 1)
self.assertEquals(len(em.mockGetNamedCalls("removeReader")), 1) self.assertEquals(len(em.mockGetNamedCalls("removeReader")), 1)
def test_14_ServerConnection(self): def test_14_ServerConnection(self):
em = Mock() em = Mock()
handler = Mock() handler = Mock()
...@@ -963,8 +994,7 @@ class ConnectionTests(NeoTestBase): ...@@ -963,8 +994,7 @@ class ConnectionTests(NeoTestBase):
self.assertTrue(bc.isServer()) self.assertTrue(bc.isServer())
def test_15_MTClientConnection(self): def test_MTClientConnection1(self):
makeClientConnection_org = DoNothingConnector.makeClientConnection
# same as ClientConnection, except definition of some lock # same as ClientConnection, except definition of some lock
# create a good client connection # create a good client connection
em = Mock() em = Mock()
...@@ -990,11 +1020,15 @@ class ConnectionTests(NeoTestBase): ...@@ -990,11 +1020,15 @@ class ConnectionTests(NeoTestBase):
self.assertNotEqual(bc.getEventManager(), None) self.assertNotEqual(bc.getEventManager(), None)
self.assertEquals(len(em.mockGetNamedCalls("addReader")), 1) self.assertEquals(len(em.mockGetNamedCalls("addReader")), 1)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0)
def test_MTClientConnection2(self):
# raise connection in progress # raise connection in progress
makeClientConnection_org = DoNothingConnector.makeClientConnection
def makeClientConnection(self, *args, **kw): def makeClientConnection(self, *args, **kw):
raise ConnectorInProgressException raise ConnectorInProgressException
em = Mock() em = Mock()
handler = Mock() handler = Mock()
dispatcher = Mock()
DoNothingConnector.makeClientConnection = makeClientConnection DoNothingConnector.makeClientConnection = makeClientConnection
try: try:
bc = MTClientConnection(em, handler, connector_handler=DoNothingConnector, bc = MTClientConnection(em, handler, connector_handler=DoNothingConnector,
...@@ -1020,11 +1054,14 @@ class ConnectionTests(NeoTestBase): ...@@ -1020,11 +1054,14 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(em.mockGetNamedCalls("addReader")), 0) self.assertEquals(len(em.mockGetNamedCalls("addReader")), 0)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 1) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 1)
def test_MTClientConnection3(self):
# raise another error, connection must fail # raise another error, connection must fail
makeClientConnection_org = DoNothingConnector.makeClientConnection
def makeClientConnection(self, *args, **kw): def makeClientConnection(self, *args, **kw):
raise ConnectorException raise ConnectorException
em = Mock() em = Mock()
handler = Mock() handler = Mock()
dispatcher = Mock()
DoNothingConnector.makeClientConnection = makeClientConnection DoNothingConnector.makeClientConnection = makeClientConnection
try: try:
self.assertRaises(ConnectorException, MTClientConnection, em, handler, self.assertRaises(ConnectorException, MTClientConnection, em, handler,
...@@ -1034,12 +1071,10 @@ class ConnectionTests(NeoTestBase): ...@@ -1034,12 +1071,10 @@ class ConnectionTests(NeoTestBase):
DoNothingConnector.makeClientConnection = makeClientConnection_org DoNothingConnector.makeClientConnection = makeClientConnection_org
# the connection is not created # the connection is not created
# check call to handler # check call to handler
self.assertNotEqual(bc.getHandler(), None)
self.assertEquals(len(handler.mockGetNamedCalls("connectionStarted")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionStarted")), 1)
self.assertEquals(len(handler.mockGetNamedCalls("connectionCompleted")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionCompleted")), 0)
self.assertEquals(len(handler.mockGetNamedCalls("connectionFailed")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionFailed")), 1)
# check call to event manager # check call to event manager
self.assertNotEqual(bc.getEventManager(), None)
self.assertEquals(len(em.mockGetNamedCalls("addReader")), 0) self.assertEquals(len(em.mockGetNamedCalls("addReader")), 0)
self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 0) self.assertEquals(len(em.mockGetNamedCalls("addWriter")), 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