forked from vmware/vmware-openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_output_handling.py
203 lines (194 loc) · 8.37 KB
/
test_output_handling.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import unittest
from lib import utils
from lib.file_output_handler import SpecificationDictsMerger
class TestSpecificationDictsMerger(unittest.TestCase):
def test_merge_api_rest_dicts(self):
rest_path_dict = {"/rest/com/vmware/vcenter/ovf/library_item":
{"post": {
"tags": [
"ovf/library_item"
],
"parameters": [
{
"in": "body",
"name": "request_body",
"required": True,
"schema": {
"$ref": "#/definitions/com.vmware.vcenter.ovf.library_item_create"
}
}
],
"responses": {
200: {
"schema": {
"$ref": "#/definitions/com.vmware.vcenter.ovf.library_item.create_resp"
}
},
400: {
"description": "if the specified virtual machine or virtual appliance is busy.",
"schema": {
"$ref": "#/definitions/com.vmware.vapi.std.errors.resource_busy_error"
}
},
404: {
"description": "if the virtual machine or virtual appliance specified by {@param.name source} does not exist.",
"schema": {
"$ref": "#/definitions/com.vmware.vapi.std.errors.not_found_error"
}
}
},
"operationId": "create"
}
},
"/rest/com/vmware/vcenter/ovf/import_flag": {
"get": {
"tags": [
"ovf/import_flag"
],
"summary": "Returns information about the import flags supported by the deployment platform. <p> The supported flags are: <dl> <dt>LAX</dt> <dd>Lax mode parsing of the OVF descriptor.</dd> </dl> <p> Future server versions might support additional flags.",
"parameters": [
{
"type": "string",
"in": "query",
"name": "rp",
"description": "The identifier of resource pool target for retrieving the import flag(s).",
"required": True
}
],
"responses": {
200: {
"description": "A {@term list} of supported import flags.",
"schema": {
"$ref": "#/definitions/com.vmware.vcenter.ovf.import_flag.list_resp"
}
},
404: {
"description": "If the resource pool associated with {@param.name rp} does not exist.",
"schema": {
"$ref": "#/definitions/com.vmware.vapi.std.errors.not_found_error"
}
}
},
"operationId": "list"
}
}
}
rest_type_dict = {"com.vmware.vcenter.ovf.import_flag.list_resp": {
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/com.vmware.vcenter.ovf.import_flag.info"
}
}
},
"required": [
"value"
]
}}
# Use copies rather than references to the same dict
api_path_dict = {
"/api/com/vmware/vcenter/ovf/library_item": {"post": {
"tags": [
"ovf/library_item"
],
"parameters": [
{
"in": "body",
"name": "request_body",
"required": True,
"schema": {
"$ref": "#/definitions/com.vmware.vcenter.ovf.library_item_create"
}
}
],
"responses": {
200: {
"schema": {
"$ref": "#/definitions/com.vmware.vcenter.ovf.library_item.create_resp"
}
},
400: {
"description": "if the specified virtual machine or virtual appliance is busy.",
"schema": {
"$ref": "#/definitions/com.vmware.vapi.std.errors.resource_busy_error"
}
},
404: {
"description": "if the virtual machine or virtual appliance specified by {@param.name source} does not exist.",
"schema": {
"$ref": "#/definitions/com.vmware.vapi.std.errors.not_found_error"
}
}
},
"operationId": "create"
}
},
"/api/com/vmware/vcenter/ovf/import_flag": {
"get": {
"tags": [
"ovf/import_flag"
],
"summary": "Returns information about the import flags supported by the deployment platform. <p> The supported flags are: <dl> <dt>LAX</dt> <dd>Lax mode parsing of the OVF descriptor.</dd> </dl> <p> Future server versions might support additional flags.",
"parameters": [
{
"type": "string",
"in": "query",
"name": "rp",
"description": "The identifier of resource pool target for retrieving the import flag(s).",
"required": True
}
],
"responses": {
200: {
"description": "A {@term list} of supported import flags.",
"schema": {
"$ref": "#/definitions/com.vmware.vcenter.ovf.import_flag.list_resp"
}
},
404: {
"description": "If the resource pool associated with {@param.name rp} does not exist.",
"schema": {
"$ref": "#/definitions/com.vmware.vapi.std.errors.not_found_error"
}
}
},
"operationId": "list"
}
},
"/api/com/vmware/vcenter/ovf/export_flag": {}
}
api_type_dict = {"ComVmwareVcenterOvfImportFlag": {
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/com.vmware.vcenter.ovf.import_flag.info"
}
}
},
"required": [
"value"
]
}}
rest_spec = {"vcenter": (dict(rest_path_dict), dict(rest_type_dict)),
"appliance": ({}, {})}
api_spec = {"vcenter": (dict(api_path_dict), dict(api_type_dict)),
"cis": ({}, {})}
merger = SpecificationDictsMerger(dict(rest_spec), dict(api_spec))
merged = merger.merge_api_rest_dicts()
self.assertTrue("vcenter" in merged and "cis" in merged and "appliance" in merged)
self.assertEqual(len(merged["vcenter"][0]), 5)
self.assertEqual(len(merged["vcenter"][1]), 2)
api_def_type = merged["vcenter"][0] \
.get("/api/com/vmware/vcenter/ovf/import_flag") \
.get("get") \
.get("responses") \
.get(200) \
.get("schema") \
.get("$ref")
self.assertEqual(api_def_type, "#/definitions/com.vmware.vcenter.ovf.import_flag.list_resp")
if __name__ == '__main__':
unittest.main()