File: test_qsh.py

package info (click to toggle)
python-jira 3.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,008 kB
  • sloc: python: 8,643; sh: 13; makefile: 7; xml: 4
file content (49 lines) | stat: -rw-r--r-- 1,311 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
from __future__ import annotations

import pytest

from jira.client import QshGenerator


class MockRequest:
    def __init__(self, method, url):
        self.method = method
        self.url = url


@pytest.mark.parametrize(
    "method,url,expected",
    [
        ("GET", "http://example.com", "GET&&"),
        # empty parameter
        ("GET", "http://example.com?key=&key2=A", "GET&&key=&key2=A"),
        # whitespace
        ("GET", "http://example.com?key=A+B", "GET&&key=A%20B"),
        # tilde
        ("GET", "http://example.com?key=A~B", "GET&&key=A~B"),
        # repeated parameters
        (
            "GET",
            "http://example.com?key2=Z&key1=X&key3=Y&key1=A",
            "GET&&key1=A,X&key2=Z&key3=Y",
        ),
        # repeated parameters with whitespace
        (
            "GET",
            "http://example.com?key2=Z+A&key1=X+B&key3=Y&key1=A+B",
            "GET&&key1=A%20B,X%20B&key2=Z%20A&key3=Y",
        ),
    ],
    ids=[
        "no parameters",
        "empty parameter",
        "whitespace",
        "tilde",
        "repeated parameters",
        "repeated parameters with whitespace",
    ],
)
def test_qsh(method, url, expected):
    gen = QshGenerator("http://example.com")
    req = MockRequest(method, url)
    assert gen._generate_qsh(req) == expected