Added testing documentation
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent ef524f2 · Browse files · 3 files·+41 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+41 added−12 removed
- other:+41 added−12 removed
Provenance
- Commit
03148db- Tree
74b96e4- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
ef524f2
3 files changed+41 added−12 removed
modified:docs/api.rst+16 added
17 unmodified lines18 19 Incoming Request Data20 ---------------------21 22+.. autoclass:: Request23+24 .. class:: request25 26 To access incoming request data, you can use the global `request`27 object. Flask parses incoming request data for you and gives you77 unmodified lines105 `base_url` ``http://www.example.com/myapplication/page.html?x=y``106 `root_url` ``http://www.example.com/myapplication/``107 ============= ======================================================108 109+Response Objects110+----------------111 112+.. autoclass:: flask.Response113+ :members: set_cookie, data, mimetype114+115+ .. attribute:: headers116+117+ A :class:`Headers` object representing the response headers.118+119+ .. attribute:: status_code120+121+ The response status as integer.122+123+124 Sessions125 --------126 127 If you have the :attr:`Flask.secret_key` set you can use sessions in Flask82 unmodified linesmodified:docs/index.rst+1 added
19 unmodified lines20 quickstart21 patterns22 api23 deploying24+ testing25 becomingbigmodified:flask.py+24 added-12 removed
13 unmodified lines14 import pkg_resources15 from threading import local16 from contextlib import contextmanager17 from jinja2 import Environment, PackageLoader18-from werkzeug import Request, Response, LocalStack, LocalProxy, \19- create_environ, cached_property18+from werkzeug import Request as RequestBase, Response as ResponseBase, \19+ LocalStack, LocalProxy, create_environ, cached_property20 from werkzeug.routing import Map, Rule21 from werkzeug.exceptions import HTTPException, InternalServerError22 from werkzeug.contrib.securecookie import SecureCookie23 2 unmodified lines26 from werkzeug import abort, redirect27 from jinja2 import Markup, escape28 29 30-class FlaskRequest(Request):30+class Request(RequestBase):31 """The request object used by default in flask. Remembers the32 matched endpoint and view arguments.33+34+ It is what ends up as :class:`~flask.request`. If you want to replace35+ the request object used you can subclass this and set36+ :attr:`~flask.Flask.request_class` to your subclass.37 """38 39 def __init__(self, environ):36- Request.__init__(self, environ)40+ RequestBase.__init__(self, environ)41 self.endpoint = None42 self.view_args = None43 44 41-class FlaskResponse(Response):45+class Response(ResponseBase):46 """The response object that is used by default in flask. Works like the47 response object from Werkzeug but is set to have a HTML mimetype by44- default.48+ default. Quite often you don't have to create this object yourself because49+ :meth:`~flask.Flask.make_response` will take care of that for you.50+51+ If you want to replace the response object used you can subclass this and52+ set :attr:`~flask.Flask.request_class` to your subclass.53 """54 default_mimetype = 'text/html'55 56 92 unmodified lines149 from flask import Flask150 app = Flask(__name__)151 """152 145- #: the class that is used for request objects146- request_class = FlaskRequest153+ #: the class that is used for request objects. See :class:`~flask.request`154+ #: for more information.155+ request_class = Request156 148- #: the class that is used for response objects149- response_class = FlaskResponse157+ #: the class that is used for response objects. See158+ #: :class:`~flask.Response` for more information.159+ response_class = Response160 161 #: path for the static files. If you don't want to use static files162 #: you can set this value to `None` in which case no URL rule is added163 #: and the development server will no longer serve any static files.111 unmodified lines275 options.setdefault('use_debugger', self.debug)276 return run_simple(host, port, self, **options)277 278 def test_client(self):269- """Creates a test client for this application"""279+ """Creates a test client for this application. For information280+ about unit testing head over to :ref:`testing`.281+ """282 from werkzeug import Client283 return Client(self, self.response_class, use_cookies=True)284 285 def open_resource(self, resource):81 unmodified lines367 return 'Hello World'368 369 Variables parts in the route can be specified with angular370 brackets (``/user/<username>``). By default a variable part359- in the URL accepts any string without a slash however a differnt371+ in the URL accepts any string without a slash however a different372 converter can be specified as well by using ``<converter:name>``.373 374 Variable parts are passed to the view function as keyword375 arguments.230 unmodified lines