-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathtest_json_schema.py
104 lines (100 loc) · 2.76 KB
/
test_json_schema.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pytest
from pydantic import BaseModel
from pydantic_extra_types.color import Color
from pydantic_extra_types.country import (
CountryAlpha2,
CountryAlpha3,
CountryNumericCode,
CountryOfficialName,
CountryShortName,
)
from pydantic_extra_types.pandas_types import Series
from pydantic_extra_types.payment import PaymentCardNumber
@pytest.mark.parametrize(
'cls,expected',
[
(
Color,
{
'properties': {'x': {'format': 'color', 'title': 'X', 'type': 'string'}},
'required': ['x'],
'title': 'Model',
'type': 'object',
},
),
(
PaymentCardNumber,
{
'properties': {
'x': {
'maxLength': 19,
'minLength': 12,
'title': 'X',
'type': 'string',
}
},
'required': ['x'],
'title': 'Model',
'type': 'object',
},
),
(
CountryAlpha2,
{
'properties': {'x': {'pattern': '^\\w{2}$', 'title': 'X', 'type': 'string'}},
'required': ['x'],
'title': 'Model',
'type': 'object',
},
),
(
CountryAlpha3,
{
'properties': {'x': {'pattern': '^\\w{3}$', 'title': 'X', 'type': 'string'}},
'required': ['x'],
'title': 'Model',
'type': 'object',
},
),
(
CountryNumericCode,
{
'properties': {'x': {'pattern': '^[0-9]{3}$', 'title': 'X', 'type': 'string'}},
'required': ['x'],
'title': 'Model',
'type': 'object',
},
),
(
CountryOfficialName,
{
'properties': {'x': {'title': 'X', 'type': 'string'}},
'required': ['x'],
'title': 'Model',
'type': 'object',
},
),
(
CountryShortName,
{
'properties': {'x': {'title': 'X', 'type': 'string'}},
'required': ['x'],
'title': 'Model',
'type': 'object',
},
),
(
Series,
{
'properties': {'x': {'title': 'X'}},
'required': ['x'],
'title': 'Model',
'type': 'object',
},
),
],
)
def test_json_schema(cls, expected):
class Model(BaseModel):
x: cls
assert Model.model_json_schema() == expected