def build_environ(method, path, host='localhost', accept_type='text/html', content_type=None, query=None, form=None, files=None, cookies=None): if '://' in host: url = host.rstrip('/') + '/' + path.lstrip('/') else: url = 'http://' + host.strip('/') + '/' + path.lstrip('/') request = Request(method, url, None, files, form, query, cookies) prepared = request.prepare() parsed_url = parse_url(prepared.url) environ = { 'HTTP_HOST': parsed_url.host, 'PATH_INFO': parsed_url.path, 'REQUEST_METHOD': prepared.method, 'HTTP_ACCEPT': accept_type, 'QUERY_STRING': parsed_url.query or '', } for key, value in iteritems(prepared.headers): key = underscore(key) if key not in ['content_type', 'content_length']: key = 'http_' + key environ[key.upper()] = value if content_type is not None: environ['CONTENT_TYPE'] = content_type environ['wsgi.input'] = BytesIO(prepared.body) return environ
def test_basics(self): assert compat.text_type(u'Pändõra') == u'Pändõra' assert type('text') in compat.string_types string_io = compat.StringIO() string_io.write('test') assert string_io.getvalue() == 'test' mapping = {'a': 12, 'b': 16} result = {r for r in compat.iteritems(mapping)} assert result == {('a', 12), ('b', 16)}