Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _trace_app(self, tracer=None):
self.app = webtest.TestApp(self.app)
('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), {})
def test_testsuite_works1(self):
jsapp = webtest.TestApp(
app.main(
packages = "pwt.jinja2js",
)
)
self.assertEqual(jsapp.get("/").status_int, 200)
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
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
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)
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!'
def test_testbody(self):
app = webtest.TestApp(debug_app)
res = app.post('/')
res.charset = 'utf8'
res.body = 'été'.encode('latin1')
res.testbody
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)
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