From 58d639bcbac0e700ef2f15deb5415c14064073be Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Thu, 14 Nov 2024 03:13:03 +0000 Subject: [PATCH] feat(api): api update --- .stats.yml | 4 +- api.md | 14 ++ .../resources/workers/scripts/__init__.py | 14 ++ .../workers/scripts/assets/__init__.py | 33 +++ .../workers/scripts/assets/assets.py | 102 +++++++++ .../workers/scripts/assets/upload.py | 203 ++++++++++++++++++ .../resources/workers/scripts/scripts.py | 33 +++ .../types/workers/scripts/assets/__init__.py | 3 + .../scripts/assets/upload_create_params.py | 27 +++ .../scripts/assets/upload_create_response.py | 15 ++ .../workers/scripts/assets/__init__.py | 1 + .../workers/scripts/assets/test_upload.py | 146 +++++++++++++ 12 files changed, 593 insertions(+), 2 deletions(-) create mode 100644 src/cloudflare/resources/workers/scripts/assets/__init__.py create mode 100644 src/cloudflare/resources/workers/scripts/assets/assets.py create mode 100644 src/cloudflare/resources/workers/scripts/assets/upload.py create mode 100644 src/cloudflare/types/workers/scripts/assets/upload_create_params.py create mode 100644 src/cloudflare/types/workers/scripts/assets/upload_create_response.py create mode 100644 tests/api_resources/workers/scripts/assets/__init__.py create mode 100644 tests/api_resources/workers/scripts/assets/test_upload.py diff --git a/.stats.yml b/.stats.yml index 113bc58883c..75b15667679 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 1416 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-3f87896b62cce36e33c03f416ad98add2717ccd78f1743925c160a6c6a67ff15.yml +configured_endpoints: 1417 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-4396f2b615f2349cc28c23e9df6cf66c1c0fd8257d18df0ce54d7e74c839bf9f.yml diff --git a/api.md b/api.md index 3230d4d8cbc..63e615121f9 100644 --- a/api.md +++ b/api.md @@ -2298,6 +2298,20 @@ Methods: - client.workers.scripts.delete(script_name, \*, account_id, \*\*params) -> None - client.workers.scripts.get(script_name, \*, account_id) -> BinaryAPIResponse +### Assets + +#### Upload + +Types: + +```python +from cloudflare.types.workers.scripts.assets import UploadCreateResponse +``` + +Methods: + +- client.workers.scripts.assets.upload.create(script_name, \*, account_id, \*\*params) -> Optional + ### Subdomain Types: diff --git a/src/cloudflare/resources/workers/scripts/__init__.py b/src/cloudflare/resources/workers/scripts/__init__.py index 2e7a6bf46d5..8923954063a 100644 --- a/src/cloudflare/resources/workers/scripts/__init__.py +++ b/src/cloudflare/resources/workers/scripts/__init__.py @@ -8,6 +8,14 @@ TailResourceWithStreamingResponse, AsyncTailResourceWithStreamingResponse, ) +from .assets import ( + AssetsResource, + AsyncAssetsResource, + AssetsResourceWithRawResponse, + AsyncAssetsResourceWithRawResponse, + AssetsResourceWithStreamingResponse, + AsyncAssetsResourceWithStreamingResponse, +) from .content import ( ContentResource, AsyncContentResource, @@ -66,6 +74,12 @@ ) __all__ = [ + "AssetsResource", + "AsyncAssetsResource", + "AssetsResourceWithRawResponse", + "AsyncAssetsResourceWithRawResponse", + "AssetsResourceWithStreamingResponse", + "AsyncAssetsResourceWithStreamingResponse", "SubdomainResource", "AsyncSubdomainResource", "SubdomainResourceWithRawResponse", diff --git a/src/cloudflare/resources/workers/scripts/assets/__init__.py b/src/cloudflare/resources/workers/scripts/assets/__init__.py new file mode 100644 index 00000000000..3769f94bf1e --- /dev/null +++ b/src/cloudflare/resources/workers/scripts/assets/__init__.py @@ -0,0 +1,33 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .assets import ( + AssetsResource, + AsyncAssetsResource, + AssetsResourceWithRawResponse, + AsyncAssetsResourceWithRawResponse, + AssetsResourceWithStreamingResponse, + AsyncAssetsResourceWithStreamingResponse, +) +from .upload import ( + UploadResource, + AsyncUploadResource, + UploadResourceWithRawResponse, + AsyncUploadResourceWithRawResponse, + UploadResourceWithStreamingResponse, + AsyncUploadResourceWithStreamingResponse, +) + +__all__ = [ + "UploadResource", + "AsyncUploadResource", + "UploadResourceWithRawResponse", + "AsyncUploadResourceWithRawResponse", + "UploadResourceWithStreamingResponse", + "AsyncUploadResourceWithStreamingResponse", + "AssetsResource", + "AsyncAssetsResource", + "AssetsResourceWithRawResponse", + "AsyncAssetsResourceWithRawResponse", + "AssetsResourceWithStreamingResponse", + "AsyncAssetsResourceWithStreamingResponse", +] diff --git a/src/cloudflare/resources/workers/scripts/assets/assets.py b/src/cloudflare/resources/workers/scripts/assets/assets.py new file mode 100644 index 00000000000..f5a2e1f5f08 --- /dev/null +++ b/src/cloudflare/resources/workers/scripts/assets/assets.py @@ -0,0 +1,102 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from .upload import ( + UploadResource, + AsyncUploadResource, + UploadResourceWithRawResponse, + AsyncUploadResourceWithRawResponse, + UploadResourceWithStreamingResponse, + AsyncUploadResourceWithStreamingResponse, +) +from ....._compat import cached_property +from ....._resource import SyncAPIResource, AsyncAPIResource + +__all__ = ["AssetsResource", "AsyncAssetsResource"] + + +class AssetsResource(SyncAPIResource): + @cached_property + def upload(self) -> UploadResource: + return UploadResource(self._client) + + @cached_property + def with_raw_response(self) -> AssetsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers + """ + return AssetsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AssetsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response + """ + return AssetsResourceWithStreamingResponse(self) + + +class AsyncAssetsResource(AsyncAPIResource): + @cached_property + def upload(self) -> AsyncUploadResource: + return AsyncUploadResource(self._client) + + @cached_property + def with_raw_response(self) -> AsyncAssetsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers + """ + return AsyncAssetsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncAssetsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response + """ + return AsyncAssetsResourceWithStreamingResponse(self) + + +class AssetsResourceWithRawResponse: + def __init__(self, assets: AssetsResource) -> None: + self._assets = assets + + @cached_property + def upload(self) -> UploadResourceWithRawResponse: + return UploadResourceWithRawResponse(self._assets.upload) + + +class AsyncAssetsResourceWithRawResponse: + def __init__(self, assets: AsyncAssetsResource) -> None: + self._assets = assets + + @cached_property + def upload(self) -> AsyncUploadResourceWithRawResponse: + return AsyncUploadResourceWithRawResponse(self._assets.upload) + + +class AssetsResourceWithStreamingResponse: + def __init__(self, assets: AssetsResource) -> None: + self._assets = assets + + @cached_property + def upload(self) -> UploadResourceWithStreamingResponse: + return UploadResourceWithStreamingResponse(self._assets.upload) + + +class AsyncAssetsResourceWithStreamingResponse: + def __init__(self, assets: AsyncAssetsResource) -> None: + self._assets = assets + + @cached_property + def upload(self) -> AsyncUploadResourceWithStreamingResponse: + return AsyncUploadResourceWithStreamingResponse(self._assets.upload) diff --git a/src/cloudflare/resources/workers/scripts/assets/upload.py b/src/cloudflare/resources/workers/scripts/assets/upload.py new file mode 100644 index 00000000000..711cf2035d4 --- /dev/null +++ b/src/cloudflare/resources/workers/scripts/assets/upload.py @@ -0,0 +1,203 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict, Type, Optional, 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.workers.scripts.assets import upload_create_params +from .....types.workers.scripts.assets.upload_create_response import UploadCreateResponse + +__all__ = ["UploadResource", "AsyncUploadResource"] + + +class UploadResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> UploadResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers + """ + return UploadResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> UploadResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response + """ + return UploadResourceWithStreamingResponse(self) + + def create( + self, + script_name: str, + *, + account_id: str, + manifest: Dict[str, upload_create_params.Manifest] | 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, + ) -> Optional[UploadCreateResponse]: + """ + Start uploading a collection of assets for use in a Worker version. + + Args: + account_id: Identifier + + script_name: Name of the script, used in URLs and route configuration. + + manifest: A manifest ([path]: {hash, size}) map of files to upload. As an example, + `/blog/hello-world.html` would be a valid path key. + + 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_id: + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") + if not script_name: + raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}") + return self._post( + f"/accounts/{account_id}/workers/scripts/{script_name}/assets-upload-session", + body=maybe_transform({"manifest": manifest}, upload_create_params.UploadCreateParams), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[UploadCreateResponse]]._unwrapper, + ), + cast_to=cast(Type[Optional[UploadCreateResponse]], ResultWrapper[UploadCreateResponse]), + ) + + +class AsyncUploadResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncUploadResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers + """ + return AsyncUploadResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncUploadResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response + """ + return AsyncUploadResourceWithStreamingResponse(self) + + async def create( + self, + script_name: str, + *, + account_id: str, + manifest: Dict[str, upload_create_params.Manifest] | 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, + ) -> Optional[UploadCreateResponse]: + """ + Start uploading a collection of assets for use in a Worker version. + + Args: + account_id: Identifier + + script_name: Name of the script, used in URLs and route configuration. + + manifest: A manifest ([path]: {hash, size}) map of files to upload. As an example, + `/blog/hello-world.html` would be a valid path key. + + 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_id: + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") + if not script_name: + raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}") + return await self._post( + f"/accounts/{account_id}/workers/scripts/{script_name}/assets-upload-session", + body=await async_maybe_transform({"manifest": manifest}, upload_create_params.UploadCreateParams), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[UploadCreateResponse]]._unwrapper, + ), + cast_to=cast(Type[Optional[UploadCreateResponse]], ResultWrapper[UploadCreateResponse]), + ) + + +class UploadResourceWithRawResponse: + def __init__(self, upload: UploadResource) -> None: + self._upload = upload + + self.create = to_raw_response_wrapper( + upload.create, + ) + + +class AsyncUploadResourceWithRawResponse: + def __init__(self, upload: AsyncUploadResource) -> None: + self._upload = upload + + self.create = async_to_raw_response_wrapper( + upload.create, + ) + + +class UploadResourceWithStreamingResponse: + def __init__(self, upload: UploadResource) -> None: + self._upload = upload + + self.create = to_streamed_response_wrapper( + upload.create, + ) + + +class AsyncUploadResourceWithStreamingResponse: + def __init__(self, upload: AsyncUploadResource) -> None: + self._upload = upload + + self.create = async_to_streamed_response_wrapper( + upload.create, + ) diff --git a/src/cloudflare/resources/workers/scripts/scripts.py b/src/cloudflare/resources/workers/scripts/scripts.py index e12157f74b6..cc26533caa0 100644 --- a/src/cloudflare/resources/workers/scripts/scripts.py +++ b/src/cloudflare/resources/workers/scripts/scripts.py @@ -15,6 +15,14 @@ TailResourceWithStreamingResponse, AsyncTailResourceWithStreamingResponse, ) +from .assets import ( + AssetsResource, + AsyncAssetsResource, + AssetsResourceWithRawResponse, + AsyncAssetsResourceWithRawResponse, + AssetsResourceWithStreamingResponse, + AsyncAssetsResourceWithStreamingResponse, +) from .content import ( ContentResource, AsyncContentResource, @@ -87,6 +95,7 @@ ) from ...._wrappers import ResultWrapper from ....pagination import SyncSinglePage, AsyncSinglePage +from .assets.assets import AssetsResource, AsyncAssetsResource from ...._base_client import AsyncPaginator, make_request_options from ....types.workers import script_delete_params, script_update_params from ....types.workers.script import Script @@ -96,6 +105,10 @@ class ScriptsResource(SyncAPIResource): + @cached_property + def assets(self) -> AssetsResource: + return AssetsResource(self._client) + @cached_property def subdomain(self) -> SubdomainResource: return SubdomainResource(self._client) @@ -409,6 +422,10 @@ def get( class AsyncScriptsResource(AsyncAPIResource): + @cached_property + def assets(self) -> AsyncAssetsResource: + return AsyncAssetsResource(self._client) + @cached_property def subdomain(self) -> AsyncSubdomainResource: return AsyncSubdomainResource(self._client) @@ -741,6 +758,10 @@ def __init__(self, scripts: ScriptsResource) -> None: BinaryAPIResponse, ) + @cached_property + def assets(self) -> AssetsResourceWithRawResponse: + return AssetsResourceWithRawResponse(self._scripts.assets) + @cached_property def subdomain(self) -> SubdomainResourceWithRawResponse: return SubdomainResourceWithRawResponse(self._scripts.subdomain) @@ -788,6 +809,10 @@ def __init__(self, scripts: AsyncScriptsResource) -> None: AsyncBinaryAPIResponse, ) + @cached_property + def assets(self) -> AsyncAssetsResourceWithRawResponse: + return AsyncAssetsResourceWithRawResponse(self._scripts.assets) + @cached_property def subdomain(self) -> AsyncSubdomainResourceWithRawResponse: return AsyncSubdomainResourceWithRawResponse(self._scripts.subdomain) @@ -835,6 +860,10 @@ def __init__(self, scripts: ScriptsResource) -> None: StreamedBinaryAPIResponse, ) + @cached_property + def assets(self) -> AssetsResourceWithStreamingResponse: + return AssetsResourceWithStreamingResponse(self._scripts.assets) + @cached_property def subdomain(self) -> SubdomainResourceWithStreamingResponse: return SubdomainResourceWithStreamingResponse(self._scripts.subdomain) @@ -882,6 +911,10 @@ def __init__(self, scripts: AsyncScriptsResource) -> None: AsyncStreamedBinaryAPIResponse, ) + @cached_property + def assets(self) -> AsyncAssetsResourceWithStreamingResponse: + return AsyncAssetsResourceWithStreamingResponse(self._scripts.assets) + @cached_property def subdomain(self) -> AsyncSubdomainResourceWithStreamingResponse: return AsyncSubdomainResourceWithStreamingResponse(self._scripts.subdomain) diff --git a/src/cloudflare/types/workers/scripts/assets/__init__.py b/src/cloudflare/types/workers/scripts/assets/__init__.py index f8ee8b14b1c..3ec0c84c4dd 100644 --- a/src/cloudflare/types/workers/scripts/assets/__init__.py +++ b/src/cloudflare/types/workers/scripts/assets/__init__.py @@ -1,3 +1,6 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations + +from .upload_create_params import UploadCreateParams as UploadCreateParams +from .upload_create_response import UploadCreateResponse as UploadCreateResponse diff --git a/src/cloudflare/types/workers/scripts/assets/upload_create_params.py b/src/cloudflare/types/workers/scripts/assets/upload_create_params.py new file mode 100644 index 00000000000..dad448958b8 --- /dev/null +++ b/src/cloudflare/types/workers/scripts/assets/upload_create_params.py @@ -0,0 +1,27 @@ +# 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__ = ["UploadCreateParams", "Manifest"] + + +class UploadCreateParams(TypedDict, total=False): + account_id: Required[str] + """Identifier""" + + manifest: Dict[str, Manifest] + """A manifest ([path]: {hash, size}) map of files to upload. + + As an example, `/blog/hello-world.html` would be a valid path key. + """ + + +class Manifest(TypedDict, total=False): + hash: str + """The hash of the file.""" + + size: int + """The size of the file in bytes.""" diff --git a/src/cloudflare/types/workers/scripts/assets/upload_create_response.py b/src/cloudflare/types/workers/scripts/assets/upload_create_response.py new file mode 100644 index 00000000000..1f4e57e5ad5 --- /dev/null +++ b/src/cloudflare/types/workers/scripts/assets/upload_create_response.py @@ -0,0 +1,15 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List, Optional + +from ....._models import BaseModel + +__all__ = ["UploadCreateResponse"] + + +class UploadCreateResponse(BaseModel): + buckets: Optional[List[List[str]]] = None + """The requests to make to upload assets.""" + + jwt: Optional[str] = None + """A JWT to use as authentication for uploading assets.""" diff --git a/tests/api_resources/workers/scripts/assets/__init__.py b/tests/api_resources/workers/scripts/assets/__init__.py new file mode 100644 index 00000000000..fd8019a9a1a --- /dev/null +++ b/tests/api_resources/workers/scripts/assets/__init__.py @@ -0,0 +1 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. diff --git a/tests/api_resources/workers/scripts/assets/test_upload.py b/tests/api_resources/workers/scripts/assets/test_upload.py new file mode 100644 index 00000000000..fb67d1d238e --- /dev/null +++ b/tests/api_resources/workers/scripts/assets/test_upload.py @@ -0,0 +1,146 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, Optional, cast + +import pytest + +from cloudflare import Cloudflare, AsyncCloudflare +from tests.utils import assert_matches_type +from cloudflare.types.workers.scripts.assets import UploadCreateResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestUpload: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_create(self, client: Cloudflare) -> None: + upload = client.workers.scripts.assets.upload.create( + script_name="this-is_my_script-01", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(Optional[UploadCreateResponse], upload, path=["response"]) + + @parametrize + def test_method_create_with_all_params(self, client: Cloudflare) -> None: + upload = client.workers.scripts.assets.upload.create( + script_name="this-is_my_script-01", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + manifest={ + "foo": { + "hash": "hash", + "size": 0, + } + }, + ) + assert_matches_type(Optional[UploadCreateResponse], upload, path=["response"]) + + @parametrize + def test_raw_response_create(self, client: Cloudflare) -> None: + response = client.workers.scripts.assets.upload.with_raw_response.create( + script_name="this-is_my_script-01", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + upload = response.parse() + assert_matches_type(Optional[UploadCreateResponse], upload, path=["response"]) + + @parametrize + def test_streaming_response_create(self, client: Cloudflare) -> None: + with client.workers.scripts.assets.upload.with_streaming_response.create( + script_name="this-is_my_script-01", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + upload = response.parse() + assert_matches_type(Optional[UploadCreateResponse], upload, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_create(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_id` but received ''"): + client.workers.scripts.assets.upload.with_raw_response.create( + script_name="this-is_my_script-01", + account_id="", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `script_name` but received ''"): + client.workers.scripts.assets.upload.with_raw_response.create( + script_name="", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + +class TestAsyncUpload: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_create(self, async_client: AsyncCloudflare) -> None: + upload = await async_client.workers.scripts.assets.upload.create( + script_name="this-is_my_script-01", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(Optional[UploadCreateResponse], upload, path=["response"]) + + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncCloudflare) -> None: + upload = await async_client.workers.scripts.assets.upload.create( + script_name="this-is_my_script-01", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + manifest={ + "foo": { + "hash": "hash", + "size": 0, + } + }, + ) + assert_matches_type(Optional[UploadCreateResponse], upload, path=["response"]) + + @parametrize + async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None: + response = await async_client.workers.scripts.assets.upload.with_raw_response.create( + script_name="this-is_my_script-01", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + upload = await response.parse() + assert_matches_type(Optional[UploadCreateResponse], upload, path=["response"]) + + @parametrize + async def test_streaming_response_create(self, async_client: AsyncCloudflare) -> None: + async with async_client.workers.scripts.assets.upload.with_streaming_response.create( + script_name="this-is_my_script-01", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + upload = await response.parse() + assert_matches_type(Optional[UploadCreateResponse], upload, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @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_id` but received ''"): + await async_client.workers.scripts.assets.upload.with_raw_response.create( + script_name="this-is_my_script-01", + account_id="", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `script_name` but received ''"): + await async_client.workers.scripts.assets.upload.with_raw_response.create( + script_name="", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + )