-
Notifications
You must be signed in to change notification settings - Fork 420
/
Copy pathconftest.py
116 lines (84 loc) · 2.85 KB
/
conftest.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
105
106
107
108
109
110
111
112
113
114
115
116
import json
import fastjsonschema
import pytest
from tests.functional.utils import load_event
@pytest.fixture
def json_dump():
# our serializers reduce length to save on costs; fixture to replicate separators
return lambda obj: json.dumps(obj, separators=(",", ":"))
@pytest.fixture
def validation_schema():
return {
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "https://example.com/example.json",
"type": "object",
"title": "Sample schema",
"description": "The root schema comprises the entire JSON document.",
"examples": [{"message": "hello world", "username": "lessa"}],
"required": ["message", "username"],
"properties": {
"message": {
"$id": "#/properties/message",
"type": "string",
"title": "The message",
"examples": ["hello world"],
},
"username": {
"$id": "#/properties/username",
"type": "string",
"title": "The username",
"examples": ["lessa"],
},
},
}
@pytest.fixture
def raw_event():
return {"message": "hello hello", "username": "blah blah"}
@pytest.fixture
def gw_event():
return load_event("apiGatewayProxyEvent.json")
@pytest.fixture
def gw_event_http():
return load_event("apiGatewayProxyV2Event.json")
@pytest.fixture
def gw_event_alb():
return load_event("albMultiValueQueryStringEvent.json")
@pytest.fixture
def gw_event_lambda_url():
return load_event("lambdaFunctionUrlEventWithHeaders.json")
@pytest.fixture
def gw_event_vpc_lattice():
return load_event("vpcLatticeV2EventWithHeaders.json")
@pytest.fixture
def gw_event_vpc_lattice_v1():
return load_event("vpcLatticeEvent.json")
@pytest.fixture(scope="session")
def pydanticv1_only():
from pydantic import __version__
version = __version__.split(".")
if version[0] != "1":
pytest.skip("pydanticv1 test only")
@pytest.fixture(scope="session")
def pydanticv2_only():
from pydantic import __version__
version = __version__.split(".")
if version[0] != "2":
pytest.skip("pydanticv2 test only")
@pytest.fixture(scope="session")
def openapi30_schema():
from urllib.request import urlopen
f = urlopen("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json")
data = json.loads(f.read().decode("utf-8"))
return fastjsonschema.compile(
data,
use_formats=False,
)
@pytest.fixture(scope="session")
def openapi31_schema():
from urllib.request import urlopen
f = urlopen("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json")
data = json.loads(f.read().decode("utf-8"))
return fastjsonschema.compile(
data,
use_formats=False,
)