diff options
| author | Domen Kožar <domen@dev.si> | 2013-02-23 18:58:48 +0100 |
|---|---|---|
| committer | Domen Kožar <domen@dev.si> | 2013-02-23 19:14:26 +0100 |
| commit | 7e957687570b56d24fa487f2a94a30904f84f2f9 (patch) | |
| tree | fbd6e834a9cf8e21b3aed200a29a77647e08b5ce /docs/testapp_fixt.py | |
| parent | 7dcefc26d4feaca5b475ed0d0fbab6e5ab8c4baf (diff) | |
| download | webtest-7e957687570b56d24fa487f2a94a30904f84f2f9.tar.gz | |
Completely rewrite API documentation
Diffstat (limited to 'docs/testapp_fixt.py')
| -rw-r--r-- | docs/testapp_fixt.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/docs/testapp_fixt.py b/docs/testapp_fixt.py new file mode 100644 index 0000000..23742cf --- /dev/null +++ b/docs/testapp_fixt.py @@ -0,0 +1,42 @@ +# -*- 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 = json.dumps({"a": 1, "b": 2}) + elif '/resource/' in req.path_info: + content_type = 'application/json' + body = 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 |
