forked from cloudtools/troposphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_apigateway.py
72 lines (59 loc) · 1.9 KB
/
test_apigateway.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
import unittest
from troposphere import Join
from troposphere.apigateway import GatewayResponse, Model
class TestModel(unittest.TestCase):
def test_schema(self):
# Check with no schema
model = Model(
"schema",
RestApiId="apiid",
)
model.validate()
# Check valid json schema string
model = Model(
"schema",
RestApiId="apiid",
Schema='{"a": "b"}',
)
model.validate()
# Check invalid json schema string
model = Model(
"schema",
RestApiId="apiid",
Schema='{"a: "b"}',
)
with self.assertRaises(ValueError):
model.validate()
# Check accepting dict and converting to string in validate
d = {"c": "d"}
model = Model("schema", RestApiId="apiid", Schema=d)
model.validate()
self.assertEqual(model.properties["Schema"], '{"c": "d"}')
# Check invalid Schema type
with self.assertRaises(TypeError):
model = Model("schema", RestApiId="apiid", Schema=1)
# Check Schema being an AWSHelperFn
model = Model(
"schema",
RestApiId="apiid",
Schema=Join(":", ['{"a', ': "b"}']),
)
model.validate()
class TestGatewayResponse(unittest.TestCase):
def test_response_type(self):
gateway_response = GatewayResponse(
"GatewayResponse",
ResponseType="DEFAULT_4XX",
RestApiId="apiid",
StatusCode="200",
)
gateway_response.validate()
with self.assertRaises(ValueError):
gateway_response = GatewayResponse(
"GatewayResponse",
ResponseType="INVALID_RESPONSE_TYPE",
RestApiId="apiid",
StatusCode="200",
)
if __name__ == "__main__":
unittest.main()