testresponse_fixt.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 from doctest import NORMALIZE_WHITESPACE
00003 from doctest import ELLIPSIS
00004 from doctest import SKIP
00005 from webtest import TestApp
00006 from webob import Request
00007 from webob import Response
00008 import json
00009 import six
00010 import sys
00011 
00012 
00013 def application(environ, start_response):
00014     req = Request(environ)
00015     if req.path_info.endswith('.html'):
00016         content_type = 'text/html'
00017         body = six.b('<html><body><div id="content">hey!</div></body>')
00018     elif req.path_info.endswith('.xml'):
00019         content_type = 'text/xml'
00020         body = six.b('<xml><message>hey!</message></xml>')
00021     elif req.path_info.endswith('.json'):
00022         content_type = 'application/json'
00023         body = json.dumps({"a": 1, "b": 2})
00024     resp = Response(body, content_type=content_type)
00025     return resp(environ, start_response)
00026 
00027 
00028 def setup_test(test):
00029     ver = sys.version_info[:2]
00030     is_pypy = 'PyPy' in sys.version
00031     test.globs.update(app=TestApp(application))
00032     for example in test.examples:
00033         if "lxml" in example.source and is_pypy:
00034             # minidom node do not render the same in 2.6
00035             example.options[SKIP] = 1
00036         elif "pyquery" in example.source and is_pypy:
00037             # minidom node do not render the same in 2.6
00038             example.options[SKIP] = 1
00039         elif "'xml'" in example.want and ver == (2, 6):
00040             # minidom node do not render the same in 2.6
00041             example.options[SKIP] = 1
00042         else:
00043             example.options[ELLIPSIS] = 1
00044             example.options[NORMALIZE_WHITESPACE] = 1
00045 
00046 setup_test.__test__ = False


webtest
Author(s): AlexV
autogenerated on Sat Mar 25 2017 03:32:05