Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _gen_request(self, method, url, params=utils.NoDefault,
headers=None, extra_environ=None, status=None,
upload_files=None, expect_errors=False,
content_type=None, auth=None, auth_type=None, **kwargs):
"""Do a generic request.
"""
return super(TestApp, self)._gen_request(method=method,
url=url,
params=params,
headers=self._build_headers(
headers, auth, auth_type),
extra_environ=extra_environ,
status=status,
upload_files=upload_files,
expect_errors=expect_errors,
content_type=content_type,
**kwargs)
pass
res.errors = errors.getvalue()
for name, value in req.environ['paste.testing_variables'].items():
if hasattr(res, name):
raise ValueError(
"paste.testing_variables contains the variable %r, but "
"the response object already has an attribute by that "
"name" % name)
setattr(res, name, value)
if not expect_errors:
self._check_status(status, res)
self._check_errors(res)
# merge cookies back in
self.cookiejar.extract_cookies(utils._ResponseCookieAdapter(res),
utils._RequestCookieAdapter(req))
return res
def head(self, url, headers=None, extra_environ=None,
status=None, expect_errors=False, xhr=False):
"""
Do a HEAD request. Similar to :meth:`~webtest.TestApp.get`.
:returns: :class:`webtest.TestResponse` instance.
"""
if xhr:
headers = self._add_xhr_header(headers)
return self._gen_request('HEAD', url, headers=headers,
extra_environ=extra_environ, status=status,
upload_files=None,
expect_errors=expect_errors)
post_json = utils.json_method('POST')
put_json = utils.json_method('PUT')
patch_json = utils.json_method('PATCH')
delete_json = utils.json_method('DELETE')
def encode_multipart(self, params, files):
"""
Encodes a set of parameters (typically a name/value list) and
a set of files (a list of (name, filename, file_body, mimetype)) into a
typical POST body, returning the (content_type, body).
"""
boundary = to_bytes(str(random.random()))[2:]
boundary = b'----------a_BoUnDaRy' + boundary + b'$'
lines = []
def _append_file(file_info):
def test_stringify_text(self):
self.assertEqual(utils.stringify("foo"), "foo")
def delete(self, url, params=utils.NoDefault, headers=None,
extra_environ=None, status=None, expect_errors=False,
content_type=None, xhr=False, auth=None, auth_type=None, **kwargs):
return super(TestApp, self).delete(
url=url, params=params,
headers=self._build_headers(headers, auth, auth_type),
extra_environ=extra_environ,
status=status,
expect_errors=expect_errors,
content_type=content_type, xhr=xhr, **kwargs)