Minor testing documentation fixes (grammar, etc)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Adam Zapletal · committed by Armin Ronacher · parent 5ede530 · Browse files · 1 file·+6 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+6 added−6 removed
- other:+6 added−6 removed
Provenance
- Commit
505c530- Tree
220139f- Author
Adam Zapletal <adamzap@gmail.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
5ede530
1 file changed+6 added−6 removed
modified:docs/testing.rst+6 added-6 removed
6 unmodified lines7 8 Not sure where that is coming from, and it's not entirely correct, but9 also not that far from the truth. Untested applications make it hard to10 improve existing code and developers of untested applications tend to11-become pretty paranoid. If an application however has automated tests, you12-can safely change things and you will instantly know if your change broke11+become pretty paranoid. If an application has automated tests, you can12+safely change things, and you will instantly know if your change broke13 something.14 15 Flask gives you a couple of ways to test applications. It mainly does16 that by exposing the Werkzeug test :class:`~werkzeug.Client` class to your42 unmodified lines59 each individual test function. To delete the database after the test, we60 close the file and remove it from the filesystem in the61 :meth:`~unittest.TestCase.tearDown` method. What the test client does is62 give us a simple interface to the application. We can trigger test63-requests to the application and the client will also keep track of cookies63+requests to the application, and the client will also keep track of cookies64 for us.65 66 Because SQLite3 is filesystem-based we can easily use the tempfile module67 to create a temporary database and initialize it. The61 unmodified lines129 Logging In and Out130 ------------------131 132 The majority of the functionality of our application is only available for133-the administration user. So we need a way to log our test client in to the133+the administrative user, so we need a way to log our test client in to the134 application and out of it again. For that we fire some requests to the135 login and logout pages with the required form data (username and136 password). Because the login and logout pages redirect, we tell the137 client to `follow_redirects`.61 unmodified lines199 200 Other Testing Tricks201 --------------------202 203-Besides using the test client we used above there is also the203+Besides using the test client we used above, there is also the204 :meth:`~flask.Flask.test_request_context` method that in combination with205 the `with` statement can be used to activate a request context206 temporarily. With that you can access the :class:`~flask.request`,207 :class:`~flask.g` and :class:`~flask.session` objects like in view208-functions. Here a full example that showcases this::208+functions. Here's a full example that showcases this::209 210 app = flask.Flask(__name__)211 212 with app.test_request_context('/?name=Peter'):32 unmodified lines