Commit f7652c07 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Rewrite dispatcher (now generic) tests.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1308 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 235fdc88
...@@ -17,42 +17,46 @@ ...@@ -17,42 +17,46 @@
import unittest import unittest
from mock import Mock
from neo.dispatcher import Dispatcher from neo.dispatcher import Dispatcher
class DispatcherTests(unittest.TestCase): class DispatcherTests(unittest.TestCase):
def test_register(self): def setUp(self):
dispatcher = Dispatcher() self.dispatcher = Dispatcher()
conn = []
other_conn = [] def testRegister(self):
queue = [] conn = object()
test_message_id = 1 self.dispatcher.register(conn, 1, 0)
class Packet: self.assertEqual(self.dispatcher.pop(conn, 1, None), 0)
def __init__(self, msg_id): self.assertEqual(self.dispatcher.pop(conn, 2, 3), 3)
self.msg_id = msg_id
def testUnregister(self):
def getId(self): conn = object()
return self.msg_id queue = Mock()
packet = Packet(test_message_id) self.dispatcher.register(conn, 2, queue)
other_packet = Packet(test_message_id + 1) self.dispatcher.unregister(conn)
# Check that unregistered message is detected as unregistered self.assertEqual(len(queue.mockGetNamedCalls('put')), 1)
self.assertEqual(dispatcher.getQueue(conn, packet), None) self.assertEqual(self.dispatcher.pop(conn, 2, 3), 3)
self.assertFalse(dispatcher.registered(conn))
# Register (must not raise) def testRegistered(self):
dispatcher.register(conn, test_message_id, queue) conn1 = object()
# Check that connection is detected as registered conn2 = object()
self.assertTrue(dispatcher.registered(conn)) self.assertFalse(self.dispatcher.registered(conn1))
# Check that variations don't get detected as registered self.assertFalse(self.dispatcher.registered(conn2))
self.assertFalse(dispatcher.registered(other_conn)) self.dispatcher.register(conn1, 1, Mock())
self.assertEqual(dispatcher.getQueue(other_conn, packet), None) self.assertTrue(self.dispatcher.registered(conn1))
self.assertEqual(dispatcher.getQueue(conn, other_packet), None) self.assertFalse(self.dispatcher.registered(conn2))
self.assertEqual(dispatcher.getQueue(other_conn, other_packet), None) self.dispatcher.register(conn2, 2, Mock())
# Check that queue is detected as registered. self.assertTrue(self.dispatcher.registered(conn1))
# This unregisters the message... self.assertTrue(self.dispatcher.registered(conn2))
self.assertTrue(dispatcher.getQueue(conn, packet) is queue) self.dispatcher.unregister(conn1)
# so check again that unregistered message is detected as unregistered self.assertFalse(self.dispatcher.registered(conn1))
self.assertEqual(dispatcher.getQueue(conn, packet), None) self.assertTrue(self.dispatcher.registered(conn2))
self.assertFalse(dispatcher.registered(conn)) self.dispatcher.unregister(conn2)
self.assertFalse(self.dispatcher.registered(conn1))
self.assertFalse(self.dispatcher.registered(conn2))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
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