|
| 1 | +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 2 | +# This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 3 | +# Copyright 2019-Present Datadog, Inc. |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +import collections |
| 7 | +from typing import Any, Dict, Union |
| 8 | + |
| 9 | +from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint |
| 10 | +from datadog_api_client.configuration import Configuration |
| 11 | +from datadog_api_client.model_utils import ( |
| 12 | + set_attribute_from_path, |
| 13 | + get_attribute_from_path, |
| 14 | + UnsetType, |
| 15 | + unset, |
| 16 | +) |
| 17 | +from datadog_api_client.v2.model.flaky_tests_search_response import FlakyTestsSearchResponse |
| 18 | +from datadog_api_client.v2.model.flaky_tests_search_request import FlakyTestsSearchRequest |
| 19 | +from datadog_api_client.v2.model.flaky_test import FlakyTest |
| 20 | + |
| 21 | + |
| 22 | +class TestOptimizationApi: |
| 23 | + """ |
| 24 | + Search and manage flaky tests through Test Optimization. See the `Test Optimization page <https://docs.datadoghq.com/tests/>`_ for more information. |
| 25 | + """ |
| 26 | + |
| 27 | + def __init__(self, api_client=None): |
| 28 | + if api_client is None: |
| 29 | + api_client = ApiClient(Configuration()) |
| 30 | + self.api_client = api_client |
| 31 | + |
| 32 | + self._search_flaky_tests_endpoint = _Endpoint( |
| 33 | + settings={ |
| 34 | + "response_type": (FlakyTestsSearchResponse,), |
| 35 | + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], |
| 36 | + "endpoint_path": "/api/v2/test/flaky-test-management/tests", |
| 37 | + "operation_id": "search_flaky_tests", |
| 38 | + "http_method": "POST", |
| 39 | + "version": "v2", |
| 40 | + }, |
| 41 | + params_map={ |
| 42 | + "body": { |
| 43 | + "openapi_types": (FlakyTestsSearchRequest,), |
| 44 | + "location": "body", |
| 45 | + }, |
| 46 | + }, |
| 47 | + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, |
| 48 | + api_client=api_client, |
| 49 | + ) |
| 50 | + |
| 51 | + def search_flaky_tests( |
| 52 | + self, |
| 53 | + *, |
| 54 | + body: Union[FlakyTestsSearchRequest, UnsetType] = unset, |
| 55 | + ) -> FlakyTestsSearchResponse: |
| 56 | + """Search flaky tests. |
| 57 | +
|
| 58 | + List endpoint returning flaky tests from Flaky Test Management. Results are paginated. |
| 59 | +
|
| 60 | + :type body: FlakyTestsSearchRequest, optional |
| 61 | + :rtype: FlakyTestsSearchResponse |
| 62 | + """ |
| 63 | + kwargs: Dict[str, Any] = {} |
| 64 | + if body is not unset: |
| 65 | + kwargs["body"] = body |
| 66 | + |
| 67 | + return self._search_flaky_tests_endpoint.call_with_http_info(**kwargs) |
| 68 | + |
| 69 | + def search_flaky_tests_with_pagination( |
| 70 | + self, |
| 71 | + *, |
| 72 | + body: Union[FlakyTestsSearchRequest, UnsetType] = unset, |
| 73 | + ) -> collections.abc.Iterable[FlakyTest]: |
| 74 | + """Search flaky tests. |
| 75 | +
|
| 76 | + Provide a paginated version of :meth:`search_flaky_tests`, returning all items. |
| 77 | +
|
| 78 | + :type body: FlakyTestsSearchRequest, optional |
| 79 | +
|
| 80 | + :return: A generator of paginated results. |
| 81 | + :rtype: collections.abc.Iterable[FlakyTest] |
| 82 | + """ |
| 83 | + kwargs: Dict[str, Any] = {} |
| 84 | + if body is not unset: |
| 85 | + kwargs["body"] = body |
| 86 | + |
| 87 | + local_page_size = get_attribute_from_path(kwargs, "body.data.attributes.page.limit", 10) |
| 88 | + endpoint = self._search_flaky_tests_endpoint |
| 89 | + set_attribute_from_path(kwargs, "body.data.attributes.page.limit", local_page_size, endpoint.params_map) |
| 90 | + pagination = { |
| 91 | + "limit_value": local_page_size, |
| 92 | + "results_path": "data", |
| 93 | + "cursor_param": "body.data.attributes.page.cursor", |
| 94 | + "cursor_path": "meta.pagination.next_page", |
| 95 | + "endpoint": endpoint, |
| 96 | + "kwargs": kwargs, |
| 97 | + } |
| 98 | + return endpoint.call_with_http_info_paginated(pagination) |
0 commit comments