From 0e93b49f64b305452fa5bdeae3006546e3f100b8 Mon Sep 17 00:00:00 2001 From: Sebastian Mainberger Date: Tue, 8 Dec 2020 12:46:11 -0800 Subject: [PATCH] TST: Add tests for path prioritization. --- tests/unit/templating/test_paths_finders.py | 87 +++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tests/unit/templating/test_paths_finders.py b/tests/unit/templating/test_paths_finders.py index 953cc1e..3b95aa0 100644 --- a/tests/unit/templating/test_paths_finders.py +++ b/tests/unit/templating/test_paths_finders.py @@ -435,3 +435,90 @@ class TestSimilarPaths( assert result == ( path_2, operation_2, server, path_result, server_result, ) + + +class TestConcretePaths( + BaseTestSpecServer, BaseTestSimpleServer): + + path_name = '/keys/{id}/tokens' + + @pytest.fixture + def operation_2(self): + return Operation('get', '/keys/master/tokens', {}, {}) + + @pytest.fixture + def operations_2(self, operation_2): + return { + 'get': operation_2, + } + + @pytest.fixture + def path(self, operations): + return Path('/keys/{id}/tokens', operations) + + @pytest.fixture + def path_2(self, operations_2): + return Path('/keys/master/tokens', operations_2) + + @pytest.fixture + def paths(self, path, path_2): + return { + path.name: path, + path_2.name: path_2, + } + + def test_valid(self, finder, path_2, operation_2, server): + request_uri = '/keys/master/tokens' + request = MockRequest( + 'http://petstore.swagger.io', 'get', request_uri) + result = finder.find(request) + + path_result = TemplateResult(path_2.name, {}) + server_result = TemplateResult(self.server_url, {}) + assert result == ( + path_2, operation_2, server, path_result, server_result, + ) + + +class TestTemplateConcretePaths( + BaseTestSpecServer, BaseTestSimpleServer): + + path_name = '/keys/{id}/tokens/{id2}' + + @pytest.fixture + def operation_2(self): + return Operation('get', '/keys/{id}/tokens/master', {}, {}) + + @pytest.fixture + def operations_2(self, operation_2): + return { + 'get': operation_2, + } + + @pytest.fixture + def path(self, operations): + return Path('/keys/{id}/tokens/{id2}', operations) + + @pytest.fixture + def path_2(self, operations_2): + return Path('/keys/{id}/tokens/master', operations_2) + + @pytest.fixture + def paths(self, path, path_2): + return { + path.name: path, + path_2.name: path_2, + } + + def test_valid(self, finder, path_2, operation_2, server): + token_id = '123' + request_uri = '/keys/{0}/tokens/master'.format(token_id) + request = MockRequest( + 'http://petstore.swagger.io', 'get', request_uri) + result = finder.find(request) + + path_result = TemplateResult(path_2.name, {'id': '123'}) + server_result = TemplateResult(self.server_url, {}) + assert result == ( + path_2, operation_2, server, path_result, server_result, + )