How to use the webtest.TestApp 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 DataDog / dd-trace-py / tests / contrib / bottle / test_autopatch.py View on Github external
def _trace_app(self, tracer=None):
        self.app = webtest.TestApp(self.app)
github Pylons / webtest / tests / test_app.py View on Github external
('Content-Type', 'text/plain'),
                ('Content-Length', str(len(body))),
                ('Set-Cookie',
                 'spam=eggs; secure; Domain=.example.org;'),
            ]
            start_response(status, headers)
            return [to_bytes(body)]

        policy = webtest.app.CookiePolicy()
        flags = (
            policy.DomainStrictNoDots |
            policy.DomainRFC2965Match |
            policy.DomainStrictNonDomain)
        policy.strict_ns_domain |= flags
        cookiejar = http_cookiejar.CookieJar(policy=policy)
        app = webtest.TestApp(
            cookie_app,
            cookiejar=cookiejar,
            extra_environ={'HTTP_HOST': 'example.org'})
        res = app.get('/')
        res = app.get('/')
        self.assertFalse(app.cookies,
                        'Response should not have set cookies')
        self.assertNotIn('HTTP_COOKIE', res.request.environ)
        self.assertEqual(dict(res.request.cookies), {})
github mkerrin / pwt.jinja2js / src / pwt / jinja2js / tests.py View on Github external
def test_testsuite_works1(self):
        jsapp = webtest.TestApp(
            app.main(
                packages = "pwt.jinja2js",
                )
            )

        self.assertEqual(jsapp.get("/").status_int, 200)
github fdev31 / drink / tests / features / terrain.py View on Github external
from lettuce import world
import logging
import subprocess
import webtest
import os, sys
sys.path.insert(0, os.pardir)
import drink

world.www = webtest.TestApp(drink.make_app())
VERBOSE=False

import os
#from lettuce import after

#@after.each_step
#def apply_pdb_if_not_in_ciserver(step):
#    if 'CI_SERVER' in os.environ:
#        return
#
#    has_traceback = step.why
#
#    if not has_traceback:
#        return
#
#    import pdb
github TurboGears / tg2 / tg / test_stack / __init__.py View on Github external
def app_from_config(base_config, deployment_config=None):
    if not deployment_config:
        deployment_config = {'debug': 'true',
                             'error_email_from': 'paste@localhost',
                             'smtp_server': 'localhost'}

    env_loader = base_config.make_load_environment()
    app_maker = base_config.setup_tg_wsgi_app(env_loader)
    app = TestApp(app_maker(deployment_config, full_stack=True))
    return app
github anomaly / prestans / tests / issues / test_issue155.py View on Github external
def test_app():
    from webtest import TestApp
    from prestans.rest import RequestRouter

    api = RequestRouter([
        ('/auth', AuthHandler),
        ('/no-auth', NoAuthHandler)
    ], application_name="api", debug=True)

    return TestApp(app=api)
github pecan / pecan / tests / test_base.py View on Github external
def test_simple_app(self):    
        class RootController(object):
            @expose()
            def index(self):
                return 'Hello, World!'
        
        app = TestApp(Pecan(RootController()))
        r = app.get('/')
        assert r.status_int == 200
        assert r.body == 'Hello, World!'
        
        r = app.get('/index')
        assert r.status_int == 200
        assert r.body == 'Hello, World!'
        
        r = app.get('/index.html')
        assert r.status_int == 200
        assert r.body == 'Hello, World!'
github Pylons / webtest / tests / test_response.py View on Github external
def test_testbody(self):
        app = webtest.TestApp(debug_app)
        res = app.post('/')
        res.charset = 'utf8'
        res.body = 'été'.encode('latin1')
        res.testbody
github ymyzk / wsgi_lineprof / benchmarks / benchmarks.py View on Github external
def prepare_app(app, profiler, filters=None):
    if filters is None:
        filters = []

    if profiler == "sync":
        app = LineProfilerMiddleware(app,
                                     filters=filters,
                                     stream=StringNoopIO())
    elif profiler == "async":
        app = LineProfilerMiddleware(app,
                                     filters=filters,
                                     stream=StringNoopIO(),
                                     async_stream=True)
    return TestApp(app)
github anybox / buttervolume / buttervolume / cli.py View on Github external
def sync(args, test=False):
    urlpath = '/VolumeDriver.Volume.Sync'
    param = {'Volumes': args.volumes, 'Hosts': args.hosts}
    if test:
        param['Test'] = True
        resp = TestApp(app).post(urlpath, json.dumps(param))
    else:
        resp = Session().post(
            'http+unix://{}{}'
            .format(urllib.parse.quote_plus(USOCKET), urlpath),
            json.dumps(param))
    res = get_from(resp, '')
    if res:
        print(res)
    return res