Skip to content

Commit

Permalink
Add a FakeProxy to ease the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed Nov 14, 2012
1 parent af0cef1 commit 66257c2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Empty file added vaurien/tests/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions vaurien/tests/support.py
@@ -0,0 +1,36 @@
import sys

from vaurien.webserver import create_app

from gevent.wsgi import WSGIServer


class FakeProxy(object):
"""Fake proxy object, to mock the proxy in the tests"""

def __init__(self, handlers=None):
self.handlers = handlers or ['default', 'blackout']
self.handler = 'default'

def get_handler(self):
# return None as a callable, since this is for tests only.
return None, self.handler

def set_handler(self, name, **options):
self.handler = name

def get_handler_names(self):
return self.handlers


def start_vaurien_httpserver(port):
"""Start a vaurien httpserver, controlling a fake proxy"""
app = create_app()
setattr(app, 'proxy', FakeProxy())

server = WSGIServer(('localhost', int(port)), app)
server.serve_forever()


if __name__ == '__main__':
start_vaurien_httpserver(int(sys.argv[1]))

0 comments on commit 66257c2

Please sign in to comment.