summaryrefslogtreecommitdiff
path: root/sleekxmpp/test
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-05-31 10:59:14 -0700
committerLance Stout <lancestout@gmail.com>2011-05-31 10:59:14 -0700
commit5ed27bf5f65f03e14da24a60e261a175074cb7aa (patch)
treec79db47352f003b51459016df699032b51712292 /sleekxmpp/test
parent62bdaab7c7fc5a35c83ac9f3b0bf5b393f0eb925 (diff)
parenta81162edd2434756e21d7f9a79d71d770a43db7b (diff)
downloadslixmpp-5ed27bf5f65f03e14da24a60e261a175074cb7aa.tar.gz
slixmpp-5ed27bf5f65f03e14da24a60e261a175074cb7aa.tar.bz2
slixmpp-5ed27bf5f65f03e14da24a60e261a175074cb7aa.tar.xz
slixmpp-5ed27bf5f65f03e14da24a60e261a175074cb7aa.zip
Merge branch 'develop' into roster
Diffstat (limited to 'sleekxmpp/test')
-rw-r--r--sleekxmpp/test/livesocket.py12
-rw-r--r--sleekxmpp/test/mocksocket.py14
-rw-r--r--sleekxmpp/test/sleektest.py9
3 files changed, 35 insertions, 0 deletions
diff --git a/sleekxmpp/test/livesocket.py b/sleekxmpp/test/livesocket.py
index 3e0f2135..7dd4693c 100644
--- a/sleekxmpp/test/livesocket.py
+++ b/sleekxmpp/test/livesocket.py
@@ -58,6 +58,18 @@ class TestLiveSocket(object):
# ------------------------------------------------------------------
# Testing Interface
+ def disconnect_errror(self):
+ """
+ Used to simulate a socket disconnection error.
+
+ Not used by live sockets.
+ """
+ try:
+ self.socket.shutdown()
+ self.socket.close()
+ except:
+ pass
+
def next_sent(self, timeout=None):
"""
Get the next stanza that has been sent.
diff --git a/sleekxmpp/test/mocksocket.py b/sleekxmpp/test/mocksocket.py
index e3ddd700..a2af8d6b 100644
--- a/sleekxmpp/test/mocksocket.py
+++ b/sleekxmpp/test/mocksocket.py
@@ -39,6 +39,7 @@ class TestSocket(object):
self.recv_queue = queue.Queue()
self.send_queue = queue.Queue()
self.is_live = False
+ self.disconnected = False
def __getattr__(self, name):
"""
@@ -89,6 +90,13 @@ class TestSocket(object):
"""
self.recv_queue.put(data)
+ def disconnect_error(self):
+ """
+ Simulate a disconnect error by raising a socket.error exception
+ for any current or further socket operations.
+ """
+ self.disconnected = True
+
# ------------------------------------------------------------------
# Socket Interface
@@ -99,6 +107,8 @@ class TestSocket(object):
Arguments:
Placeholders. Same as for socket.Socket.recv.
"""
+ if self.disconnected:
+ raise socket.error
return self.read(block=True)
def send(self, data):
@@ -108,6 +118,8 @@ class TestSocket(object):
Arguments:
data -- String value to write.
"""
+ if self.disconnected:
+ raise socket.error
self.send_queue.put(data)
# ------------------------------------------------------------------
@@ -132,6 +144,8 @@ class TestSocket(object):
timeout -- Time in seconds a block should last before
returning None.
"""
+ if self.disconnected:
+ raise socket.error
if timeout is not None:
block = True
try:
diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py
index 92f467fc..19309fc5 100644
--- a/sleekxmpp/test/sleektest.py
+++ b/sleekxmpp/test/sleektest.py
@@ -285,6 +285,13 @@ class SleekTest(unittest.TestCase):
# ------------------------------------------------------------------
# Methods for simulating stanza streams.
+ def stream_disconnect(self):
+ """
+ Simulate a stream disconnection.
+ """
+ if self.xmpp:
+ self.xmpp.socket.disconnect_error()
+
def stream_start(self, mode='client', skip=True, header=None,
socket='mock', jid='tester@localhost',
password='test', server='localhost',
@@ -353,6 +360,8 @@ class SleekTest(unittest.TestCase):
self.xmpp.process(threaded=True)
if skip:
if socket != 'live':
+ # Mark send queue as usable
+ self.xmpp.session_started_event.set()
# Clear startup stanzas
self.xmpp.socket.next_sent(timeout=1)
if mode == 'component':