From 90d849f945e4899967150eeb953b8cc25455a9bb Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sun, 29 Jun 2008 17:06:30 +0000 Subject: [PATCH] added test for parsing of unbound namespace prefixes --- test/test_dispatcher_nb.py | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/test_dispatcher_nb.py diff --git a/test/test_dispatcher_nb.py b/test/test_dispatcher_nb.py new file mode 100644 index 000000000..c82115fa2 --- /dev/null +++ b/test/test_dispatcher_nb.py @@ -0,0 +1,53 @@ +# tests for xmpppy's dispatcher_nb.py +import unittest + +import testlib +testlib.setup_env() + +from mock import Mock + +from common.xmpp import dispatcher_nb +from common.xmpp import auth + +class TestDispatcherNB(unittest.TestCase): + def test_unbound_namespace_prefix(self): + '''tests our handling of a message with an unbound namespace prefix''' + d = dispatcher_nb.Dispatcher() + + conn = Mock() + + owner = Mock() + owner._caller = Mock() + owner.defaultNamespace = auth.NS_CLIENT + owner.debug_flags = [] + owner.Connection = conn + owner._component = False + + d._owner = owner + d.plugin(owner) + + msgs = [] + + def _got_message(conn, msg): + msgs.append(msg) + + d.RegisterHandler('message', _got_message) + + d.StreamInit() + + d.ProcessNonBlocking("") + + # should be able to parse a normal message + d.ProcessNonBlocking('hello') + self.assertEqual(1, len(msgs)) + + d.ProcessNonBlocking('') + # we should not have been disconnected after that message + self.assertEqual(0, len(conn.mockGetNamedCalls('pollend'))) + + # we should be able to keep parsing + d.ProcessNonBlocking('still here?') + self.assertEqual(2, len(msgs)) + +if __name__ == '__main__': + unittest.main()