diff options
| author | Gael Pasgrimaud <gael@gawel.org> | 2018-09-22 12:42:07 +0200 |
|---|---|---|
| committer | Gael Pasgrimaud <gael@gawel.org> | 2018-09-22 12:42:07 +0200 |
| commit | 632a2a2fedfe72a5bf6c6f4c42d37f5be68ad97d (patch) | |
| tree | 132213d801cd3c1d0362815052b8390dc60c4f6c /docs | |
| parent | e89083b582f8e7f03976236ea22f604f6bddf355 (diff) | |
| parent | 6f124d6f81ef34c8731f3498b4402008144eb087 (diff) | |
| download | webtest-632a2a2fedfe72a5bf6c6f4c42d37f5be68ad97d.tar.gz | |
Merge branch 'master' into docs-cleanup
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/forms.rst | 8 | ||||
| -rw-r--r-- | docs/forms_fixt.py | 20 | ||||
| -rw-r--r-- | docs/index.rst | 5 | ||||
| -rw-r--r-- | docs/index_fixt.py | 15 | ||||
| -rw-r--r-- | docs/testapp.rst | 25 | ||||
| -rw-r--r-- | docs/testapp_fixt.py | 42 | ||||
| -rw-r--r-- | docs/testresponse.rst | 23 | ||||
| -rw-r--r-- | docs/testresponse_fixt.py | 46 |
8 files changed, 61 insertions, 123 deletions
diff --git a/docs/forms.rst b/docs/forms.rst index 0bd5740..63cd804 100644 --- a/docs/forms.rst +++ b/docs/forms.rst @@ -1,6 +1,14 @@ Form handling ============= +.. + >>> from webtest.debugapp import make_debug_app + >>> from webtest.app import TestApp + >>> app = make_debug_app({}, + ... form='docs/form.html', + ... show_form=True) + >>> app = TestApp(app) + Getting a form -------------- diff --git a/docs/forms_fixt.py b/docs/forms_fixt.py deleted file mode 100644 index 26548aa..0000000 --- a/docs/forms_fixt.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -from webtest.debugapp import make_debug_app -from webtest.app import TestApp -from doctest import ELLIPSIS -from doctest import NORMALIZE_WHITESPACE -import os - -dirname = os.path.dirname(__file__) - - -def setup_test(test): - app = make_debug_app({}, - form=os.path.join(dirname, 'form.html'), - show_form=True) - test.globs['app'] = TestApp(app) - for example in test.examples: - example.options.setdefault(ELLIPSIS, 1) - example.options.setdefault(NORMALIZE_WHITESPACE, 1) - -setup_test.__test__ = False diff --git a/docs/index.rst b/docs/index.rst index 9171833..8ac8353 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -70,6 +70,11 @@ The most important object in WebTest is :class:`~webtest.app.TestApp`, the wrapp for WSGI applications. It also allows you to perform HTTP requests on it. To use it, you simply instantiate it with your WSGI application. +.. + >>> import os + >>> with open('docs/form.html', 'rb') as fd: + ... body = fd.read() + .. note:: If your WSGI application requires any configuration, diff --git a/docs/index_fixt.py b/docs/index_fixt.py deleted file mode 100644 index dc60645..0000000 --- a/docs/index_fixt.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -import doctest -import os - - -def setup_test(test): - fd = open(os.path.join(os.path.dirname(__file__), 'form.html'), 'rb') - body = fd.read() - fd.close() - test.globs.update(body=body) - for example in test.examples: - example.options.setdefault(doctest.ELLIPSIS, 1) - example.options.setdefault(doctest.NORMALIZE_WHITESPACE, 1) - -setup_test.__test__ = False diff --git a/docs/testapp.rst b/docs/testapp.rst index e600eb0..ba99baa 100644 --- a/docs/testapp.rst +++ b/docs/testapp.rst @@ -1,6 +1,31 @@ TestApp ======= +.. + >>> import json + >>> import six + >>> import sys + >>> from webtest.app import TestApp + >>> from webob import Request + >>> from webob import Response + >>> def application(environ, start_response): + ... req = Request(environ) + ... if req.path_info.endswith('.html'): + ... content_type = 'text/html' + ... body = six.b('<html><body><div id="content">hey!</div></body>') + ... elif req.path_info.endswith('.xml'): + ... content_type = 'text/xml' + ... body = six.b('<xml><message>hey!</message></xml>') + ... elif req.path_info.endswith('.json'): + ... content_type = 'application/json' + ... body = six.b(json.dumps({"a": 1, "b": 2})) + ... elif '/resource/' in req.path_info: + ... content_type = 'application/json' + ... body = six.b(json.dumps(dict(id=1, value='value'))) + ... resp = Response(body, content_type=content_type) + ... return resp(environ, start_response) + >>> app = TestApp(application) + Making Requests --------------- diff --git a/docs/testapp_fixt.py b/docs/testapp_fixt.py deleted file mode 100644 index ecbbeb8..0000000 --- a/docs/testapp_fixt.py +++ /dev/null @@ -1,42 +0,0 @@ -# -*- coding: utf-8 -*- -from doctest import NORMALIZE_WHITESPACE -from doctest import ELLIPSIS -from doctest import SKIP -from webtest import TestApp -from webob import Request -from webob import Response -import json -import six -import sys - - -def application(environ, start_response): - req = Request(environ) - if req.path_info.endswith('.html'): - content_type = 'text/html' - body = six.b('<html><body><div id="content">hey!</div></body>') - elif req.path_info.endswith('.xml'): - content_type = 'text/xml' - body = six.b('<xml><message>hey!</message></xml>') - elif req.path_info.endswith('.json'): - content_type = 'application/json' - body = six.b(json.dumps({"a": 1, "b": 2})) - elif '/resource/' in req.path_info: - content_type = 'application/json' - body = six.b(json.dumps(dict(id=1, value='value'))) - resp = Response(body, content_type=content_type) - return resp(environ, start_response) - - -def setup_test(test): - ver = sys.version_info[:2] - test.globs.update(app=TestApp(application)) - for example in test.examples: - if "'xml'" in example.want and ver == (2, 6): - # minidom node do not render the same in 2.6 - example.options[SKIP] = 1 - else: - example.options[ELLIPSIS] = 1 - example.options[NORMALIZE_WHITESPACE] = 1 - -setup_test.__test__ = False diff --git a/docs/testresponse.rst b/docs/testresponse.rst index bfaa0eb..8287283 100644 --- a/docs/testresponse.rst +++ b/docs/testresponse.rst @@ -1,6 +1,29 @@ TestResponse ############ +.. + >>> import json + >>> import six + >>> import sys + >>> from webob import Request + >>> from webob import Response + >>> from webtest.app import TestApp + >>> def application(environ, start_response): + ... req = Request(environ) + ... if req.path_info.endswith('.html'): + ... content_type = 'text/html' + ... body = six.b('<html><body><div id="content">hey!</div></body>') + ... elif req.path_info.endswith('.xml'): + ... content_type = 'text/xml' + ... body = six.b('<xml><message>hey!</message></xml>') + ... elif req.path_info.endswith('.json'): + ... content_type = 'application/json' + ... body = six.b(json.dumps({"a": 1, "b": 2})) + ... resp = Response(body, content_type=content_type) + ... return resp(environ, start_response) + >>> app = TestApp(application) + + The response object is based on :class:`webob.response.Response` with some additions to help with testing. diff --git a/docs/testresponse_fixt.py b/docs/testresponse_fixt.py deleted file mode 100644 index b80503e..0000000 --- a/docs/testresponse_fixt.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -from doctest import NORMALIZE_WHITESPACE -from doctest import ELLIPSIS -from doctest import SKIP -from webtest import TestApp -from webob import Request -from webob import Response -import json -import six -import sys - - -def application(environ, start_response): - req = Request(environ) - if req.path_info.endswith('.html'): - content_type = 'text/html' - body = six.b('<html><body><div id="content">hey!</div></body>') - elif req.path_info.endswith('.xml'): - content_type = 'text/xml' - body = six.b('<xml><message>hey!</message></xml>') - elif req.path_info.endswith('.json'): - content_type = 'application/json' - body = six.b(json.dumps({"a": 1, "b": 2})) - resp = Response(body, content_type=content_type) - return resp(environ, start_response) - - -def setup_test(test): - ver = sys.version_info[:2] - is_pypy = 'PyPy' in sys.version - test.globs.update(app=TestApp(application)) - for example in test.examples: - if "lxml" in example.source and is_pypy: - # minidom node do not render the same in 2.6 - example.options[SKIP] = 1 - elif "pyquery" in example.source and is_pypy: - # minidom node do not render the same in 2.6 - example.options[SKIP] = 1 - elif "'xml'" in example.want and ver == (2, 6): - # minidom node do not render the same in 2.6 - example.options[SKIP] = 1 - else: - example.options[ELLIPSIS] = 1 - example.options[NORMALIZE_WHITESPACE] = 1 - -setup_test.__test__ = False |
