summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-12-15 12:04:14 -0800
committerLance Stout <lancestout@gmail.com>2011-12-15 12:04:14 -0800
commit8f9d1bcfe07f3b2302634464eed1e329b71f54ba (patch)
treeb439366a0edeed47d269e1f9327b88a1d7e113ee /tests
parenta7a2fd1d5bd770e0df2c2df240acd57fe5e40ea9 (diff)
parentf6e30edbc4a717b34bbf01d3d0a9fe884c6b37da (diff)
downloadslixmpp-8f9d1bcfe07f3b2302634464eed1e329b71f54ba.tar.gz
slixmpp-8f9d1bcfe07f3b2302634464eed1e329b71f54ba.tar.bz2
slixmpp-8f9d1bcfe07f3b2302634464eed1e329b71f54ba.tar.xz
slixmpp-8f9d1bcfe07f3b2302634464eed1e329b71f54ba.zip
Merge branch 'develop-1.1' of github.com:fritzy/SleekXMPP into develop-1.1
Diffstat (limited to 'tests')
-rw-r--r--tests/test_stream_filters.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/test_stream_filters.py b/tests/test_stream_filters.py
new file mode 100644
index 00000000..ef4d5dc8
--- /dev/null
+++ b/tests/test_stream_filters.py
@@ -0,0 +1,88 @@
+import time
+
+from sleekxmpp import Message
+from sleekxmpp.test import *
+from sleekxmpp.xmlstream.handler import *
+from sleekxmpp.xmlstream.matcher import *
+
+
+class TestFilters(SleekTest):
+
+ """
+ Test using incoming and outgoing filters.
+ """
+
+ def setUp(self):
+ self.stream_start()
+
+ def tearDown(self):
+ self.stream_close()
+
+ def testIncoming(self):
+
+ data = []
+
+ def in_filter(stanza):
+ if isinstance(stanza, Message):
+ if stanza['body'] == 'testing':
+ stanza['subject'] = stanza['body'] + ' filter'
+ print('>>> %s' % stanza['subject'])
+ return stanza
+
+ def on_message(msg):
+ print('<<< %s' % msg['subject'])
+ data.append(msg['subject'])
+
+ self.xmpp.add_filter('in', in_filter)
+ self.xmpp.add_event_handler('message', on_message)
+
+ self.recv("""
+ <message>
+ <body>no filter</body>
+ </message>
+ """)
+
+ self.recv("""
+ <message>
+ <body>testing</body>
+ </message>
+ """)
+
+ time.sleep(0.5)
+
+ self.assertEqual(data, ['', 'testing filter'],
+ 'Incoming filter did not apply %s' % data)
+
+ def testOutgoing(self):
+
+ def out_filter(stanza):
+ if isinstance(stanza, Message):
+ if stanza['body'] == 'testing':
+ stanza['body'] = 'changed!'
+ return stanza
+
+ self.xmpp.add_filter('out', out_filter)
+
+ m1 = self.Message()
+ m1['body'] = 'testing'
+ m1.send()
+
+ m2 = self.Message()
+ m2['body'] = 'blah'
+ m2.send()
+
+ self.send("""
+ <message>
+ <body>changed!</body>
+ </message>
+ """)
+
+ self.send("""
+ <message>
+ <body>blah</body>
+ </message>
+ """)
+
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestFilters)