Skip to content
Myr

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

1 file+6 added−6 removed

modified:docs/testing.rst+6 added-6 removed
6 unmodified lines
78Not sure where that is coming from, and it's not entirely correct, but9also not that far from the truth. Untested applications make it hard to10improve existing code and developers of untested applications tend to11become pretty paranoid. If an application however has automated tests, you12can safely change things and you will instantly know if your change broke11become pretty paranoid. If an application has automated tests, you can12safely change things, and you will instantly know if your change broke13something.1415Flask gives you a couple of ways to test applications. It mainly does16that by exposing the Werkzeug test :class:`~werkzeug.Client` class to your
42 unmodified lines
59each individual test function. To delete the database after the test, we60close the file and remove it from the filesystem in the61:meth:`~unittest.TestCase.tearDown` method. What the test client does is62give us a simple interface to the application. We can trigger test63requests to the application and the client will also keep track of cookies63requests to the application, and the client will also keep track of cookies64for us.6566Because SQLite3 is filesystem-based we can easily use the tempfile module67to create a temporary database and initialize it. The
61 unmodified lines
129Logging In and Out130------------------131132The majority of the functionality of our application is only available for133the administration user. So we need a way to log our test client in to the133the administrative user, so we need a way to log our test client in to the134application and out of it again. For that we fire some requests to the135login and logout pages with the required form data (username and136password). Because the login and logout pages redirect, we tell the137client to `follow_redirects`.
61 unmodified lines
199200Other Testing Tricks201--------------------202203Besides using the test client we used above there is also the203Besides using the test client we used above, there is also the204:meth:`~flask.Flask.test_request_context` method that in combination with205the `with` statement can be used to activate a request context206temporarily. With that you can access the :class:`~flask.request`,207:class:`~flask.g` and :class:`~flask.session` objects like in view208functions. Here a full example that showcases this::208functions. Here's a full example that showcases this::209210 app = flask.Flask(__name__)211212 with app.test_request_context('/?name=Peter'):
32 unmodified lines