Permalink
Browse files

Add FakeConnection to ease testing

  • Loading branch information...
1 parent a9553b1 commit 1ea16219b76a1b19e6de7733354e1b8905f70d0a @schmichael schmichael committed Mar 26, 2012
Showing with 33 additions and 0 deletions.
  1. +33 −0 kiddiepool.py
View
@@ -1,3 +1,4 @@
+# Copyright 2012 Urban Airship
import collections
import Queue as queue
import random
@@ -298,3 +299,35 @@ def _sendall(self, request, attempts=None):
raise self.SendException(
'Failed to send request (%d bytes) after %d attempts. '
'Last exception: %r' % (len(request), attempts, e))
+
+
+class FakeConnection(object):
+ """Connection class for testing (noops)"""
+ def __init__(self, *args, **kwargs):
+ self.host = kwargs.get('host', 'localhost')
+ self.port = kwargs.get('port', 9000)
+ self.closed = kwargs.get('closed', False)
+
+ def connect(self, host, port):
+ self.host = host
+ self.port = port
+ return True
+
+ def close(self):
+ self.closed = True
+
+ def sendall(self, payload):
+ pass
+
+ def recv(self, size, flags=0):
+ return ''
+
+ def recvall(self, size):
+ return ''
+
+ def handle_exception(self, e):
+ if isinstance(e, socket.error):
+ self.close()
+
+ def validate(self):
+ return True

0 comments on commit 1ea1621

Please sign in to comment.