-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_parse_qs.py
68 lines (58 loc) · 1.86 KB
/
test_parse_qs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from urllib.parse import urlencode
from fast_query_parsers import parse_url_encoded_dict
encoded = urlencode(
[
("value", "10"),
("value", "12"),
("veggies", '["tomato", "potato", "aubergine"]'),
("nested", '{"some_key": "some_value"}'),
("calories", "122.53"),
("healthy", "true"),
("polluting", "false"),
("json", "null"),
],
).encode()
def test_parse_urlencoded_with_parse_numbers() -> None:
result = parse_url_encoded_dict(encoded, True)
assert result == {
"value": [10, 12],
"veggies": ["tomato", "potato", "aubergine"],
"nested": {"some_key": "some_value"},
"calories": 122.53,
"healthy": True,
"polluting": False,
"json": None,
}
def test_parse_urlencoded_without_parse_numbers() -> None:
result = parse_url_encoded_dict(encoded, False)
assert result == {
"value": ["10", "12"],
"veggies": ["tomato", "potato", "aubergine"],
"nested": {"some_key": "some_value"},
"calories": "122.53",
"healthy": True,
"polluting": False,
"json": None,
}
def test_parse_urlencoded_defaults_parse_numbers_true() -> None:
result = parse_url_encoded_dict(encoded)
assert result == {
"value": [10, 12],
"veggies": ["tomato", "potato", "aubergine"],
"nested": {"some_key": "some_value"},
"calories": 122.53,
"healthy": True,
"polluting": False,
"json": None,
}
def test_parse_urlencoded_kwargs() -> None:
result = parse_url_encoded_dict(qs=encoded, parse_numbers=True)
assert result == {
"value": [10, 12],
"veggies": ["tomato", "potato", "aubergine"],
"nested": {"some_key": "some_value"},
"calories": 122.53,
"healthy": True,
"polluting": False,
"json": None,
}