Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_dispatcher_nb.py « test - dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9af6717b8a66d7d176fe7ea106bdcce93552f5f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# tests for xmpppy's dispatcher_nb.py
import unittest

import lib
lib.setup_env()

from mock import Mock

from common.xmpp import dispatcher_nb
from common.xmpp import auth_nb

class TestDispatcherNB(unittest.TestCase):
	def test_unbound_namespace_prefix(self):
		'''tests our handling of a message with an unbound namespace prefix'''
		d = dispatcher_nb.XMPPDispatcher()

		conn = Mock()

		owner = Mock()
		owner._caller = Mock()
		owner.defaultNamespace = auth_nb.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(3, len(msgs))

if __name__ == '__main__':
	unittest.main()

# vim: se ts=3: