File: test_minimal.py

package info (click to toggle)
python-openapi-core 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,008 kB
  • sloc: python: 18,868; makefile: 47
file content (52 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pytest

from openapi_core import unmarshal_request
from openapi_core import validate_request
from openapi_core.templating.paths.exceptions import OperationNotFound
from openapi_core.templating.paths.exceptions import PathNotFound
from openapi_core.testing import MockRequest


class TestMinimal:
    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",
        "data/v3.1/minimal_with_servers.yaml",
        "data/v3.1/minimal.yaml",
    ]

    @pytest.mark.parametrize("server", servers)
    @pytest.mark.parametrize("spec_path", spec_paths)
    def test_hosts(self, schema_path_factory, server, spec_path):
        spec = schema_path_factory.from_file(spec_path)
        request = MockRequest(server, "get", "/status")

        result = unmarshal_request(request, spec=spec)

        assert not result.errors

    @pytest.mark.parametrize("server", servers)
    @pytest.mark.parametrize("spec_path", spec_paths)
    def test_invalid_operation(self, schema_path_factory, server, spec_path):
        spec = schema_path_factory.from_file(spec_path)
        request = MockRequest(server, "post", "/status")

        with pytest.raises(OperationNotFound):
            validate_request(request, spec)

    @pytest.mark.parametrize("server", servers)
    @pytest.mark.parametrize("spec_path", spec_paths)
    def test_invalid_path(self, schema_path_factory, server, spec_path):
        spec = schema_path_factory.from_file(spec_path)
        request = MockRequest(server, "get", "/nonexistent")

        with pytest.raises(PathNotFound):
            validate_request(request, spec=spec)