Skip to content

Commit 00b7b29

Browse files
committed
Add tests, remove cov options
1 parent 1da1f02 commit 00b7b29

File tree

2 files changed

+264
-1
lines changed

2 files changed

+264
-1
lines changed

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ exclude = tests
6767
where=src
6868

6969
[tool:pytest]
70-
addopts = --cov=datadog_api_client --cov-config .coveragerc
7170
# addopts = --black --cov=datadog_api_client --cov-config .coveragerc --cov-report=term-missing
7271

7372
[flake8]

tests/test_deserialization.py

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
import json
2+
3+
from datadog_api_client.v1.model.synthetics_api_test import SyntheticsAPITest
4+
from datadog_api_client.v1.model.synthetics_browser_test import SyntheticsBrowserTest
5+
from datadog_api_client.v1.model.synthetics_test_request import SyntheticsTestRequest
6+
from datadog_api_client.v1.model_utils import validate_and_convert_types
7+
from datadog_api_client.v1 import Configuration as Configuration
8+
from datadog_api_client.v2.model.logs_archive import LogsArchive
9+
from datadog_api_client.v2.model.logs_archive_destination import LogsArchiveDestination
10+
from datadog_api_client.v2.model_utils import validate_and_convert_types as validate_and_convert_types_v2
11+
from datadog_api_client.v2 import Configuration as ConfigurationV2
12+
13+
14+
def test_unknown_nested_oneof_in_list():
15+
body = """{
16+
"status": "paused",
17+
"public_id": "jv7-wfd-kvt",
18+
"tags": [],
19+
"locations": [
20+
"pl:pl-kevin-y-6382df0d72d4588e1817f090b131541f"
21+
],
22+
"message": "",
23+
"name": "Test on www.example.com",
24+
"monitor_id": 28558768,
25+
"type": "api",
26+
"created_at": "2021-01-12T10:11:40.802074+00:00",
27+
"modified_at": "2021-01-22T16:42:10.520384+00:00",
28+
"subtype": "http",
29+
"config": {
30+
"request": {
31+
"url": "https://www.example.com",
32+
"method": "GET",
33+
"timeout": 30
34+
},
35+
"assertions": [
36+
{
37+
"operator": "lessThan",
38+
"type": "responseTime",
39+
"target": 1000
40+
},
41+
{
42+
"operator": "is",
43+
"type": "statusCode",
44+
"target": 200
45+
},
46+
{
47+
"operator": "A non existent operator",
48+
"type": "body",
49+
"target": {
50+
"xPath": "//html/head/title",
51+
"operator": "contains",
52+
"targetValue": "Example"
53+
}
54+
}
55+
],
56+
"configVariables": []
57+
},
58+
"options": {
59+
"monitor_options": {
60+
"notify_audit": false,
61+
"locked": false,
62+
"include_tags": true,
63+
"new_host_delay": 300,
64+
"notify_no_data": false,
65+
"renotify_interval": 0
66+
},
67+
"retry": {
68+
"count": 0,
69+
"interval": 300
70+
},
71+
"min_location_failed": 1,
72+
"min_failure_duration": 0,
73+
"tick_every": 60
74+
}
75+
}"""
76+
config = Configuration()
77+
deserialized_data = validate_and_convert_types(
78+
json.loads(body), (SyntheticsAPITest,), ["received_data"], True, True, config)
79+
assert isinstance(deserialized_data, SyntheticsAPITest)
80+
assert len(deserialized_data.config.assertions) == 3
81+
assert deserialized_data.config.assertions[2].operator == "A non existent operator"
82+
83+
84+
def test_unknown_nested_enum_in_list():
85+
body = """{
86+
"status": "live",
87+
"public_id": "2fx-64b-fb8",
88+
"tags": [
89+
"mini-website",
90+
"team:synthetics",
91+
"firefox",
92+
"synthetics-ci-browser",
93+
"edge",
94+
"chrome"
95+
],
96+
"locations": [
97+
"aws:ap-northeast-1",
98+
"aws:eu-north-1",
99+
"aws:eu-west-3",
100+
"aws:eu-central-1"
101+
],
102+
"message": "This mini-website check failed, please investigate why. @slack-synthetics-ops-worker",
103+
"name": "Mini Website - Click Trap",
104+
"monitor_id": 7647262,
105+
"type": "browser",
106+
"created_at": "2018-12-20T13:19:23.734004+00:00",
107+
"modified_at": "2021-06-30T15:46:49.387631+00:00",
108+
"config": {
109+
"variables": [],
110+
"setCookie": "",
111+
"request": {
112+
"url": "http://34.95.79.70/click-trap",
113+
"headers": {},
114+
"method": "GET"
115+
},
116+
"assertions": [],
117+
"configVariables": []
118+
},
119+
"options": {
120+
"ci": {
121+
"executionRule": "blocking"
122+
},
123+
"retry": {
124+
"count": 1,
125+
"interval": 1000
126+
},
127+
"min_location_failed": 1,
128+
"min_failure_duration": 0,
129+
"noScreenshot": false,
130+
"tick_every": 300,
131+
"forwardProxy": false,
132+
"disableCors": false,
133+
"device_ids": [
134+
"chrome.laptop_large",
135+
"firefox.laptop_large",
136+
"A non existent device ID"
137+
],
138+
"monitor_options": {
139+
"renotify_interval": 360
140+
},
141+
"ignoreServerCertificateError": true
142+
}
143+
}"""
144+
config = Configuration()
145+
deserialized_data = validate_and_convert_types(
146+
json.loads(body), (SyntheticsBrowserTest,), ["received_data"], True, True, config)
147+
assert isinstance(deserialized_data, SyntheticsBrowserTest)
148+
assert len(deserialized_data.options.device_ids) == 3
149+
assert str(deserialized_data.options.device_ids[2]) == "A non existent device ID"
150+
151+
152+
def test_unknown_top_level_enum():
153+
body = """{
154+
"status": "live",
155+
"public_id": "g6d-gcm-pdq",
156+
"tags": [],
157+
"locations": [
158+
"aws:eu-central-1",
159+
"aws:ap-northeast-1"
160+
],
161+
"message": "",
162+
"name": "Check on www.10.0.0.1.xip.io",
163+
"monitor_id": 7464050,
164+
"type": "A non existent test type",
165+
"created_at": "2018-12-07T17:30:49.785089+00:00",
166+
"modified_at": "2019-09-04T17:01:09.921070+00:00",
167+
"subtype": "http",
168+
"config": {
169+
"request": {
170+
"url": "https://www.10.0.0.1.xip.io",
171+
"method": "GET",
172+
"timeout": 30
173+
},
174+
"assertions": [
175+
{
176+
"operator": "is",
177+
"type": "statusCode",
178+
"target": 200
179+
}
180+
]
181+
},
182+
"options": {
183+
"tick_every": 60
184+
}
185+
}"""
186+
config = Configuration()
187+
deserialized_data = validate_and_convert_types(
188+
json.loads(body), (SyntheticsBrowserTest,), ["received_data"], True, True, config)
189+
assert isinstance(deserialized_data, SyntheticsBrowserTest)
190+
assert str(deserialized_data.type) == "A non existent test type"
191+
192+
193+
def test_unknown_nested_enum():
194+
body = """{
195+
"status": "live",
196+
"public_id": "g6d-gcm-pdq",
197+
"tags": [],
198+
"locations": [
199+
"aws:eu-central-1",
200+
"aws:ap-northeast-1"
201+
],
202+
"message": "",
203+
"name": "Check on www.10.0.0.1.xip.io",
204+
"monitor_id": 7464050,
205+
"type": "api",
206+
"created_at": "2018-12-07T17:30:49.785089+00:00",
207+
"modified_at": "2019-09-04T17:01:09.921070+00:00",
208+
"subtype": "http",
209+
"config": {
210+
"request": {
211+
"url": "https://www.10.0.0.1.xip.io",
212+
"method": "A non existent method",
213+
"timeout": 30
214+
},
215+
"assertions": [
216+
{
217+
"operator": "is",
218+
"type": "statusCode",
219+
"target": 200
220+
}
221+
]
222+
},
223+
"options": {
224+
"tick_every": 60
225+
}
226+
}"""
227+
config = Configuration()
228+
deserialized_data = validate_and_convert_types(
229+
json.loads(body), (SyntheticsAPITest,), ["received_data"], True, True, config)
230+
assert isinstance(deserialized_data, SyntheticsAPITest)
231+
assert isinstance(deserialized_data.config.request, SyntheticsTestRequest)
232+
assert str(deserialized_data.config.request.method) == "A non existent method"
233+
234+
235+
def test_unknown_nested_one_of():
236+
body = """{
237+
"data": {
238+
"type": "archives",
239+
"id": "n_XDSxVpScepiBnyhysj_A",
240+
"attributes": {
241+
"name": "my first azure archive",
242+
"query": "service:toto",
243+
"state": "UNKNOWN",
244+
"destination": {
245+
"container": "my-container",
246+
"storage_account": "storageaccount",
247+
"path": "/path/blou",
248+
"type": "A non existent destination",
249+
"integration": {
250+
"tenant_id": "tf-TestAccDatadogLogsArchiveAzure_basic-local-1624981538",
251+
"client_id": "testc7f6-1234-5678-9101-3fcbf464test"
252+
}
253+
},
254+
"rehydration_tags": [],
255+
"include_tags": false
256+
}
257+
}
258+
}"""
259+
config = ConfigurationV2()
260+
deserialized_data = validate_and_convert_types_v2(
261+
json.loads(body), (LogsArchive,), ["received_data"], True, True, config)
262+
assert isinstance(deserialized_data, LogsArchive)
263+
assert isinstance(deserialized_data.data.attributes.destination, LogsArchiveDestination)
264+
assert deserialized_data.data.attributes.destination.type == "A non existent destination"

0 commit comments

Comments
 (0)