1import six
2
3from paste.request import *
4from paste.util.multidict import MultiDict
5
6def test_parse_querystring():
7    e = {'QUERY_STRING': 'a=1&b=2&c=3&b=4'}
8    d = parse_querystring(e)
9    assert d == [('a', '1'), ('b', '2'), ('c', '3'), ('b', '4')]
10    assert e['paste.parsed_querystring'] == (
11        (d, e['QUERY_STRING']))
12    e = {'QUERY_STRING': 'a&b&c=&d=1'}
13    d = parse_querystring(e)
14    assert d == [('a', ''), ('b', ''), ('c', ''), ('d', '1')]
15
16def make_post(body):
17    e = {
18        'CONTENT_TYPE': 'application/x-www-form-urlencoded',
19        'CONTENT_LENGTH': str(len(body)),
20        'REQUEST_METHOD': 'POST',
21        'wsgi.input': six.BytesIO(body),
22        }
23    return e
24
25def test_parsevars():
26    e = make_post(b'a=1&b=2&c=3&b=4')
27    #cur_input = e['wsgi.input']
28    d = parse_formvars(e)
29    assert isinstance(d, MultiDict)
30    assert d == MultiDict([('a', '1'), ('b', '2'), ('c', '3'), ('b', '4')])
31    assert e['paste.parsed_formvars'] == (
32        (d, e['wsgi.input']))
33    # XXX: http://trac.pythonpaste.org/pythonpaste/ticket/125
34    #assert e['wsgi.input'] is not cur_input
35    #cur_input.seek(0)
36    #assert e['wsgi.input'].read() == cur_input.read()
37