TST: Add tests for path prioritization.

This commit is contained in:
Sebastian Mainberger 2020-12-08 12:46:11 -08:00
parent 44d3fd3927
commit 0e93b49f64

View file

@ -435,3 +435,90 @@ class TestSimilarPaths(
assert result == ( assert result == (
path_2, operation_2, server, path_result, server_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,
)