|
| 1 | +import pytest |
| 2 | + |
1 | 3 | from openapi_core.templating.util import search
|
2 | 4 |
|
3 | 5 |
|
4 | 6 | class TestSearch:
|
5 | 7 | def test_endswith(self):
|
6 |
| - path_patter = "/{test}/test" |
| 8 | + path_pattern = "/{test}/test" |
7 | 9 | full_url_pattern = "/test1/test/test2/test"
|
8 | 10 |
|
9 |
| - result = search(path_patter, full_url_pattern) |
| 11 | + result = search(path_pattern, full_url_pattern) |
10 | 12 |
|
11 | 13 | assert result.named == {
|
12 | 14 | "test": "test2",
|
13 | 15 | }
|
14 | 16 |
|
15 | 17 | def test_exact(self):
|
16 |
| - path_patter = "/{test}/test" |
| 18 | + path_pattern = "/{test}/test" |
17 | 19 | full_url_pattern = "/test/test"
|
18 | 20 |
|
19 |
| - result = search(path_patter, full_url_pattern) |
| 21 | + result = search(path_pattern, full_url_pattern) |
20 | 22 |
|
21 | 23 | assert result.named == {
|
22 | 24 | "test": "test",
|
23 | 25 | }
|
| 26 | + |
| 27 | + @pytest.mark.parametrize( |
| 28 | + "path_pattern,expected", |
| 29 | + [ |
| 30 | + ("/{test_id}/test", {"test_id": "test"}), |
| 31 | + ("/{test.id}/test", {"test.id": "test"}), |
| 32 | + ], |
| 33 | + ) |
| 34 | + def test_chars_valid(self, path_pattern, expected): |
| 35 | + full_url_pattern = "/test/test" |
| 36 | + |
| 37 | + result = search(path_pattern, full_url_pattern) |
| 38 | + |
| 39 | + assert result.named == expected |
| 40 | + |
| 41 | + @pytest.mark.xfail( |
| 42 | + reason=( |
| 43 | + "Special characters of regex not supported. " |
| 44 | + "See https://github.com/python-openapi/openapi-core/issues/672" |
| 45 | + ), |
| 46 | + strict=True, |
| 47 | + ) |
| 48 | + @pytest.mark.parametrize( |
| 49 | + "path_pattern,expected", |
| 50 | + [ |
| 51 | + ("/{test~id}/test", {"test~id": "test"}), |
| 52 | + ("/{test-id}/test", {"test-id": "test"}), |
| 53 | + ], |
| 54 | + ) |
| 55 | + def test_special_chars_valid(self, path_pattern, expected): |
| 56 | + full_url_pattern = "/test/test" |
| 57 | + |
| 58 | + result = search(path_pattern, full_url_pattern) |
| 59 | + |
| 60 | + assert result.named == expected |
0 commit comments