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 |
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
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 |
|||
) |
def webtest.app.TestApp._add_xhr_header | ( | headers | ) | [static, private] |
def webtest.app.TestApp._check_errors | ( | self, | |
res | |||
) | [private] |
def webtest.app.TestApp._check_status | ( | self, | |
status, | |||
res | |||
) | [private] |
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] |
def webtest.app.TestApp._get_file_info | ( | self, | |
file_info | |||
) | [private] |
def webtest.app.TestApp._make_environ | ( | self, | |
extra_environ = None |
|||
) | [private] |
def webtest.app.TestApp._remove_fragment | ( | self, | |
url | |||
) | [private] |
def webtest.app.TestApp.cookies | ( | self | ) |
def webtest.app.TestApp.delete | ( | self, | |
url, | |||
params = '' , |
|||
headers = None , |
|||
extra_environ = None , |
|||
status = None , |
|||
expect_errors = False , |
|||
content_type = None , |
|||
xhr = False |
|||
) |
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.
def webtest.app.TestApp.encode_multipart | ( | self, | |
params, | |||
files | |||
) |
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.
def webtest.app.TestApp.get_authorization | ( | self | ) |
def webtest.app.TestApp.head | ( | self, | |
url, | |||
headers = None , |
|||
extra_environ = None , |
|||
status = None , |
|||
expect_errors = False , |
|||
xhr = False |
|||
) |
def webtest.app.TestApp.options | ( | self, | |
url, | |||
headers = None , |
|||
extra_environ = None , |
|||
status = None , |
|||
expect_errors = False , |
|||
xhr = False |
|||
) |
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 |
|||
) |
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.
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 |
|||
) |
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)
def webtest.app.TestApp.reset | ( | self | ) |
def webtest.app.TestApp.set_authorization | ( | self, | |
value | |||
) |
def webtest.app.TestApp.set_cookie | ( | self, | |
name, | |||
value | |||
) |
def webtest.app.TestApp.set_parser_features | ( | self, | |
parser_features | |||
) |
tuple webtest::app.TestApp::delete_json = utils.json_method('DELETE') [static] |
tuple webtest::app.TestApp::patch_json = utils.json_method('PATCH') [static] |
tuple webtest::app.TestApp::post_json = utils.json_method('POST') [static] |
tuple webtest::app.TestApp::put_json = utils.json_method('PUT') [static] |
webtest::app.TestApp::RequestClass = TestRequest [static] |
webtest::app.TestApp::authorization = property(get_authorization, set_authorization) [static] |