testapp_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     elif '/resource/' in req.path_info:
00025         content_type = 'application/json'
00026         body = json.dumps(dict(id=1, value='value'))
00027     resp = Response(body, content_type=content_type)
00028     return resp(environ, start_response)
00029 
00030 
00031 def setup_test(test):
00032     ver = sys.version_info[:2]
00033     test.globs.update(app=TestApp(application))
00034     for example in test.examples:
00035         if "'xml'" in example.want and ver == (2, 6):
00036             # minidom node do not render the same in 2.6
00037             example.options[SKIP] = 1
00038         else:
00039             example.options[ELLIPSIS] = 1
00040             example.options[NORMALIZE_WHITESPACE] = 1
00041 
00042 setup_test.__test__ = False


webtest
Author(s): AlexV
autogenerated on Sat Jun 8 2019 20:32:07