File: test_querymatcher.py

package info (click to toggle)
pytest-httpserver 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: python: 2,382; makefile: 77; sh: 21
file content (57 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download
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
from werkzeug.datastructures import MultiDict

from pytest_httpserver.httpserver import BooleanQueryMatcher
from pytest_httpserver.httpserver import MappingQueryMatcher
from pytest_httpserver.httpserver import StringQueryMatcher


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(result=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")