diff options
author | Brendan Taylor <bct@diffeq.com> | 2008-06-29 21:06:30 +0400 |
---|---|---|
committer | Brendan Taylor <bct@diffeq.com> | 2008-06-29 21:06:30 +0400 |
commit | 90d849f945e4899967150eeb953b8cc25455a9bb (patch) | |
tree | 1e00a7c97f4edd953a2895737e75c85f42732470 /test/test_dispatcher_nb.py | |
parent | 3a94e595e5dba4b995f2b8c9109ddaffda19d40d (diff) |
added test for parsing of unbound namespace prefixes
Diffstat (limited to 'test/test_dispatcher_nb.py')
-rw-r--r-- | test/test_dispatcher_nb.py | 53 |
1 files changed, 53 insertions, 0 deletions
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("<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>") + + # should be able to parse a normal message + d.ProcessNonBlocking('<message><body>hello</body></message>') + self.assertEqual(1, len(msgs)) + + d.ProcessNonBlocking('<message><x:y/></message>') + # 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('<message><body>still here?</body></message>') + self.assertEqual(2, len(msgs)) + +if __name__ == '__main__': + unittest.main() |