How to use the webtest.http.StopableWSGIServer function in WebTest

To help you get started, we’ve selected a few WebTest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github galaxyproject / pulsar / test / test_utils.py View on Github external
def server_for_test_app(app):
    try:
        from paste.exceptions.errormiddleware import ErrorMiddleware
        error_app = ErrorMiddleware(app.app, debug=True, error_log="errors.log")
        server = StopableWSGIServer.create(error_app)
    except ImportError:
        # paste.exceptions not available for Python 3.
        error_app = app.app
        server = StopableWSGIServer.create(error_app)
    try:
        server.wait()
        yield server
    finally:
        server.shutdown()
    # There seem to be persistent transient problems with the testing, sleeping
    # between creation of test app instances for greater than .5 seconds seems
    # to help (async loop length in code is .5 so this maybe makes some sense?)
    if "TEST_WEBAPP_POST_SHUTDOWN_SLEEP" in environ:
        time.sleep(int(environ.get("TEST_WEBAPP_POST_SHUTDOWN_SLEEP")))
github galaxyproject / pulsar / test / test_utils.py View on Github external
def server_for_test_app(app):
    try:
        from paste.exceptions.errormiddleware import ErrorMiddleware
        error_app = ErrorMiddleware(app.app, debug=True, error_log="errors.log")
        server = StopableWSGIServer.create(error_app)
    except ImportError:
        # paste.exceptions not available for Python 3.
        error_app = app.app
        server = StopableWSGIServer.create(error_app)
    try:
        server.wait()
        yield server
    finally:
        server.shutdown()
    # There seem to be persistent transient problems with the testing, sleeping
    # between creation of test app instances for greater than .5 seconds seems
    # to help (async loop length in code is .5 so this maybe makes some sense?)
    if "TEST_WEBAPP_POST_SHUTDOWN_SLEEP" in environ:
        time.sleep(int(environ.get("TEST_WEBAPP_POST_SHUTDOWN_SLEEP")))
github Pylons / webtest / tests / test_http.py View on Github external
def test_shutdown_non_running(self):
        host, port = http.get_free_port()
        s = http.StopableWSGIServer(debug_app, host=host, port=port)
        self.assertFalse(s.wait(retries=-1))
        self.assertTrue(s.shutdown())
github gawel / pyquery / tests / test_pyquery.py View on Github external
def setUp(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/plain')])
            time.sleep(2)
            return [b'foobar\n']
        self.s = http.StopableWSGIServer.create(app)
        self.s.wait()
        self.application_url = self.s.application_url.rstrip('/')
github liqd / adhocracy3 / src / adhocracy_sample / adhocracy_sample / testing.py View on Github external
def backend_sample(request, settings, app_sample):
    """Return a http server with the adhocracy wsgi application."""
    port = settings['port']
    backend = StopableWSGIServer.create(app_sample, port=port)
    request.addfinalizer(backend.shutdown)
    return backend
github Pylons / webtest / webtest / http.py View on Github external
def __init__(self, application, *args, **kwargs):
        super(StopableWSGIServer, self).__init__(self.wrapper, *args, **kwargs)
        self.runner = None
        self.test_app = application
        self.application_url = 'http://%s:%s/' % (self.adj.host, self.adj.port)
github gawel / pyquery / docs / ajax_fixt.py View on Github external
def setup_test(test):
    for example in test.examples:
        # urlopen as moved in py3
        if PY3:
            example.options.setdefault(SKIP, 1)
    if not PY3:
        server = http.StopableWSGIServer.create(input_app)
        server.wait()
        path_to_html_file = os.path.join('tests', 'test.html')
        test.globs.update(
            input_app=input_app,
            server=server,
            your_url=server.application_url.rstrip('/') + '/html',
            path_to_html_file=path_to_html_file,
        )
github gawel / pyquery / README_fixt.py View on Github external
def setup_test(test):
    server = http.StopableWSGIServer.create(debug_app)
    server.wait()
    path_to_html_file = os.path.join('tests', 'test.html')
    test.globs.update(
        urlopen=urlopen,
        server=server,
        your_url=server.application_url,
        path_to_html_file=path_to_html_file,
    )
github gawel / pyquery / docs / scrap_fixt.py View on Github external
def setup_test(test):
    server = http.StopableWSGIServer.create(input_app)
    server.wait()
    test.globs.update(
        server=server,
        your_url=server.application_url.rstrip('/') + '/html',
    )