forked from csernazs/pytest-httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_querymatcher.py
More file actions
54 lines (35 loc) · 1.37 KB
/
test_querymatcher.py
File metadata and controls
54 lines (35 loc) · 1.37 KB
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
from pytest_httpserver.httpserver import StringQueryMatcher, BooleanQueryMatcher, MappingQueryMatcher
from werkzeug.datastructures import MultiDict
def assert_match(qm, query_string):
values = qm.get_comparing_values(query_string)
assert values[0] == values[1]
def assert_not_match(qm, query_string):
values = qm.get_comparing_values(query_string)
assert values[0] != values[1]
def test_qm_string():
qm = StringQueryMatcher("k1=v1&k2=v2")
assert_match(qm, b"k1=v1&k2=v2")
assert_not_match(qm, b"k2=v2&k1=v1")
def test_qm_bytes():
qm = StringQueryMatcher(b"k1=v1&k2=v2")
assert_match(qm, b"k1=v1&k2=v2")
assert_not_match(qm, b"k2=v2&k1=v1")
def test_qm_boolean():
qm = BooleanQueryMatcher(True)
assert_match(qm, b"k1=v1")
def test_qm_mapping_string():
qm = MappingQueryMatcher({"k1": "v1"})
assert_match(qm, b"k1=v1")
def test_qm_mapping_unordered():
qm = MappingQueryMatcher({"k1": "v1", "k2": "v2"})
assert_match(qm, b"k1=v1&k2=v2")
assert_match(qm, b"k2=v2&k1=v1")
def test_qm_mapping_first_value():
qm = MappingQueryMatcher({"k1": "v1"})
assert_match(qm, b"k1=v1&k1=v2")
qm = MappingQueryMatcher({"k1": "v2"})
assert_match(qm, b"k1=v2&k1=v1")
def test_qm_mapping_multiple_values():
md = MultiDict([("k1", "v1"), ("k1", "v2")])
qm = MappingQueryMatcher(md)
assert_match(qm, b"k1=v1&k1=v2")