drakken.mock module

Mock objects for testing.

class drakken.mock.Client(prefix, app)

Bases: object

Mock web browser, sends requests to app and receives responses.

For simplicity it talks directly to the WSGI app instead of through a web server like gunicorn.

delete(url, **kwargs)
get(url, **kwargs)
get_environ(url, method, json, data)

Return environ dict for this URL.

handle_request(method, url, allow_redirects=True, headers={}, json={}, data={})

Handle request.

Parameters:
  • method (str) – ‘DELETE’, ‘GET’, ‘PATCH’, ‘POST’, ‘PUT’.

  • url (str) – URL.

  • allow_redirects – (bool). Default: True.

  • headers (dict) – client headers. Default: {}

  • json (dict) – JSON data. Default: {}

  • data (dict) – form data. Default: {}

Returns:

mock.Response object.

patch(url, **kwargs)
post(url, **kwargs)
put(url, **kwargs)
xform(name)

Convert header name to uppercase.

class drakken.mock.Response(url)

Bases: object

Wrapper of all info returned by server.

history = []
load(content)
start_response(status, response_headers, exc_info=None)

Callback function to send HTTP status and headers to server.

drakken.mock.cookie2environ(cookies)

Convert to cookie (dict) to environ (dict).

Returns:

{‘HTTP_COOKIE’: ‘name1=val1; name2=val2…’}

Return type:

dict

drakken.mock.header2cookie(header)

Convert header (str) to cookie (dict)