|
| 1 | +import pytest |
1 | 2 | from werkzeug.datastructures import MultiDict |
2 | 3 |
|
3 | 4 | from pytest_httpserver.httpserver import BooleanQueryMatcher |
@@ -55,3 +56,40 @@ def test_qm_mapping_multiple_values(): |
55 | 56 | md = MultiDict([("k1", "v1"), ("k1", "v2")]) |
56 | 57 | qm = MappingQueryMatcher(md) |
57 | 58 | assert_match(qm, b"k1=v1&k1=v2") |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.parametrize("query_string", [b"flag=", b"flag", b"flag=&", b"&flag="]) |
| 62 | +def test_qm_mapping_empty_value(query_string): |
| 63 | + qm = MappingQueryMatcher({"flag": ""}) |
| 64 | + assert_match(qm, query_string) |
| 65 | + assert_not_match(qm, b"") |
| 66 | + assert_not_match(qm, b"flag=value") |
| 67 | + |
| 68 | + |
| 69 | +@pytest.mark.parametrize("query_string", [b"flag=", b"flag", b"flag=&flag="]) |
| 70 | +def test_qm_mapping_empty_value_is_not_missing(query_string): |
| 71 | + qm = MappingQueryMatcher({}) |
| 72 | + assert_not_match(qm, query_string) |
| 73 | + assert_match(qm, b"") |
| 74 | + |
| 75 | + |
| 76 | +@pytest.mark.parametrize("query_string", [b"flag=&flag=value", b"flag&flag=value"]) |
| 77 | +def test_qm_mapping_first_value_is_empty(query_string): |
| 78 | + assert_match(MappingQueryMatcher({"flag": ""}), query_string) |
| 79 | + assert_not_match(MappingQueryMatcher({"flag": "value"}), query_string) |
| 80 | + assert_match(MappingQueryMatcher({"flag": "value"}), b"flag=value&flag=") |
| 81 | + |
| 82 | + |
| 83 | +@pytest.mark.parametrize("query_string", [b"flag=&flag=value", b"flag&flag=value"]) |
| 84 | +def test_qm_mapping_multiple_values_include_empty(query_string): |
| 85 | + qm = MappingQueryMatcher(MultiDict([("flag", ""), ("flag", "value")])) |
| 86 | + assert_match(qm, query_string) |
| 87 | + assert_not_match(qm, b"flag=value") |
| 88 | + assert_not_match(qm, b"flag=") |
| 89 | + |
| 90 | + |
| 91 | +def test_qm_mapping_empty_encoded_name(): |
| 92 | + qm = MappingQueryMatcher({"empty name": "", "": "value"}) |
| 93 | + assert_match(qm, b"empty%20name=&=value") |
| 94 | + assert_match(qm, b"=value&empty+name=") |
| 95 | + assert_not_match(qm, b"=value") |
0 commit comments