-
Notifications
You must be signed in to change notification settings - Fork 421
/
Copy pathconftest.py
141 lines (102 loc) · 3.52 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from __future__ import annotations
import json
import fastjsonschema
import pytest
from aws_lambda_powertools.event_handler.openapi.models import APIKey, APIKeyIn
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://spec.openapis.org/oas/3.0/schema/2021-09-28")
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://spec.openapis.org/oas/3.1/schema/2022-10-07")
data = json.loads(f.read().decode("utf-8"))
return fastjsonschema.compile(
data,
use_formats=False,
)
@pytest.fixture
def security_scheme():
return {"apiKey": APIKey(name="X-API-KEY", description="API Key", in_=APIKeyIn.header)}
@pytest.fixture
def openapi_extension_integration_detail():
return {
"type": "aws",
"httpMethod": "POST",
"uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/..integration/invocations",
"responses": {"default": {"statusCode": "200"}},
"passthroughBehavior": "when_no_match",
"contentHandling": "CONVERT_TO_TEXT",
}
@pytest.fixture
def openapi_extension_validator_detail():
return "Validate body, query string parameters, and headers"