Commit 58d29260 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix tests conflict where monkey patches where not restored. Also fix a bug in

connectToPrimary test for client application.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@612 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 4857818a
......@@ -803,7 +803,7 @@ class ClientApplicationTest(NeoTestBase):
app.pt = Mock({ 'operational': ReturnValues(False, False, True, True)})
self.all_passed = False
try:
self.connectToPrimaryMasterNode(app)
app.master_conn = app.connectToPrimaryMasterNode()
finally:
Application._waitMessage = _waitMessage_old
self.assertEquals(len(app.pt.mockGetNamedCalls('clear')), 1)
......@@ -821,8 +821,8 @@ class ClientApplicationTest(NeoTestBase):
def _waitMessage_hook(app, conn=None, msg_id=None, handler=None):
self.test_ok = True
_waitMessage_old = Application._waitMessage
Application._waitMessage = _waitMessage_hook
packet = protocol.askNewTID()
Application._waitMessage = _waitMessage_hook
try:
app._askStorage(conn, packet)
finally:
......@@ -846,8 +846,8 @@ class ClientApplicationTest(NeoTestBase):
self.assertEquals(handler, app.primary_handler)
self.test_ok = True
_waitMessage_old = Application._waitMessage
Application._waitMessage = _waitMessage_hook
packet = protocol.askNewTID()
Application._waitMessage = _waitMessage_hook
try:
app._askPrimary(packet)
finally:
......
......@@ -748,6 +748,7 @@ class testConnection(unittest.TestCase):
def test_12_ClientConnection_init(self):
makeClientConnection_org = DoNothingConnector.makeClientConnection
# create a good client connection
em = Mock()
handler = Mock()
......@@ -776,12 +777,15 @@ class testConnection(unittest.TestCase):
# raise connection in progress
def makeClientConnection(self, *args, **kw):
raise ConnectorInProgressException
DoNothingConnector.makeClientConnection = makeClientConnection
em = Mock()
handler = Mock()
connector = DoNothingConnector()
DoNothingConnector.makeClientConnection = makeClientConnection
try:
bc = ClientConnection(em, handler, connector_handler=DoNothingConnector,
addr=("127.0.0.7", 93413))
finally:
DoNothingConnector.makeClientConnection = makeClientConnection_org
# check connector created and connection initialize
self.assertTrue(bc.connecting)
self.assertFalse(bc.isServerConnection())
......@@ -804,12 +808,15 @@ class testConnection(unittest.TestCase):
# raise another error, connection must fail
def makeClientConnection(self, *args, **kw):
raise ConnectorException
DoNothingConnector.makeClientConnection = makeClientConnection
em = Mock()
handler = Mock()
connector = DoNothingConnector()
DoNothingConnector.makeClientConnection = makeClientConnection
try:
self.assertRaises(ConnectorException, ClientConnection, em, handler,
connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413))
finally:
DoNothingConnector.makeClientConnection = makeClientConnection_org
# since the exception was raised, the connection is not created
# check call to handler
self.assertNotEqual(bc.getHandler(), None)
......@@ -828,12 +835,18 @@ class testConnection(unittest.TestCase):
handler = Mock()
def makeClientConnection(self, *args, **kw):
return "OK"
DoNothingConnector.makeClientConnection = makeClientConnection
def send(self, data):
return len(data)
makeClientConnection_org = DoNothingConnector.makeClientConnection
send_org = DoNothingConnector.send
DoNothingConnector.send = send
DoNothingConnector.makeClientConnection = makeClientConnection
try:
bc = ClientConnection(em, handler, connector_handler=DoNothingConnector,
addr=("127.0.0.7", 93413))
finally:
DoNothingConnector.send = send_org
DoNothingConnector.makeClientConnection = makeClientConnection_org
# check connector created and connection initialize
self.assertFalse(bc.connecting)
self.assertNotEqual(bc.getConnector(), None)
......@@ -977,6 +990,7 @@ class testConnection(unittest.TestCase):
def test_15_MTClientConnection(self):
makeClientConnection_org = DoNothingConnector.makeClientConnection
# same as ClientConnection, except definition of some lock
# create a good client connection
em = Mock()
......@@ -1005,12 +1019,15 @@ class testConnection(unittest.TestCase):
# raise connection in progress
def makeClientConnection(self, *args, **kw):
raise ConnectorInProgressException
DoNothingConnector.makeClientConnection = makeClientConnection
em = Mock()
handler = Mock()
connector = DoNothingConnector()
DoNothingConnector.makeClientConnection = makeClientConnection
try:
bc = MTClientConnection(em, handler, connector_handler=DoNothingConnector,
addr=("127.0.0.7", 93413))
finally:
DoNothingConnector.makeClientConnection = makeClientConnection_org
# check connector created and connection initialize
self.assertTrue(bc.connecting)
self.assertFalse(bc.isServerConnection())
......@@ -1033,12 +1050,15 @@ class testConnection(unittest.TestCase):
# raise another error, connection must fail
def makeClientConnection(self, *args, **kw):
raise ConnectorException
DoNothingConnector.makeClientConnection = makeClientConnection
em = Mock()
handler = Mock()
connector = DoNothingConnector()
DoNothingConnector.makeClientConnection = makeClientConnection
try:
self.assertRaises(ConnectorException, MTClientConnection, em, handler,
connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413))
finally:
DoNothingConnector.makeClientConnection = makeClientConnection_org
# the connection is not created
# check call to handler
self.assertNotEqual(bc.getHandler(), None)
......
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