From 1eff5a2c9fdb15a570ac4091fb1ad5ddc4555b42 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Mon, 25 Sep 2023 15:22:56 +0000 Subject: [PATCH] Tests for special characters of regex nonsupported --- tests/unit/templating/test_templating_util.py | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/tests/unit/templating/test_templating_util.py b/tests/unit/templating/test_templating_util.py index b6a5eb9b..b268e4f0 100644 --- a/tests/unit/templating/test_templating_util.py +++ b/tests/unit/templating/test_templating_util.py @@ -1,23 +1,60 @@ +import pytest + from openapi_core.templating.util import search class TestSearch: def test_endswith(self): - path_patter = "/{test}/test" + path_pattern = "/{test}/test" full_url_pattern = "/test1/test/test2/test" - result = search(path_patter, full_url_pattern) + result = search(path_pattern, full_url_pattern) assert result.named == { "test": "test2", } def test_exact(self): - path_patter = "/{test}/test" + path_pattern = "/{test}/test" full_url_pattern = "/test/test" - result = search(path_patter, full_url_pattern) + result = search(path_pattern, 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"}), + ], + ) + def test_chars_valid(self, path_pattern, expected): + full_url_pattern = "/test/test" + + result = search(path_pattern, full_url_pattern) + + assert result.named == expected + + @pytest.mark.xfail( + reason=( + "Special characters of regex not supported. " + "See https://github.com/python-openapi/openapi-core/issues/672" + ), + strict=True, + ) + @pytest.mark.parametrize( + "path_pattern,expected", + [ + ("/{test~id}/test", {"test~id": "test"}), + ("/{test-id}/test", {"test-id": "test"}), + ], + ) + def test_special_chars_valid(self, path_pattern, expected): + full_url_pattern = "/test/test" + + result = search(path_pattern, full_url_pattern) + + assert result.named == expected