slixmpp/tests/test_stream.py
mathieui 1e2665df19
Update the test suite.
- monkey-patch our own monkey-patched idle_call to run events immediatly
  rather than adding them to the event queue, and add a fake transport
  with a fake socket.
- remove the test file related to xep_0059 as it relies on blocking
  behavior, and comment out one xep_0030 test uses xep_0059
- remove many instances of threading and sleep()s because they do
  nothing except waste time and introduce race conditions.
- keep exactly two sleep() in IoT xeps because they rely on timeouts
2015-02-12 12:23:47 +01:00

61 lines
1.6 KiB
Python

import time
import unittest
from slixmpp.test import SlixTest
class TestStreamTester(SlixTest):
"""
Test that we can simulate and test a stanza stream.
"""
def tearDown(self):
self.stream_close()
def testClientEcho(self):
"""Test that we can interact with a ClientXMPP instance."""
self.stream_start(mode='client')
def echo(msg):
msg.reply('Thanks for sending: %s' % msg['body']).send()
self.xmpp.add_event_handler('message', echo)
self.recv("""
<message to="tester@localhost" from="user@localhost">
<body>Hi!</body>
</message>
""")
self.send("""
<message to="user@localhost">
<body>Thanks for sending: Hi!</body>
</message>
""")
def testComponentEcho(self):
"""Test that we can interact with a ComponentXMPP instance."""
self.stream_start(mode='component')
def echo(msg):
msg.reply('Thanks for sending: %(body)s' % msg).send()
self.xmpp.add_event_handler('message', echo)
self.recv("""
<message to="tester.localhost" from="user@localhost">
<body>Hi!</body>
</message>
""")
self.send("""
<message to="user@localhost" from="tester.localhost">
<body>Thanks for sending: Hi!</body>
</message>
""")
def testSendStreamHeader(self):
"""Test that we can check a sent stream header."""
self.stream_start(mode='client', skip=False)
self.send_header(sto='localhost')
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamTester)