File: test_paths_parsers.py

package info (click to toggle)
python-openapi-core 0.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,104 kB
  • sloc: python: 19,979; makefile: 44
file content (57 lines) | stat: -rw-r--r-- 1,597 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
import pytest

from openapi_core.templating.paths.parsers import PathParser


class TestSearch:
    def test_endswith(self):
        path_pattern = "/{test}/test"
        parser = PathParser(path_pattern, post_expression="$")
        full_url_pattern = "/test1/test/test2/test"

        result = parser.search(full_url_pattern)

        assert result.named == {
            "test": "test2",
        }

    def test_exact(self):
        path_pattern = "/{test}/test"
        parser = PathParser(path_pattern, post_expression="$")
        full_url_pattern = "/test/test"

        result = parser.search(full_url_pattern)

        assert result.named == {
            "test": "test",
        }

    @pytest.mark.parametrize(
        "path_pattern,expected",
        [
            ("/{test_id}/test", {"test_id": "test"}),
            ("/{test.id}/test", {"test.id": "test"}),
            ("/{test-id}/test", {"test-id": "test"}),
        ],
    )
    def test_chars_valid(self, path_pattern, expected):
        parser = PathParser(path_pattern, post_expression="$")
        full_url_pattern = "/test/test"

        result = parser.search(full_url_pattern)

        assert result.named == expected

    @pytest.mark.parametrize(
        "path_pattern,expected",
        [
            ("/{test~id}/test", {"test~id": "test"}),
        ],
    )
    def test_special_chars_valid(self, path_pattern, expected):
        parser = PathParser(path_pattern, post_expression="$")
        full_url_pattern = "/test/test"

        result = parser.search(full_url_pattern)

        assert result.named == expected