Skip to content

Commit 24bbd9f

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination extension to synthetics tests (#1640)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 0a40161 commit 24bbd9f

7 files changed

+124
-13
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.5",
7-
"regenerated": "2023-08-30 08:42:52.326487",
8-
"spec_repo_commit": "fee86b40"
7+
"regenerated": "2023-08-30 11:45:23.706840",
8+
"spec_repo_commit": "2f2fd804"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-08-30 08:42:52.374431",
13-
"spec_repo_commit": "fee86b40"
12+
"regenerated": "2023-08-30 11:45:23.724782",
13+
"spec_repo_commit": "2f2fd804"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27990,14 +27990,19 @@ paths:
2799027990
- description: Used for pagination. The number of tests returned in the page.
2799127991
in: query
2799227992
name: page_size
27993+
required: false
2799327994
schema:
27994-
type: string
27995+
default: 100
27996+
format: int64
27997+
type: integer
2799527998
- description: Used for pagination. Which page you want to retrieve. Starts
2799627999
at zero.
2799728000
in: query
2799828001
name: page_number
28002+
required: false
2799928003
schema:
28000-
type: string
28004+
format: int64
28005+
type: integer
2800128006
responses:
2800228007
'200':
2800328008
content:
@@ -28027,6 +28032,10 @@ paths:
2802728032
summary: Get the list of all Synthetic tests
2802828033
tags:
2802928034
- Synthetics
28035+
x-pagination:
28036+
limitParam: page_size
28037+
pageParam: page_number
28038+
resultsPath: tests
2803028039
/api/v1/synthetics/tests/api:
2803128040
post:
2803228041
description: Create a Synthetic API test.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Get the list of all Synthetic tests returns "OK - Returns the list of all Synthetic tests." response with pagination
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v1.api.synthetics_api import SyntheticsApi
7+
8+
configuration = Configuration()
9+
with ApiClient(configuration) as api_client:
10+
api_instance = SyntheticsApi(api_client)
11+
items = api_instance.list_tests_with_pagination(
12+
page_size=2,
13+
)
14+
for item in items:
15+
print(item)

src/datadog_api_client/v1/api/synthetics_api.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
# Copyright 2019-Present Datadog, Inc.
44
from __future__ import annotations
55

6+
import collections
67
from typing import Any, Dict, List, Union
78

89
from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
910
from datadog_api_client.configuration import Configuration
1011
from datadog_api_client.model_utils import (
12+
set_attribute_from_path,
13+
get_attribute_from_path,
1114
UnsetType,
1215
unset,
1316
)
@@ -18,6 +21,7 @@
1821
)
1922
from datadog_api_client.v1.model.synthetics_private_location import SyntheticsPrivateLocation
2023
from datadog_api_client.v1.model.synthetics_list_tests_response import SyntheticsListTestsResponse
24+
from datadog_api_client.v1.model.synthetics_test_details import SyntheticsTestDetails
2125
from datadog_api_client.v1.model.synthetics_api_test import SyntheticsAPITest
2226
from datadog_api_client.v1.model.synthetics_browser_test import SyntheticsBrowserTest
2327
from datadog_api_client.v1.model.synthetics_get_browser_test_latest_results_response import (
@@ -29,7 +33,6 @@
2933
from datadog_api_client.v1.model.synthetics_trigger_ci_tests_response import SyntheticsTriggerCITestsResponse
3034
from datadog_api_client.v1.model.synthetics_trigger_body import SyntheticsTriggerBody
3135
from datadog_api_client.v1.model.synthetics_ci_test_body import SyntheticsCITestBody
32-
from datadog_api_client.v1.model.synthetics_test_details import SyntheticsTestDetails
3336
from datadog_api_client.v1.model.synthetics_get_api_test_latest_results_response import (
3437
SyntheticsGetAPITestLatestResultsResponse,
3538
)
@@ -562,12 +565,12 @@ def __init__(self, api_client=None):
562565
},
563566
params_map={
564567
"page_size": {
565-
"openapi_types": (str,),
568+
"openapi_types": (int,),
566569
"attribute": "page_size",
567570
"location": "query",
568571
},
569572
"page_number": {
570-
"openapi_types": (str,),
573+
"openapi_types": (int,),
571574
"attribute": "page_number",
572575
"location": "query",
573576
},
@@ -1125,17 +1128,17 @@ def list_locations(
11251128
def list_tests(
11261129
self,
11271130
*,
1128-
page_size: Union[str, UnsetType] = unset,
1129-
page_number: Union[str, UnsetType] = unset,
1131+
page_size: Union[int, UnsetType] = unset,
1132+
page_number: Union[int, UnsetType] = unset,
11301133
) -> SyntheticsListTestsResponse:
11311134
"""Get the list of all Synthetic tests.
11321135
11331136
Get the list of all Synthetic tests.
11341137
11351138
:param page_size: Used for pagination. The number of tests returned in the page.
1136-
:type page_size: str, optional
1139+
:type page_size: int, optional
11371140
:param page_number: Used for pagination. Which page you want to retrieve. Starts at zero.
1138-
:type page_number: str, optional
1141+
:type page_number: int, optional
11391142
:rtype: SyntheticsListTestsResponse
11401143
"""
11411144
kwargs: Dict[str, Any] = {}
@@ -1147,6 +1150,43 @@ def list_tests(
11471150

11481151
return self._list_tests_endpoint.call_with_http_info(**kwargs)
11491152

1153+
def list_tests_with_pagination(
1154+
self,
1155+
*,
1156+
page_size: Union[int, UnsetType] = unset,
1157+
page_number: Union[int, UnsetType] = unset,
1158+
) -> collections.abc.Iterable[SyntheticsTestDetails]:
1159+
"""Get the list of all Synthetic tests.
1160+
1161+
Provide a paginated version of :meth:`list_tests`, returning all items.
1162+
1163+
:param page_size: Used for pagination. The number of tests returned in the page.
1164+
:type page_size: int, optional
1165+
:param page_number: Used for pagination. Which page you want to retrieve. Starts at zero.
1166+
:type page_number: int, optional
1167+
1168+
:return: A generator of paginated results.
1169+
:rtype: collections.abc.Iterable[SyntheticsTestDetails]
1170+
"""
1171+
kwargs: Dict[str, Any] = {}
1172+
if page_size is not unset:
1173+
kwargs["page_size"] = page_size
1174+
1175+
if page_number is not unset:
1176+
kwargs["page_number"] = page_number
1177+
1178+
local_page_size = get_attribute_from_path(kwargs, "page_size", 100)
1179+
endpoint = self._list_tests_endpoint
1180+
set_attribute_from_path(kwargs, "page_size", local_page_size, endpoint.params_map)
1181+
pagination = {
1182+
"limit_value": local_page_size,
1183+
"results_path": "tests",
1184+
"page_param": "page_number",
1185+
"endpoint": endpoint,
1186+
"kwargs": kwargs,
1187+
}
1188+
return endpoint.call_with_http_info_paginated(pagination)
1189+
11501190
def trigger_ci_tests(
11511191
self,
11521192
body: SyntheticsCITestBody,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023-08-30T09:42:25.568Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
accept:
6+
- application/json
7+
method: GET
8+
uri: https://api.datadoghq.com/api/v1/synthetics/tests?page_size=2&page_number=0
9+
response:
10+
body:
11+
string: '{"tests":[{"public_id":"888-nvp-kbw","name":"tf-TestAccDatadogSyntheticsTestBrowserMML_Basic-local-1689951468-updated","status":"paused","type":"browser","tags":["foo:bar","baz"],"created_at":"2023-07-21T14:57:51.688079+00:00","modified_at":"2023-07-21T14:58:21.332326+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify
12+
@datadog.user","options":{"device_ids":["laptop_large"],"min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":126283369,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}},{"public_id":"i9r-v4f-v3u","name":"tf-TestAccDatadogSyntheticsBrowserTest_Updated_RumSettings-local-1689951491-updated-rumsettings","status":"live","type":"browser","tags":["foo:bar","buz"],"created_at":"2023-07-21T14:58:17.635359+00:00","modified_at":"2023-08-28T14:37:49.734465+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","headers":{"Accept":"application/xml","X-Datadog-Trace-ID":"987654321"},"url":"https://docs.datadoghq.com"},"setCookie":"","variables":[{"example":"7956","name":"MY_PATTERN_VAR","pattern":"{{numeric(4)}}","secure":false,"type":"text"}]},"message":"Notify
13+
@pagerduty","options":{"device_ids":["chrome.laptop_large","chrome.tablet"],"ignoreServerCertificateError":false,"disableCors":false,"disableCsp":false,"noScreenshot":false,"tick_every":1800,"min_failure_duration":10,"min_location_failed":1,"retry":{"count":3,"interval":500},"monitor_options":{"renotify_interval":120},"ci":{"executionRule":"skipped"},"rumSettings":{"isEnabled":false},"enableProfiling":false,"enableSecurityTesting":false},"locations":["aws:eu-central-1"],"monitor_id":126283421,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}],"total":3}'
14+
headers:
15+
content-type:
16+
- application/json
17+
status:
18+
code: 200
19+
message: OK
20+
- request:
21+
body: null
22+
headers:
23+
accept:
24+
- application/json
25+
method: GET
26+
uri: https://api.datadoghq.com/api/v1/synthetics/tests?page_size=2&page_number=1
27+
response:
28+
body:
29+
string: '{"tests":[{"public_id":"p34-3up-y6p","name":"Example-Create_an_API_HTTP_test_returns_OK_Returns_the_created_test_details_response_1692944481","status":"live","type":"api","tags":["testing:api"],"created_at":"2023-08-25T06:21:21.640836+00:00","modified_at":"2023-08-25T06:21:21.640836+00:00","config":{"assertions":[{"operator":"is","property":"{{
30+
PROPERTY }}","target":"text/html","type":"header"},{"operator":"lessThan","target":2000,"type":"responseTime"},{"operator":"validatesJSONPath","target":{"jsonPath":"topKey","operator":"isNot","targetValue":"0"},"type":"body"},{"operator":"validatesXPath","target":{"xPath":"target-xpath","targetValue":"0","operator":"contains"},"type":"body"}],"configVariables":[{"example":"content-type","name":"PROPERTY","pattern":"content-type","type":"text"}],"request":{"certificate":{"cert":{"filename":"cert-filename","updatedAt":"2020-10-16T09:23:24.857Z"},"key":{"filename":"key-filename","updatedAt":"2020-10-16T09:23:24.857Z"}},"headers":{"unique":"examplecreateanapihttptestreturnsokreturnsthecreatedtestdetailsresponse1692944481"},"method":"GET","timeout":10,"url":"https://datadoghq.com","proxy":{"url":"https://datadoghq.com","headers":{}},"basicAuth":{"accessTokenUrl":"https://datadog-token.com","audience":"audience","clientId":"client-id","clientSecret":"client-secret","resource":"resource","scope":"yoyo","tokenApiAuthentication":"header","type":"oauth-client"},"persistCookies":true}},"message":"BDD
31+
test payload: synthetics_api_http_test_payload.json","options":{"accept_self_signed":false,"allow_insecure":true,"follow_redirects":true,"min_failure_duration":10,"min_location_failed":1,"monitor_name":"Example-Create_an_API_HTTP_test_returns_OK_Returns_the_created_test_details_response_1692944481","monitor_priority":5,"retry":{"count":3,"interval":10},"tick_every":60,"httpVersion":"http2"},"locations":["aws:us-east-2"],"subtype":"http","monitor_id":130283608,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}],"total":3}'
32+
headers:
33+
content-type:
34+
- application/json
35+
status:
36+
code: 200
37+
message: OK
38+
version: 1

tests/v1/features/synthetics.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,14 @@ Feature: Synthetics
534534
When the request is sent
535535
Then the response status is 200 OK - Returns the list of all Synthetic tests.
536536

537+
@replay-only @skip-validation @team:DataDog/synthetics-app @with-pagination
538+
Scenario: Get the list of all Synthetic tests returns "OK - Returns the list of all Synthetic tests." response with pagination
539+
Given new "ListTests" request
540+
And request contains "page_size" parameter with value 2
541+
When the request with pagination is sent
542+
Then the response status is 200 OK - Returns the list of all Synthetic tests.
543+
And the response has 3 items
544+
537545
@generated @skip @team:DataDog/synthetics-app
538546
Scenario: Get the list of all Synthetic tests returns "Synthetic Monitoring is not activated for the user." response
539547
Given new "ListTests" request

0 commit comments

Comments
 (0)