From 2ca82f593d9927aeea752c5e56a87b340cb40322 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:59:32 +0000 Subject: [PATCH] feat(api): OpenAPI spec update via Stainless API (#274) --- .stats.yml | 2 +- api.md | 6 +- src/cloudflare/_client.py | 8 + src/cloudflare/resources/__init__.py | 14 ++ .../resources/request_tracers/__init__.py | 33 +++ .../request_tracers/request_tracers.py | 80 ++++++ .../resources/request_tracers/traces.py | 232 ++++++++++++++++++ .../types/request_tracers/__init__.py | 5 + src/cloudflare/types/request_tracers/trace.py | 11 + .../request_tracers/trace_create_params.py | 80 ++++++ .../request_tracers/trace_create_response.py | 25 ++ .../types/request_tracers/trace_item.py | 49 ++++ .../request_tracers/test_traces.py | 206 ++++++++++++++++ 13 files changed, 749 insertions(+), 2 deletions(-) create mode 100644 src/cloudflare/resources/request_tracers/__init__.py create mode 100644 src/cloudflare/resources/request_tracers/request_tracers.py create mode 100644 src/cloudflare/resources/request_tracers/traces.py create mode 100644 src/cloudflare/types/request_tracers/trace.py create mode 100644 src/cloudflare/types/request_tracers/trace_create_params.py create mode 100644 src/cloudflare/types/request_tracers/trace_create_response.py create mode 100644 src/cloudflare/types/request_tracers/trace_item.py create mode 100644 tests/api_resources/request_tracers/test_traces.py diff --git a/.stats.yml b/.stats.yml index a9d90133735d..0818ecbb822b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 1250 +configured_endpoints: 1251 diff --git a/api.md b/api.md index 97a4a41bf3c5..73a847727922 100644 --- a/api.md +++ b/api.md @@ -4174,9 +4174,13 @@ Methods: Types: ```python -from cloudflare.types.request_tracers import Trace, TraceItem +from cloudflare.types.request_tracers import Trace, TraceItem, TraceCreateResponse ``` +Methods: + +- client.request_tracers.traces.create(account_identifier, \*\*params) -> TraceCreateResponse + # Rules ## Lists diff --git a/src/cloudflare/_client.py b/src/cloudflare/_client.py index dfd01609e7c6..d85574035e04 100644 --- a/src/cloudflare/_client.py +++ b/src/cloudflare/_client.py @@ -103,6 +103,7 @@ class Cloudflare(SyncAPIClient): pages: resources.Pages pcaps: resources.PCAPs registrar: resources.Registrar + request_tracers: resources.RequestTracers rules: resources.Rules storage: resources.Storage stream: resources.Stream @@ -257,6 +258,7 @@ def __init__( self.pages = resources.Pages(self) self.pcaps = resources.PCAPs(self) self.registrar = resources.Registrar(self) + self.request_tracers = resources.RequestTracers(self) self.rules = resources.Rules(self) self.storage = resources.Storage(self) self.stream = resources.Stream(self) @@ -514,6 +516,7 @@ class AsyncCloudflare(AsyncAPIClient): pages: resources.AsyncPages pcaps: resources.AsyncPCAPs registrar: resources.AsyncRegistrar + request_tracers: resources.AsyncRequestTracers rules: resources.AsyncRules storage: resources.AsyncStorage stream: resources.AsyncStream @@ -668,6 +671,7 @@ def __init__( self.pages = resources.AsyncPages(self) self.pcaps = resources.AsyncPCAPs(self) self.registrar = resources.AsyncRegistrar(self) + self.request_tracers = resources.AsyncRequestTracers(self) self.rules = resources.AsyncRules(self) self.storage = resources.AsyncStorage(self) self.stream = resources.AsyncStream(self) @@ -926,6 +930,7 @@ def __init__(self, client: Cloudflare) -> None: self.pages = resources.PagesWithRawResponse(client.pages) self.pcaps = resources.PCAPsWithRawResponse(client.pcaps) self.registrar = resources.RegistrarWithRawResponse(client.registrar) + self.request_tracers = resources.RequestTracersWithRawResponse(client.request_tracers) self.rules = resources.RulesWithRawResponse(client.rules) self.storage = resources.StorageWithRawResponse(client.storage) self.stream = resources.StreamWithRawResponse(client.stream) @@ -1015,6 +1020,7 @@ def __init__(self, client: AsyncCloudflare) -> None: self.pages = resources.AsyncPagesWithRawResponse(client.pages) self.pcaps = resources.AsyncPCAPsWithRawResponse(client.pcaps) self.registrar = resources.AsyncRegistrarWithRawResponse(client.registrar) + self.request_tracers = resources.AsyncRequestTracersWithRawResponse(client.request_tracers) self.rules = resources.AsyncRulesWithRawResponse(client.rules) self.storage = resources.AsyncStorageWithRawResponse(client.storage) self.stream = resources.AsyncStreamWithRawResponse(client.stream) @@ -1104,6 +1110,7 @@ def __init__(self, client: Cloudflare) -> None: self.pages = resources.PagesWithStreamingResponse(client.pages) self.pcaps = resources.PCAPsWithStreamingResponse(client.pcaps) self.registrar = resources.RegistrarWithStreamingResponse(client.registrar) + self.request_tracers = resources.RequestTracersWithStreamingResponse(client.request_tracers) self.rules = resources.RulesWithStreamingResponse(client.rules) self.storage = resources.StorageWithStreamingResponse(client.storage) self.stream = resources.StreamWithStreamingResponse(client.stream) @@ -1197,6 +1204,7 @@ def __init__(self, client: AsyncCloudflare) -> None: self.pages = resources.AsyncPagesWithStreamingResponse(client.pages) self.pcaps = resources.AsyncPCAPsWithStreamingResponse(client.pcaps) self.registrar = resources.AsyncRegistrarWithStreamingResponse(client.registrar) + self.request_tracers = resources.AsyncRequestTracersWithStreamingResponse(client.request_tracers) self.rules = resources.AsyncRulesWithStreamingResponse(client.rules) self.storage = resources.AsyncStorageWithStreamingResponse(client.storage) self.stream = resources.AsyncStreamWithStreamingResponse(client.stream) diff --git a/src/cloudflare/resources/__init__.py b/src/cloudflare/resources/__init__.py index 19790921911f..096d7cfd8ea4 100644 --- a/src/cloudflare/resources/__init__.py +++ b/src/cloudflare/resources/__init__.py @@ -520,6 +520,14 @@ ManagedHeadersWithStreamingResponse, AsyncManagedHeadersWithStreamingResponse, ) +from .request_tracers import ( + RequestTracers, + AsyncRequestTracers, + RequestTracersWithRawResponse, + AsyncRequestTracersWithRawResponse, + RequestTracersWithStreamingResponse, + AsyncRequestTracersWithStreamingResponse, +) from .brand_protection import ( BrandProtection, AsyncBrandProtection, @@ -970,6 +978,12 @@ "AsyncRegistrarWithRawResponse", "RegistrarWithStreamingResponse", "AsyncRegistrarWithStreamingResponse", + "RequestTracers", + "AsyncRequestTracers", + "RequestTracersWithRawResponse", + "AsyncRequestTracersWithRawResponse", + "RequestTracersWithStreamingResponse", + "AsyncRequestTracersWithStreamingResponse", "Rules", "AsyncRules", "RulesWithRawResponse", diff --git a/src/cloudflare/resources/request_tracers/__init__.py b/src/cloudflare/resources/request_tracers/__init__.py new file mode 100644 index 000000000000..f19a11ba800e --- /dev/null +++ b/src/cloudflare/resources/request_tracers/__init__.py @@ -0,0 +1,33 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .traces import ( + Traces, + AsyncTraces, + TracesWithRawResponse, + AsyncTracesWithRawResponse, + TracesWithStreamingResponse, + AsyncTracesWithStreamingResponse, +) +from .request_tracers import ( + RequestTracers, + AsyncRequestTracers, + RequestTracersWithRawResponse, + AsyncRequestTracersWithRawResponse, + RequestTracersWithStreamingResponse, + AsyncRequestTracersWithStreamingResponse, +) + +__all__ = [ + "Traces", + "AsyncTraces", + "TracesWithRawResponse", + "AsyncTracesWithRawResponse", + "TracesWithStreamingResponse", + "AsyncTracesWithStreamingResponse", + "RequestTracers", + "AsyncRequestTracers", + "RequestTracersWithRawResponse", + "AsyncRequestTracersWithRawResponse", + "RequestTracersWithStreamingResponse", + "AsyncRequestTracersWithStreamingResponse", +] diff --git a/src/cloudflare/resources/request_tracers/request_tracers.py b/src/cloudflare/resources/request_tracers/request_tracers.py new file mode 100644 index 000000000000..bf03ddeaa5e0 --- /dev/null +++ b/src/cloudflare/resources/request_tracers/request_tracers.py @@ -0,0 +1,80 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from .traces import ( + Traces, + AsyncTraces, + TracesWithRawResponse, + AsyncTracesWithRawResponse, + TracesWithStreamingResponse, + AsyncTracesWithStreamingResponse, +) +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource + +__all__ = ["RequestTracers", "AsyncRequestTracers"] + + +class RequestTracers(SyncAPIResource): + @cached_property + def traces(self) -> Traces: + return Traces(self._client) + + @cached_property + def with_raw_response(self) -> RequestTracersWithRawResponse: + return RequestTracersWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> RequestTracersWithStreamingResponse: + return RequestTracersWithStreamingResponse(self) + + +class AsyncRequestTracers(AsyncAPIResource): + @cached_property + def traces(self) -> AsyncTraces: + return AsyncTraces(self._client) + + @cached_property + def with_raw_response(self) -> AsyncRequestTracersWithRawResponse: + return AsyncRequestTracersWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncRequestTracersWithStreamingResponse: + return AsyncRequestTracersWithStreamingResponse(self) + + +class RequestTracersWithRawResponse: + def __init__(self, request_tracers: RequestTracers) -> None: + self._request_tracers = request_tracers + + @cached_property + def traces(self) -> TracesWithRawResponse: + return TracesWithRawResponse(self._request_tracers.traces) + + +class AsyncRequestTracersWithRawResponse: + def __init__(self, request_tracers: AsyncRequestTracers) -> None: + self._request_tracers = request_tracers + + @cached_property + def traces(self) -> AsyncTracesWithRawResponse: + return AsyncTracesWithRawResponse(self._request_tracers.traces) + + +class RequestTracersWithStreamingResponse: + def __init__(self, request_tracers: RequestTracers) -> None: + self._request_tracers = request_tracers + + @cached_property + def traces(self) -> TracesWithStreamingResponse: + return TracesWithStreamingResponse(self._request_tracers.traces) + + +class AsyncRequestTracersWithStreamingResponse: + def __init__(self, request_tracers: AsyncRequestTracers) -> None: + self._request_tracers = request_tracers + + @cached_property + def traces(self) -> AsyncTracesWithStreamingResponse: + return AsyncTracesWithStreamingResponse(self._request_tracers.traces) diff --git a/src/cloudflare/resources/request_tracers/traces.py b/src/cloudflare/resources/request_tracers/traces.py new file mode 100644 index 000000000000..faac2d453767 --- /dev/null +++ b/src/cloudflare/resources/request_tracers/traces.py @@ -0,0 +1,232 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict, Type, cast + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._utils import ( + maybe_transform, + async_maybe_transform, +) +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ..._wrappers import ResultWrapper +from ..._base_client import ( + make_request_options, +) +from ...types.request_tracers import TraceCreateResponse, trace_create_params + +__all__ = ["Traces", "AsyncTraces"] + + +class Traces(SyncAPIResource): + @cached_property + def with_raw_response(self) -> TracesWithRawResponse: + return TracesWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> TracesWithStreamingResponse: + return TracesWithStreamingResponse(self) + + def create( + self, + account_identifier: str, + *, + method: str, + url: str, + body: trace_create_params.Body | NotGiven = NOT_GIVEN, + context: trace_create_params.Context | NotGiven = NOT_GIVEN, + cookies: Dict[str, str] | NotGiven = NOT_GIVEN, + headers: Dict[str, str] | NotGiven = NOT_GIVEN, + protocol: str | NotGiven = NOT_GIVEN, + skip_response: bool | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> TraceCreateResponse: + """ + Request Trace + + Args: + account_identifier: Identifier + + method: HTTP Method of tracing request + + url: URL to which perform tracing request + + context: Additional request parameters + + cookies: Cookies added to tracing request + + headers: Headers added to tracing request + + protocol: HTTP Protocol of tracing request + + skip_response: Skip sending the request to the Origin server after all rules evaluation + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not account_identifier: + raise ValueError(f"Expected a non-empty value for `account_identifier` but received {account_identifier!r}") + return self._post( + f"/accounts/{account_identifier}/request-tracer/trace", + body=maybe_transform( + { + "method": method, + "url": url, + "body": body, + "context": context, + "cookies": cookies, + "headers": headers, + "protocol": protocol, + "skip_response": skip_response, + }, + trace_create_params.TraceCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper._unwrapper, + ), + cast_to=cast(Type[TraceCreateResponse], ResultWrapper[TraceCreateResponse]), + ) + + +class AsyncTraces(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncTracesWithRawResponse: + return AsyncTracesWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncTracesWithStreamingResponse: + return AsyncTracesWithStreamingResponse(self) + + async def create( + self, + account_identifier: str, + *, + method: str, + url: str, + body: trace_create_params.Body | NotGiven = NOT_GIVEN, + context: trace_create_params.Context | NotGiven = NOT_GIVEN, + cookies: Dict[str, str] | NotGiven = NOT_GIVEN, + headers: Dict[str, str] | NotGiven = NOT_GIVEN, + protocol: str | NotGiven = NOT_GIVEN, + skip_response: bool | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> TraceCreateResponse: + """ + Request Trace + + Args: + account_identifier: Identifier + + method: HTTP Method of tracing request + + url: URL to which perform tracing request + + context: Additional request parameters + + cookies: Cookies added to tracing request + + headers: Headers added to tracing request + + protocol: HTTP Protocol of tracing request + + skip_response: Skip sending the request to the Origin server after all rules evaluation + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not account_identifier: + raise ValueError(f"Expected a non-empty value for `account_identifier` but received {account_identifier!r}") + return await self._post( + f"/accounts/{account_identifier}/request-tracer/trace", + body=await async_maybe_transform( + { + "method": method, + "url": url, + "body": body, + "context": context, + "cookies": cookies, + "headers": headers, + "protocol": protocol, + "skip_response": skip_response, + }, + trace_create_params.TraceCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper._unwrapper, + ), + cast_to=cast(Type[TraceCreateResponse], ResultWrapper[TraceCreateResponse]), + ) + + +class TracesWithRawResponse: + def __init__(self, traces: Traces) -> None: + self._traces = traces + + self.create = to_raw_response_wrapper( + traces.create, + ) + + +class AsyncTracesWithRawResponse: + def __init__(self, traces: AsyncTraces) -> None: + self._traces = traces + + self.create = async_to_raw_response_wrapper( + traces.create, + ) + + +class TracesWithStreamingResponse: + def __init__(self, traces: Traces) -> None: + self._traces = traces + + self.create = to_streamed_response_wrapper( + traces.create, + ) + + +class AsyncTracesWithStreamingResponse: + def __init__(self, traces: AsyncTraces) -> None: + self._traces = traces + + self.create = async_to_streamed_response_wrapper( + traces.create, + ) diff --git a/src/cloudflare/types/request_tracers/__init__.py b/src/cloudflare/types/request_tracers/__init__.py index f8ee8b14b1c9..40a594702593 100644 --- a/src/cloudflare/types/request_tracers/__init__.py +++ b/src/cloudflare/types/request_tracers/__init__.py @@ -1,3 +1,8 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations + +from .trace import Trace as Trace +from .trace_item import TraceItem as TraceItem +from .trace_create_params import TraceCreateParams as TraceCreateParams +from .trace_create_response import TraceCreateResponse as TraceCreateResponse diff --git a/src/cloudflare/types/request_tracers/trace.py b/src/cloudflare/types/request_tracers/trace.py new file mode 100644 index 000000000000..4687762c7f89 --- /dev/null +++ b/src/cloudflare/types/request_tracers/trace.py @@ -0,0 +1,11 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import List + +__all__ = ["Trace"] + +Trace = List["TraceItem"] + +from .trace_item import TraceItem diff --git a/src/cloudflare/types/request_tracers/trace_create_params.py b/src/cloudflare/types/request_tracers/trace_create_params.py new file mode 100644 index 000000000000..d817af499b35 --- /dev/null +++ b/src/cloudflare/types/request_tracers/trace_create_params.py @@ -0,0 +1,80 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict +from typing_extensions import Required, TypedDict + +__all__ = ["TraceCreateParams", "Body", "Context", "ContextGeoloc"] + + +class TraceCreateParams(TypedDict, total=False): + method: Required[str] + """HTTP Method of tracing request""" + + url: Required[str] + """URL to which perform tracing request""" + + body: Body + + context: Context + """Additional request parameters""" + + cookies: Dict[str, str] + """Cookies added to tracing request""" + + headers: Dict[str, str] + """Headers added to tracing request""" + + protocol: str + """HTTP Protocol of tracing request""" + + skip_response: bool + """Skip sending the request to the Origin server after all rules evaluation""" + + +class Body(TypedDict, total=False): + base64: str + """Base64 encoded request body""" + + json: object + """Arbitrary json as request body""" + + plain_text: str + """Request body as plain text""" + + +class ContextGeoloc(TypedDict, total=False): + city: str + + continent: str + + is_eu_country: bool + + iso_code: str + + latitude: float + + longitude: float + + postal_code: str + + region_code: str + + subdivision_2_iso_code: str + + timezone: str + + +class Context(TypedDict, total=False): + bot_score: int + """Bot score used for evaluating tracing request processing""" + + geoloc: ContextGeoloc + """Geodata for tracing request""" + + skip_challenge: bool + """Whether to skip any challenges for tracing request (e.g.: captcha)""" + + threat_score: int + """Threat score used for evaluating tracing request processing""" diff --git a/src/cloudflare/types/request_tracers/trace_create_response.py b/src/cloudflare/types/request_tracers/trace_create_response.py new file mode 100644 index 000000000000..3e72c080e9a8 --- /dev/null +++ b/src/cloudflare/types/request_tracers/trace_create_response.py @@ -0,0 +1,25 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional + +from ..._compat import PYDANTIC_V2 +from ..._models import BaseModel + +__all__ = ["TraceCreateResponse"] + + +class TraceCreateResponse(BaseModel): + status_code: Optional[int] = None + """HTTP Status code of zone response""" + + trace: Optional["Trace"] = None + + +from .trace import Trace + +if PYDANTIC_V2: + TraceCreateResponse.model_rebuild() +else: + TraceCreateResponse.update_forward_refs() # type: ignore diff --git a/src/cloudflare/types/request_tracers/trace_item.py b/src/cloudflare/types/request_tracers/trace_item.py new file mode 100644 index 000000000000..2830764115ef --- /dev/null +++ b/src/cloudflare/types/request_tracers/trace_item.py @@ -0,0 +1,49 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional + +from ..._compat import PYDANTIC_V2 +from ..._models import BaseModel + +__all__ = ["TraceItem"] + + +class TraceItem(BaseModel): + action: Optional[str] = None + """If step type is rule, then action performed by this rule""" + + action_parameters: Optional[object] = None + """If step type is rule, then action parameters of this rule as JSON""" + + description: Optional[str] = None + """If step type is rule or ruleset, the description of this entity""" + + expression: Optional[str] = None + """If step type is rule, then expression used to match for this rule""" + + kind: Optional[str] = None + """If step type is ruleset, then kind of this ruleset""" + + matched: Optional[bool] = None + """Whether tracing step affected tracing request/response""" + + name: Optional[str] = None + """If step type is ruleset, then name of this ruleset""" + + step_name: Optional[str] = None + """Tracing step identifying name""" + + trace: Optional["Trace"] = None + + type: Optional[str] = None + """Tracing step type""" + + +from .trace import Trace + +if PYDANTIC_V2: + TraceItem.model_rebuild() +else: + TraceItem.update_forward_refs() # type: ignore diff --git a/tests/api_resources/request_tracers/test_traces.py b/tests/api_resources/request_tracers/test_traces.py new file mode 100644 index 000000000000..a8deb3bbce2c --- /dev/null +++ b/tests/api_resources/request_tracers/test_traces.py @@ -0,0 +1,206 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from cloudflare import Cloudflare, AsyncCloudflare +from tests.utils import assert_matches_type +from cloudflare.types.request_tracers import TraceCreateResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestTraces: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + def test_method_create(self, client: Cloudflare) -> None: + trace = client.request_tracers.traces.create( + "023e105f4ecef8ad9ca31a8372d0c353", + method="PUT", + url="https://some.zone/some_path", + ) + assert_matches_type(TraceCreateResponse, trace, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_method_create_with_all_params(self, client: Cloudflare) -> None: + trace = client.request_tracers.traces.create( + "023e105f4ecef8ad9ca31a8372d0c353", + method="PUT", + url="https://some.zone/some_path", + body={ + "base64": "c29tZV9yZXF1ZXN0X2JvZHk=", + "json": {}, + "plain_text": "string", + }, + context={ + "bot_score": 0, + "geoloc": { + "city": "London", + "continent": "string", + "is_eu_country": True, + "iso_code": "string", + "latitude": 0, + "longitude": 0, + "postal_code": "string", + "region_code": "string", + "subdivision_2_iso_code": "string", + "timezone": "string", + }, + "skip_challenge": True, + "threat_score": 0, + }, + cookies={ + "cookie_name_1": "cookie_value_1", + "cookie_name_2": "cookie_value_2", + }, + headers={ + "header_name_1": "header_value_1", + "header_name_2": "header_value_2", + }, + protocol="HTTP/1.1", + skip_response=True, + ) + assert_matches_type(TraceCreateResponse, trace, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_create(self, client: Cloudflare) -> None: + response = client.request_tracers.traces.with_raw_response.create( + "023e105f4ecef8ad9ca31a8372d0c353", + method="PUT", + url="https://some.zone/some_path", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + trace = response.parse() + assert_matches_type(TraceCreateResponse, trace, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_create(self, client: Cloudflare) -> None: + with client.request_tracers.traces.with_streaming_response.create( + "023e105f4ecef8ad9ca31a8372d0c353", + method="PUT", + url="https://some.zone/some_path", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + trace = response.parse() + assert_matches_type(TraceCreateResponse, trace, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_create(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_identifier` but received ''"): + client.request_tracers.traces.with_raw_response.create( + "", + method="PUT", + url="https://some.zone/some_path", + ) + + +class TestAsyncTraces: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + async def test_method_create(self, async_client: AsyncCloudflare) -> None: + trace = await async_client.request_tracers.traces.create( + "023e105f4ecef8ad9ca31a8372d0c353", + method="PUT", + url="https://some.zone/some_path", + ) + assert_matches_type(TraceCreateResponse, trace, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncCloudflare) -> None: + trace = await async_client.request_tracers.traces.create( + "023e105f4ecef8ad9ca31a8372d0c353", + method="PUT", + url="https://some.zone/some_path", + body={ + "base64": "c29tZV9yZXF1ZXN0X2JvZHk=", + "json": {}, + "plain_text": "string", + }, + context={ + "bot_score": 0, + "geoloc": { + "city": "London", + "continent": "string", + "is_eu_country": True, + "iso_code": "string", + "latitude": 0, + "longitude": 0, + "postal_code": "string", + "region_code": "string", + "subdivision_2_iso_code": "string", + "timezone": "string", + }, + "skip_challenge": True, + "threat_score": 0, + }, + cookies={ + "cookie_name_1": "cookie_value_1", + "cookie_name_2": "cookie_value_2", + }, + headers={ + "header_name_1": "header_value_1", + "header_name_2": "header_value_2", + }, + protocol="HTTP/1.1", + skip_response=True, + ) + assert_matches_type(TraceCreateResponse, trace, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None: + response = await async_client.request_tracers.traces.with_raw_response.create( + "023e105f4ecef8ad9ca31a8372d0c353", + method="PUT", + url="https://some.zone/some_path", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + trace = await response.parse() + assert_matches_type(TraceCreateResponse, trace, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_create(self, async_client: AsyncCloudflare) -> None: + async with async_client.request_tracers.traces.with_streaming_response.create( + "023e105f4ecef8ad9ca31a8372d0c353", + method="PUT", + url="https://some.zone/some_path", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + trace = await response.parse() + assert_matches_type(TraceCreateResponse, trace, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_create(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_identifier` but received ''"): + await async_client.request_tracers.traces.with_raw_response.create( + "", + method="PUT", + url="https://some.zone/some_path", + )