Public Member Functions | Public Attributes | Static Public Attributes | Properties | Private Member Functions | Static Private Member Functions
webtest.app.TestApp Class Reference

List of all members.

Public Member Functions

def __init__
def cookies
def delete
def do_request
def encode_multipart
def get
def get_authorization
def head
def options
def patch
def post
def put
def request
def reset
def set_authorization
def set_cookie
def set_parser_features

Public Attributes

 app
 authorization_value
 cookiejar
 extra_environ
 JSONEncoder
 lint
 relative_to
 use_unicode

Static Public Attributes

tuple delete_json = utils.json_method('DELETE')
tuple patch_json = utils.json_method('PATCH')
tuple post_json = utils.json_method('POST')
tuple put_json = utils.json_method('PUT')
 RequestClass = TestRequest

Properties

 authorization = property(get_authorization, set_authorization)

Private Member Functions

def _check_errors
def _check_status
def _gen_request
def _get_file_info
def _make_environ
def _remove_fragment

Static Private Member Functions

def _add_xhr_header

Detailed Description

Wraps a WSGI application in a more convenient interface for
testing. It uses extended version of :class:`webob.BaseRequest`
and :class:`webob.Response`.

:param app:
    May be an WSGI application or Paste Deploy app,
    like ``'config:filename.ini#test'``.

    .. versionadded:: 2.0

    It can also be an actual full URL to an http server and webtest
    will proxy requests with `wsgiproxy`.
:type app:
    WSGI application
:param extra_environ:
    A dictionary of values that should go
    into the environment for each request. These can provide a
    communication channel with the application.
:type extra_environ:
    dict
:param relative_to:
    A directory used for file
    uploads are calculated relative to this.  Also ``config:``
    URIs that aren't absolute.
:type relative_to:
    string
:param cookiejar:
    :class:`cookielib.CookieJar` alike API that keeps cookies
    across requets.
:type cookiejar:
    CookieJar instance

.. attribute:: cookies

    A convenient shortcut for a dict of all cookies in
    ``cookiejar``.

:param parser_features:
    Passed to BeautifulSoup when parsing responses.
:type parser_features:
    string or list
:param json_encoder:
    Passed to json.dumps when encoding json
:type json_encoder:
    A subclass of json.JSONEncoder
:param lint:
    If True (default) then check that the application is WSGI compliant
:type lint:
    A boolean

Definition at line 89 of file app.py.


Constructor & Destructor Documentation

def webtest.app.TestApp.__init__ (   self,
  app,
  extra_environ = None,
  relative_to = None,
  use_unicode = True,
  cookiejar = None,
  parser_features = None,
  json_encoder = None,
  lint = True 
)

Definition at line 144 of file app.py.


Member Function Documentation

def webtest.app.TestApp._add_xhr_header (   headers) [static, private]

Definition at line 765 of file app.py.

def webtest.app.TestApp._check_errors (   self,
  res 
) [private]

Definition at line 668 of file app.py.

def webtest.app.TestApp._check_status (   self,
  status,
  res 
) [private]

Definition at line 640 of file app.py.

def webtest.app.TestApp._gen_request (   self,
  method,
  url,
  params = utils.NoDefault,
  headers = None,
  extra_environ = None,
  status = None,
  upload_files = None,
  expect_errors = False,
  content_type = None 
) [private]
Do a generic request.

Definition at line 685 of file app.py.

def webtest.app.TestApp._get_file_info (   self,
  file_info 
) [private]

Definition at line 737 of file app.py.

def webtest.app.TestApp._make_environ (   self,
  extra_environ = None 
) [private]

Definition at line 674 of file app.py.

def webtest.app.TestApp._remove_fragment (   self,
  url 
) [private]

Definition at line 681 of file app.py.

Definition at line 221 of file app.py.

def webtest.app.TestApp.delete (   self,
  url,
  params = '',
  headers = None,
  extra_environ = None,
  status = None,
  expect_errors = False,
  content_type = None,
  xhr = False 
)
Do a DELETE request. Similar to :meth:`~webtest.TestApp.get`.

:returns: :class:`webtest.TestResponse` instance.

Definition at line 407 of file app.py.

def webtest.app.TestApp.do_request (   self,
  req,
  status = None,
  expect_errors = None 
)
Executes the given webob Request (``req``), with the expected
``status``.  Generally :meth:`~webtest.TestApp.get` and
:meth:`~webtest.TestApp.post` are used instead.

To use this::

    req = webtest.TestRequest.blank('url', ...args...)
    resp = app.do_request(req)

.. note::

    You can pass any keyword arguments to
    ``TestRequest.blank()``, which will be set on the request.
    These can be arguments like ``content_type``, ``accept``, etc.

Definition at line 569 of file app.py.

def webtest.app.TestApp.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).

Definition at line 459 of file app.py.

def webtest.app.TestApp.get (   self,
  url,
  params = None,
  headers = None,
  extra_environ = None,
  status = None,
  expect_errors = False,
  xhr = False 
)
Do a GET request given the url path.

:param params:
    A query string, or a dictionary that will be encoded
    into a query string.  You may also include a URL query
    string on the ``url``.
:param headers:
    Extra headers to send.
:type headers:
    dictionary
:param extra_environ:
    Environmental variables that should be added to the request.
:type extra_environ:
    dictionary
:param status:
    The HTTP status code you expect in response (if not 200 or 3xx).
    You can also use a wildcard, like ``'3*'`` or ``'*'``.
:type status:
    integer or string
:param expect_errors:
    If this is False, then if anything is written to
    environ ``wsgi.errors`` it will be an error.
    If it is True, then non-200/3xx responses are also okay.
:type expect_errors:
    boolean
:param xhr:
    If this is true, then marks response as ajax. The same as
    headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }
:type xhr:
    boolean

:returns: :class:`webtest.TestResponse` instance.

Definition at line 264 of file app.py.

Allow to set the HTTP_AUTHORIZATION environ key. Value should looks
like ``('Basic', ('user', 'password'))``

If value is None the the HTTP_AUTHORIZATION is removed

Definition at line 185 of file app.py.

def webtest.app.TestApp.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.

Definition at line 439 of file app.py.

def webtest.app.TestApp.options (   self,
  url,
  headers = None,
  extra_environ = None,
  status = None,
  expect_errors = False,
  xhr = False 
)
Do a OPTIONS request. Similar to :meth:`~webtest.TestApp.get`.

:returns: :class:`webtest.TestResponse` instance.

Definition at line 424 of file app.py.

def webtest.app.TestApp.patch (   self,
  url,
  params = '',
  headers = None,
  extra_environ = None,
  status = None,
  upload_files = None,
  expect_errors = False,
  content_type = None,
  xhr = False 
)
Do a PATCH request. Similar to :meth:`~webtest.TestApp.post`.

:returns: :class:`webtest.TestResponse` instance.

Definition at line 390 of file app.py.

def webtest.app.TestApp.post (   self,
  url,
  params = '',
  headers = None,
  extra_environ = None,
  status = None,
  upload_files = None,
  expect_errors = False,
  content_type = None,
  xhr = False 
)
Do a POST request. Similar to :meth:`~webtest.TestApp.get`.

:param params:
    Are put in the body of the request. If params is a
    iterator it will be urlencoded, if it is string it will not
    be encoded, but placed in the body directly.

    Can be a collections.OrderedDict with
    :class:`webtest.forms.Upload` fields included::


    app.post('/myurl', collections.OrderedDict([
('textfield1', 'value1'),
('uploadfield', webapp.Upload('filename.txt', 'contents'),
('textfield2', 'value2')])))

:param upload_files:
    It should be a list of ``(fieldname, filename, file_content)``.
    You can also use just ``(fieldname, filename)`` and the file
    contents will be read from disk.
:type upload_files:
    list
:param content_type:
    HTTP content type, for example `application/json`.
:type content_type:
    string

:param xhr:
    If this is true, then marks response as ajax. The same as
    headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }
:type xhr:
    boolean

:returns: :class:`webtest.TestResponse` instance.

Definition at line 324 of file app.py.

def webtest.app.TestApp.put (   self,
  url,
  params = '',
  headers = None,
  extra_environ = None,
  status = None,
  upload_files = None,
  expect_errors = False,
  content_type = None,
  xhr = False 
)
Do a PUT request. Similar to :meth:`~webtest.TestApp.post`.

:returns: :class:`webtest.TestResponse` instance.

Definition at line 372 of file app.py.

def webtest.app.TestApp.request (   self,
  url_or_req,
  status = None,
  expect_errors = False,
  req_params 
)
Creates and executes a request. You may either pass in an
instantiated :class:`TestRequest` object, or you may pass in a
URL and keyword arguments to be passed to
:meth:`TestRequest.blank`.

You can use this to run a request without the intermediary
functioning of :meth:`TestApp.get` etc.  For instance, to
test a WebDAV method::

    resp = app.request('/new-col', method='MKCOL')

Note that the request won't have a body unless you specify it,
like::

    resp = app.request('/test.txt', method='PUT', body='test')

You can use :class:`webtest.TestRequest`::

    req = webtest.TestRequest.blank('/url/', method='GET')
    resp = app.do_request(req)

Definition at line 525 of file app.py.

def webtest.app.TestApp.reset (   self)
Resets the state of the application; currently just clears
saved cookies.

Definition at line 250 of file app.py.

def webtest.app.TestApp.set_authorization (   self,
  value 
)

Definition at line 193 of file app.py.

def webtest.app.TestApp.set_cookie (   self,
  name,
  value 
)
Sets a cookie to be passed through with requests.

Definition at line 224 of file app.py.

def webtest.app.TestApp.set_parser_features (   self,
  parser_features 
)
Changes the parser used by BeautifulSoup. See its documentation to
know the supported parsers.

Definition at line 257 of file app.py.


Member Data Documentation

Definition at line 144 of file app.py.

Definition at line 193 of file app.py.

Definition at line 144 of file app.py.

Definition at line 457 of file app.py.

Definition at line 144 of file app.py.

Definition at line 144 of file app.py.

Definition at line 144 of file app.py.

Definition at line 456 of file app.py.

Definition at line 454 of file app.py.

Definition at line 455 of file app.py.

Definition at line 144 of file app.py.

Definition at line 142 of file app.py.

Definition at line 144 of file app.py.


Property Documentation

Definition at line 218 of file app.py.


The documentation for this class was generated from the following file:


webtest
Author(s): AlexV
autogenerated on Sat Jun 8 2019 20:32:07