diff options
| author | Gael Pasgrimaud <gael@gawel.org> | 2013-01-29 12:35:37 +0100 |
|---|---|---|
| committer | Gael Pasgrimaud <gael@gawel.org> | 2013-01-29 12:35:37 +0100 |
| commit | 52f8ebde1ee30e7c7b3680f5e98c558c227c05bf (patch) | |
| tree | 4cff57c58d8caebad355e237e699ae207b8bc090 /docs | |
| parent | ec735dd8cd79aacac5b8533281f23a6f08b3cf01 (diff) | |
| download | webtest-52f8ebde1ee30e7c7b3680f5e98c558c227c05bf.tar.gz | |
add quick start
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/index.txt | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/docs/index.txt b/docs/index.txt index 10b8824..48ce7e8 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -59,6 +59,47 @@ ensure the entire programming system works together. WebTest helps you create tests by providing a convenient interface to run WSGI applications and verify the output. +Quick start +=========== + +The main class it :class:`webtest.TestApp` which wrap your WSGI application and +allow you to perform HTTP request on it. + +Here is a basic application:: + + >>> def application(environ, start_response): + ... headers = [('Content-Type', 'text/html; charset=utf8'), + ... ('Content-Length', str(len(body)))] + ... start_response('200 Ok', headers) + ... return [body] + +Wrap it into a :class:`webtest.TestApp`:: + + >>> from webtest import TestApp + >>> app = TestApp(application) + +Then you can get the response of a HTTP GET:: + + >>> resp = app.get('/') + +And check the result. Like like reponse's status:: + + >>> assert resp.status == '200 Ok' + >>> assert resp.status_int == 200 + +Response's headers:: + + >>> assert resp.content_type == 'text/html' + >>> assert resp.content_length > 0 + +Or response's body:: + + >>> resp.mustcontain('<html>') + >>> assert 'form' in resp + +WebTest can do much more. In particular it can handle :doc:`forms` and :doc:`json`. + + Contents ======== |
