File: test_datatype.py

package info (click to toggle)
openapi-pydantic 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 744 kB
  • sloc: python: 4,392; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 758 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
import pytest
from pydantic import ValidationError

from openapi_pydantic.v3.v3_1 import Schema


@pytest.mark.parametrize(
    "datatype",
    (
        "string",
        "number",
        "integer",
        "boolean",
        "array",
        "object",
        "null",
    ),
)
def test_good_types_parse_and_equate(datatype: str) -> None:
    assert Schema(type=datatype).type == datatype


def test_bad_types_raise_validation_errors() -> None:
    with pytest.raises(ValidationError):
        Schema(type="invalid")

    with pytest.raises(ValidationError):
        Schema(anyOf=[{"type": "invalid"}])

    with pytest.raises(ValidationError):
        Schema(
            properties={
                "a": Schema(type="invalid"),
            },
        )