Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powerpack pagination and test fixes #1716

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2023-10-10 13:47:33.127844",
"spec_repo_commit": "afb48804"
"regenerated": "2023-10-12 13:31:17.639000",
"spec_repo_commit": "6653b14d"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2023-10-10 13:47:33.153228",
"spec_repo_commit": "afb48804"
"regenerated": "2023-10-12 13:31:17.656414",
"spec_repo_commit": "6653b14d"
}
}
}
16 changes: 16 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23874,6 +23874,18 @@ paths:
get:
description: Get a list of all powerpacks.
operationId: ListPowerpacks
parameters:
- description: Maximum number of powerpacks in the response.
example: 25
in: query
name: page[limit]
required: false
schema:
default: 25
format: int64
maximum: 1000
type: integer
- $ref: '#/components/parameters/PageOffset'
responses:
'200':
content:
Expand All @@ -23891,6 +23903,10 @@ paths:
summary: Get all powerpacks
tags:
- Powerpack
x-pagination:
limitParam: page[limit]
pageOffsetParam: page[offset]
resultsPath: data
post:
description: Create a powerpack.
operationId: CreatePowerpack
Expand Down
2 changes: 1 addition & 1 deletion examples/v2/powerpack/CreatePowerpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
y=0,
),
),
name="Sample Powerpack",
name="Example-Powerpack",
tags=[
"tag:sample",
],
Expand Down
4 changes: 3 additions & 1 deletion examples/v2/powerpack/ListPowerpacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = PowerpackApi(api_client)
response = api_instance.list_powerpacks()
response = api_instance.list_powerpacks(
page_limit=1000,
)

print(response)
15 changes: 15 additions & 0 deletions examples/v2/powerpack/ListPowerpacks_1173755071.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Get all powerpacks returns "OK" response with pagination
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.powerpack_api import PowerpackApi

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = PowerpackApi(api_client)
items = api_instance.list_powerpacks_with_pagination(
page_limit=2,
)
for item in items:
print(item)
2 changes: 1 addition & 1 deletion examples/v2/powerpack/UpdatePowerpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
y=0,
),
),
name="Sample Powerpack",
name="Example-Powerpack",
tags=[
"tag:sample",
],
Expand Down
76 changes: 74 additions & 2 deletions src/datadog_api_client/v2/api/powerpack_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import Any, Dict
import collections
from typing import Any, Dict, Union

from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
from datadog_api_client.configuration import Configuration
from datadog_api_client.model_utils import (
set_attribute_from_path,
get_attribute_from_path,
UnsetType,
unset,
)
from datadog_api_client.v2.model.list_powerpacks_response import ListPowerpacksResponse
from datadog_api_client.v2.model.powerpack_data import PowerpackData
from datadog_api_client.v2.model.powerpack_response import PowerpackResponse
from datadog_api_client.v2.model.powerpack import Powerpack

Expand Down Expand Up @@ -105,7 +113,21 @@ def __init__(self, api_client=None):
"http_method": "GET",
"version": "v2",
},
params_map={},
params_map={
"page_limit": {
"validation": {
"inclusive_maximum": 1000,
},
"openapi_types": (int,),
"attribute": "page[limit]",
"location": "query",
},
"page_offset": {
"openapi_types": (int,),
"attribute": "page[offset]",
"location": "query",
},
},
headers_map={
"accept": ["application/json"],
},
Expand Down Expand Up @@ -191,16 +213,66 @@ def get_powerpack(

def list_powerpacks(
self,
*,
page_limit: Union[int, UnsetType] = unset,
page_offset: Union[int, UnsetType] = unset,
) -> ListPowerpacksResponse:
"""Get all powerpacks.

Get a list of all powerpacks.

:param page_limit: Maximum number of powerpacks in the response.
:type page_limit: int, optional
:param page_offset: Specific offset to use as the beginning of the returned page.
:type page_offset: int, optional
:rtype: ListPowerpacksResponse
"""
kwargs: Dict[str, Any] = {}
if page_limit is not unset:
kwargs["page_limit"] = page_limit

if page_offset is not unset:
kwargs["page_offset"] = page_offset

return self._list_powerpacks_endpoint.call_with_http_info(**kwargs)

def list_powerpacks_with_pagination(
self,
*,
page_limit: Union[int, UnsetType] = unset,
page_offset: Union[int, UnsetType] = unset,
) -> collections.abc.Iterable[PowerpackData]:
"""Get all powerpacks.

Provide a paginated version of :meth:`list_powerpacks`, returning all items.

:param page_limit: Maximum number of powerpacks in the response.
:type page_limit: int, optional
:param page_offset: Specific offset to use as the beginning of the returned page.
:type page_offset: int, optional

:return: A generator of paginated results.
:rtype: collections.abc.Iterable[PowerpackData]
"""
kwargs: Dict[str, Any] = {}
if page_limit is not unset:
kwargs["page_limit"] = page_limit

if page_offset is not unset:
kwargs["page_offset"] = page_offset

local_page_size = get_attribute_from_path(kwargs, "page_limit", 25)
endpoint = self._list_powerpacks_endpoint
set_attribute_from_path(kwargs, "page_limit", local_page_size, endpoint.params_map)
pagination = {
"limit_value": local_page_size,
"results_path": "data",
"page_offset_param": "page_offset",
"endpoint": endpoint,
"kwargs": kwargs,
}
return endpoint.call_with_http_info_paginated(pagination)

def update_powerpack(
self,
powerpack_id: str,
Expand Down
11 changes: 8 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,17 @@ def expect_response_has_field(context, response_path, field):

@then(parsers.parse('the response "{response_path}" has item with field "{key_path}" with value {value}'))
def expect_array_contains_object(context, response_path, key_path, value):
from glom.core import PathAccessError

response_value = glom(context["api_request"]["response"][0], response_path)
test_value = json.loads(Template(value).render(**context))
for response_item in response_value:
response_item_value = glom(response_item, key_path)
if response_item_value == test_value:
return
try:
response_item_value = glom(response_item, key_path)
if response_item_value == test_value:
return
except PathAccessError:
pass
raise AssertionError(f'could not find key value pair in object array: "{key_path}": "{test_value}"')


Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-09-26T21:29:30.230Z
2023-10-11T18:44:47.026Z
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
interactions:
- request:
body: '{"data":{"attributes":{"description":"Sample powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"}}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"name":"Sample
Powerpack","tags":["tag:sample"],"template_variables":[{"defaults":["*"],"name":"sample"}]},"type":"powerpack"}}'
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"}}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"name":"Test-Create_a_new_dashboard_with_powerpack_widget-1697049887","tags":["tag:sample"],"template_variables":[{"defaults":["*"],"name":"sample"}]},"type":"powerpack"}}'
headers:
accept:
- application/json
Expand All @@ -12,9 +11,9 @@ interactions:
uri: https://api.datadoghq.com/api/v2/powerpacks
response:
body:
string: '{"data":{"type":"powerpack","id":"c71559ce-5cb3-11ee-9164-da7ad0900002","attributes":{"name":"Sample
Powerpack","description":"Sample powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"},"id":8492163139927418}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"template_variables":[{"defaults":["*"],"name":"sample"}],"tags":["tag:sample"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}
string: '{"data":{"type":"powerpack","id":"40778356-6866-11ee-812e-da7ad0900002","attributes":{"name":"Test-Create_a_new_dashboard_with_powerpack_widget-1697049887","description":"Sample
powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"},"id":6750168893668334}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"template_variables":[{"defaults":["*"],"name":"sample"}],"tags":["tag:sample"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}

'
headers:
Expand All @@ -24,8 +23,8 @@ interactions:
code: 200
message: OK
- request:
body: '{"description":"description","is_read_only":false,"layout_type":"ordered","title":"Test-Create_a_new_dashboard_with_powerpack_widget-1695763770
with powerpack widget","widgets":[{"definition":{"powerpack_id":"c71559ce-5cb3-11ee-9164-da7ad0900002","template_variables":{"controlled_by_powerpack":[{"name":"foo","prefix":"bar","values":["baz","qux","quuz"]}],"controlled_externally":[]},"type":"powerpack"},"layout":{"height":2,"is_column_break":false,"width":2,"x":1,"y":1}}]}'
body: '{"description":"description","is_read_only":false,"layout_type":"ordered","title":"Test-Create_a_new_dashboard_with_powerpack_widget-1697049887
with powerpack widget","widgets":[{"definition":{"powerpack_id":"40778356-6866-11ee-812e-da7ad0900002","template_variables":{"controlled_by_powerpack":[{"name":"foo","prefix":"bar","values":["baz","qux","quuz"]}],"controlled_externally":[]},"type":"powerpack"},"layout":{"height":2,"is_column_break":false,"width":2,"x":1,"y":1}}]}'
headers:
accept:
- application/json
Expand All @@ -35,8 +34,8 @@ interactions:
uri: https://api.datadoghq.com/api/v1/dashboard
response:
body:
string: '{"id":"qk3-bn8-9pa","title":"Test-Create_a_new_dashboard_with_powerpack_widget-1695763770
with powerpack widget","description":"description","author_handle":"[email protected]","author_name":null,"layout_type":"ordered","url":"/dashboard/qk3-bn8-9pa/test-createanewdashboardwithpowerpackwidget-1695763770-with-powerpack-widget","is_read_only":false,"template_variables":null,"widgets":[{"definition":{"powerpack_id":"c71559ce-5cb3-11ee-9164-da7ad0900002","template_variables":{"controlled_by_powerpack":[{"name":"foo","prefix":"bar","values":["baz","qux","quuz"]}],"controlled_externally":[]},"type":"powerpack"},"layout":{"height":2,"is_column_break":false,"width":2,"x":1,"y":1},"id":5618921727592736}],"notify_list":null,"created_at":"2023-09-26T21:29:30.677263+00:00","modified_at":"2023-09-26T21:29:30.677263+00:00","restricted_roles":[]}
string: '{"id":"wap-jgr-c99","title":"Test-Create_a_new_dashboard_with_powerpack_widget-1697049887
with powerpack widget","description":"description","author_handle":"[email protected]","author_name":null,"layout_type":"ordered","url":"/dashboard/wap-jgr-c99/test-createanewdashboardwithpowerpackwidget-1697049887-with-powerpack-widget","is_read_only":false,"template_variables":null,"widgets":[{"definition":{"powerpack_id":"40778356-6866-11ee-812e-da7ad0900002","template_variables":{"controlled_by_powerpack":[{"name":"foo","prefix":"bar","values":["baz","qux","quuz"]}],"controlled_externally":[]},"type":"powerpack"},"layout":{"height":2,"is_column_break":false,"width":2,"x":1,"y":1},"id":2124665012947075}],"notify_list":null,"created_at":"2023-10-11T18:44:47.485150+00:00","modified_at":"2023-10-11T18:44:47.485150+00:00","restricted_roles":[]}

'
headers:
Expand All @@ -51,10 +50,10 @@ interactions:
accept:
- application/json
method: DELETE
uri: https://api.datadoghq.com/api/v1/dashboard/qk3-bn8-9pa
uri: https://api.datadoghq.com/api/v1/dashboard/wap-jgr-c99
response:
body:
string: '{"deleted_dashboard_id":"qk3-bn8-9pa"}
string: '{"deleted_dashboard_id":"wap-jgr-c99"}

'
headers:
Expand All @@ -69,7 +68,7 @@ interactions:
accept:
- '*/*'
method: DELETE
uri: https://api.datadoghq.com/api/v2/powerpacks/c71559ce-5cb3-11ee-9164-da7ad0900002
uri: https://api.datadoghq.com/api/v2/powerpacks/40778356-6866-11ee-812e-da7ad0900002
response:
body:
string: ''
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-09-19T20:34:19.014Z
2023-10-11T15:48:55.126Z
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
interactions:
- request:
body: '{"data":{"attributes":{"description":"Sample powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"}}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"name":"Sample
Powerpack","tags":["tag:sample"],"template_variables":[{"defaults":["*"],"name":"sample"}]},"type":"powerpack"}}'
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"}}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"name":"Test-Create_a_new_powerpack_returns_OK_response-1697039335","tags":["tag:sample"],"template_variables":[{"defaults":["*"],"name":"sample"}]},"type":"powerpack"}}'
headers:
accept:
- application/json
Expand All @@ -12,9 +11,9 @@ interactions:
uri: https://api.datadoghq.com/api/v2/powerpacks
response:
body:
string: '{"data":{"type":"powerpack","id":"e88f5556-572b-11ee-b081-da7ad0900002","attributes":{"name":"Sample
Powerpack","description":"Sample powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"},"id":5644443297535288}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"template_variables":[{"defaults":["*"],"name":"sample"}],"tags":["tag:sample"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}
string: '{"data":{"type":"powerpack","id":"aef5d85a-684d-11ee-ae79-da7ad0900002","attributes":{"name":"Test-Create_a_new_powerpack_returns_OK_response-1697039335","description":"Sample
powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"},"id":5789473441337322}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"template_variables":[{"defaults":["*"],"name":"sample"}],"tags":["tag:sample"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}

'
headers:
Expand All @@ -29,7 +28,7 @@ interactions:
accept:
- '*/*'
method: DELETE
uri: https://api.datadoghq.com/api/v2/powerpacks/e88f5556-572b-11ee-b081-da7ad0900002
uri: https://api.datadoghq.com/api/v2/powerpacks/aef5d85a-684d-11ee-ae79-da7ad0900002
response:
body:
string: ''
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-09-19T20:34:19.880Z
2023-10-11T15:48:55.488Z
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
interactions:
- request:
body: '{"data":{"attributes":{"description":"Sample powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"}}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"name":"Sample
Powerpack","tags":["tag:sample"],"template_variables":[{"defaults":["*"],"name":"sample"}]},"type":"powerpack"}}'
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"}}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"name":"Test-Delete_a_powerpack_returns_OK_response-1697039335","tags":["tag:sample"],"template_variables":[{"defaults":["*"],"name":"sample"}]},"type":"powerpack"}}'
headers:
accept:
- application/json
Expand All @@ -12,9 +11,9 @@ interactions:
uri: https://api.datadoghq.com/api/v2/powerpacks
response:
body:
string: '{"data":{"type":"powerpack","id":"e918c048-572b-11ee-8cec-da7ad0900002","attributes":{"name":"Sample
Powerpack","description":"Sample powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"},"id":8519959434065727}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"template_variables":[{"defaults":["*"],"name":"sample"}],"tags":["tag:sample"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}
string: '{"data":{"type":"powerpack","id":"af2eedc0-684d-11ee-bf6c-da7ad0900002","attributes":{"name":"Test-Delete_a_powerpack_returns_OK_response-1697039335","description":"Sample
powerpack","group_widget":{"definition":{"layout_type":"ordered","show_title":true,"title":"Sample
Powerpack","type":"group","widgets":[{"definition":{"content":"test","type":"note"},"id":6052073873114005}]},"layout":{"height":3,"width":12,"x":0,"y":0}},"template_variables":[{"defaults":["*"],"name":"sample"}],"tags":["tag:sample"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}

'
headers:
Expand All @@ -29,7 +28,7 @@ interactions:
accept:
- '*/*'
method: DELETE
uri: https://api.datadoghq.com/api/v2/powerpacks/e918c048-572b-11ee-8cec-da7ad0900002
uri: https://api.datadoghq.com/api/v2/powerpacks/af2eedc0-684d-11ee-bf6c-da7ad0900002
response:
body:
string: ''
Expand All @@ -45,10 +44,10 @@ interactions:
accept:
- '*/*'
method: DELETE
uri: https://api.datadoghq.com/api/v2/powerpacks/e918c048-572b-11ee-8cec-da7ad0900002
uri: https://api.datadoghq.com/api/v2/powerpacks/af2eedc0-684d-11ee-bf6c-da7ad0900002
response:
body:
string: '{"errors":["Powerpack with ID e918c048-572b-11ee-8cec-da7ad0900002
string: '{"errors":["Powerpack with ID af2eedc0-684d-11ee-bf6c-da7ad0900002
not found"]}'
headers:
content-type:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-09-19T20:34:21.001Z
2023-10-11T15:48:56.104Z
Loading
Loading