mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-24 19:19:56 +00:00
a0305fb97d
The specification: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#oasObject requires that if the 'servers' array is not provided or empty, its default value is an array of a single Server Object with 'url' of '/'.
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import pytest
|
|
|
|
from openapi_core.exceptions import InvalidOperation
|
|
from openapi_core.shortcuts import create_spec
|
|
from openapi_core.validators import RequestValidator
|
|
from openapi_core.wrappers import MockRequest
|
|
|
|
|
|
class TestMinimal(object):
|
|
|
|
servers = [
|
|
"http://minimal.test/",
|
|
"https://bad.remote.domain.net/",
|
|
"http://localhost",
|
|
"http://localhost:8080",
|
|
"https://u:p@a.b:1337"
|
|
]
|
|
|
|
spec_paths = [
|
|
"data/v3.0/minimal_with_servers.yaml",
|
|
"data/v3.0/minimal.yaml"
|
|
]
|
|
|
|
@pytest.mark.parametrize("server", servers)
|
|
@pytest.mark.parametrize("spec_path", spec_paths)
|
|
def test_hosts(self, factory, server, spec_path):
|
|
spec_dict = factory.spec_from_file(spec_path)
|
|
spec = create_spec(spec_dict)
|
|
validator = RequestValidator(spec)
|
|
request = MockRequest(server, "get", "/status")
|
|
|
|
result = validator.validate(request)
|
|
|
|
assert not result.errors
|
|
|
|
@pytest.mark.parametrize("server", servers)
|
|
@pytest.mark.parametrize("spec_path", spec_paths)
|
|
def test_invalid_operation(self, factory, server, spec_path):
|
|
spec_dict = factory.spec_from_file(spec_path)
|
|
spec = create_spec(spec_dict)
|
|
validator = RequestValidator(spec)
|
|
request = MockRequest(server, "get", "/nonexistent")
|
|
|
|
result = validator.validate(request)
|
|
|
|
assert len(result.errors) == 1
|
|
assert isinstance(result.errors[0], InvalidOperation)
|
|
assert result.body is None
|
|
assert result.parameters == {}
|