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