Skip to content
Myr

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

3 files+41 added−12 removed

modified:docs/api.rst+16 added
17 unmodified lines
1819Incoming Request Data20---------------------2122.. autoclass:: Request2324.. class:: request2526 To access incoming request data, you can use the global `request`27 object. Flask parses incoming request data for you and gives you
77 unmodified lines
105 `base_url` ``http://www.example.com/myapplication/page.html?x=y``106 `root_url` ``http://www.example.com/myapplication/``107 ============= ======================================================108109Response Objects110----------------111112.. autoclass:: flask.Response113 :members: set_cookie, data, mimetype114115 .. attribute:: headers116117 A :class:`Headers` object representing the response headers.118119 .. attribute:: status_code120121 The response status as integer.122123124Sessions125--------126127If you have the :attr:`Flask.secret_key` set you can use sessions in Flask
82 unmodified lines
modified:docs/index.rst+1 added
19 unmodified lines
20 quickstart21 patterns22 api23 deploying24 testing25 becomingbig
modified:flask.py+24 added-12 removed
13 unmodified lines
14import pkg_resources15from threading import local16from contextlib import contextmanager17from jinja2 import Environment, PackageLoader18from werkzeug import Request, Response, LocalStack, LocalProxy, \19 create_environ, cached_property18from werkzeug import Request as RequestBase, Response as ResponseBase, \19 LocalStack, LocalProxy, create_environ, cached_property20from werkzeug.routing import Map, Rule21from werkzeug.exceptions import HTTPException, InternalServerError22from werkzeug.contrib.securecookie import SecureCookie23
2 unmodified lines
26from werkzeug import abort, redirect27from jinja2 import Markup, escape282930class FlaskRequest(Request):30class Request(RequestBase):31 """The request object used by default in flask. Remembers the32 matched endpoint and view arguments.3334 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 """3839 def __init__(self, environ):36 Request.__init__(self, environ)40 RequestBase.__init__(self, environ)41 self.endpoint = None42 self.view_args = None434441class FlaskResponse(Response):45class 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.5051 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'5556
92 unmodified lines
149 from flask import Flask150 app = Flask(__name__)151 """152145 #: 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 = Request156148 #: 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 = Response160161 #: 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 lines
275 options.setdefault('use_debugger', self.debug)276 return run_simple(host, port, self, **options)277278 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)284285 def open_resource(self, resource):
81 unmodified lines
367 return 'Hello World'368369 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>``.373374 Variable parts are passed to the view function as keyword375 arguments.
230 unmodified lines