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 @@
import unittest
from mock import Mock
from neo.dispatcher import Dispatcher
class DispatcherTests(unittest.TestCase):
def test_register(self):
dispatcher = Dispatcher()
conn = []
other_conn = []
queue = []
test_message_id = 1
class Packet:
def __init__(self, msg_id):
self.msg_id = msg_id
def getId(self):
return self.msg_id
packet = Packet(test_message_id)
other_packet = Packet(test_message_id + 1)
# Check that unregistered message is detected as unregistered
self.assertEqual(dispatcher.getQueue(conn, packet), None)
self.assertFalse(dispatcher.registered(conn))
# Register (must not raise)
dispatcher.register(conn, test_message_id, queue)
# Check that connection is detected as registered
self.assertTrue(dispatcher.registered(conn))
# Check that variations don't get detected as registered
self.assertFalse(dispatcher.registered(other_conn))
self.assertEqual(dispatcher.getQueue(other_conn, packet), None)
self.assertEqual(dispatcher.getQueue(conn, other_packet), None)
self.assertEqual(dispatcher.getQueue(other_conn, other_packet), None)
# Check that queue is detected as registered.
# This unregisters the message...
self.assertTrue(dispatcher.getQueue(conn, packet) is queue)
# so check again that unregistered message is detected as unregistered
self.assertEqual(dispatcher.getQueue(conn, packet), None)
self.assertFalse(dispatcher.registered(conn))
def setUp(self):
self.dispatcher = Dispatcher()
def testRegister(self):
conn = object()
self.dispatcher.register(conn, 1, 0)
self.assertEqual(self.dispatcher.pop(conn, 1, None), 0)
self.assertEqual(self.dispatcher.pop(conn, 2, 3), 3)
def testUnregister(self):
conn = object()
queue = Mock()
self.dispatcher.register(conn, 2, queue)
self.dispatcher.unregister(conn)
self.assertEqual(len(queue.mockGetNamedCalls('put')), 1)
self.assertEqual(self.dispatcher.pop(conn, 2, 3), 3)
def testRegistered(self):
conn1 = object()
conn2 = object()
self.assertFalse(self.dispatcher.registered(conn1))
self.assertFalse(self.dispatcher.registered(conn2))
self.dispatcher.register(conn1, 1, Mock())
self.assertTrue(self.dispatcher.registered(conn1))
self.assertFalse(self.dispatcher.registered(conn2))
self.dispatcher.register(conn2, 2, Mock())
self.assertTrue(self.dispatcher.registered(conn1))
self.assertTrue(self.dispatcher.registered(conn2))
self.dispatcher.unregister(conn1)
self.assertFalse(self.dispatcher.registered(conn1))
self.assertTrue(self.dispatcher.registered(conn2))
self.dispatcher.unregister(conn2)
self.assertFalse(self.dispatcher.registered(conn1))
self.assertFalse(self.dispatcher.registered(conn2))
if __name__ == '__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