From 122598e5cc16f201ffe816b749344fb8100b1ea4 Mon Sep 17 00:00:00 2001 From: Chris Thorwarth Date: Wed, 19 Nov 2025 12:07:18 -0500 Subject: [PATCH 1/2] wip: script upload tests --- .../workers/test_script_upload.py | 595 ++++++++++++++++++ 1 file changed, 595 insertions(+) create mode 100644 tests/api_resources/workers/test_script_upload.py diff --git a/tests/api_resources/workers/test_script_upload.py b/tests/api_resources/workers/test_script_upload.py new file mode 100644 index 00000000000..3c611c3fc2b --- /dev/null +++ b/tests/api_resources/workers/test_script_upload.py @@ -0,0 +1,595 @@ +from __future__ import annotations + +import os +from typing import Any, cast + +import httpx +import pytest +from respx import MockRouter + +from cloudflare import Cloudflare, AsyncCloudflare, BadRequestError +from tests.utils import assert_matches_type +from cloudflare.types.workers import ScriptUpdateResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestScriptUpload: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + def test_basic_script_upload(self, client: Cloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/my-hello-world-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "my-hello-world-script", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response(env.MESSAGE, { status: 200 }); + } + }; + """ + + script = client.workers.scripts.update( + "my-hello-world-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "my-hello-world-script.mjs", + "bindings": [ + { + "type": "plain_text", + "name": "MESSAGE", + "text": "Hello World!", + } + ], + }, + files={ + "my-hello-world-script.mjs": ( + "my-hello-world-script.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + def test_script_upload_with_multiple_files(self, client: Cloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/multi-file-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "multi-file-script", "startup_time_ms": 100}})) + + main_script = """ + import { helper } from './helper.js'; + export default { + async fetch(request, env, ctx) { + return new Response(helper(), { status: 200 }); + } + }; + """ + + helper_script = """ + export function helper() { + return 'Hello from helper!'; + } + """ + + script = client.workers.scripts.update( + "multi-file-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "index.mjs", + }, + files={ + "index.mjs": ( + "index.mjs", + bytes(main_script, "utf-8"), + "application/javascript+module", + ), + "helper.js": ( + "helper.js", + bytes(helper_script, "utf-8"), + "application/javascript+module", + ), + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + def test_script_upload_with_bindings(self, client: Cloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/script-with-bindings" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "script-with-bindings", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + const value = await env.MY_KV.get('key'); + return new Response(value || env.MESSAGE, { status: 200 }); + } + }; + """ + + script = client.workers.scripts.update( + "script-with-bindings", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + "bindings": [ + { + "type": "plain_text", + "name": "MESSAGE", + "text": "Default message", + }, + { + "type": "kv_namespace", + "name": "MY_KV", + "namespace_id": "abc123", + }, + ], + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + def test_script_upload_with_compatibility_flags(self, client: Cloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/nodejs-compat-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "nodejs-compat-script", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response('Node.js compatibility enabled', { status: 200 }); + } + }; + """ + + script = client.workers.scripts.update( + "nodejs-compat-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + "compatibility_date": "2024-01-01", + "compatibility_flags": ["nodejs_compat"], + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + def test_script_upload_with_source_map(self, client: Cloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/script-with-sourcemap" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "script-with-sourcemap", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response('Hello', { status: 200 }); + } + }; + """ + + source_map = '{"version":3,"sources":["worker.js"],"names":[],"mappings":"AAAA"}' + + script = client.workers.scripts.update( + "script-with-sourcemap", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ), + "worker.mjs.map": ( + "worker.mjs.map", + bytes(source_map, "utf-8"), + "application/source-map", + ), + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + def test_script_upload_raw_response(self, client: Cloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/test-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "test-script", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response('Hello', { status: 200 }); + } + }; + """ + + response = client.workers.scripts.with_raw_response.update( + "test-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + script = response.parse() + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + def test_script_upload_streaming_response(self, client: Cloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/test-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "test-script", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response('Hello', { status: 200 }); + } + }; + """ + + with client.workers.scripts.with_streaming_response.update( + "test-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + script = response.parse() + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_script_upload_missing_account_id(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_id` but received ''"): + client.workers.scripts.with_raw_response.update( + "test-script", + account_id="", + metadata={}, + ) + + @parametrize + def test_script_upload_missing_script_name(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `script_name` but received ''"): + client.workers.scripts.with_raw_response.update( + "", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={}, + ) + + +class TestAsyncScriptUpload: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + async def test_basic_script_upload(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/my-hello-world-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "my-hello-world-script", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response(env.MESSAGE, { status: 200 }); + } + }; + """ + + script = await async_client.workers.scripts.update( + "my-hello-world-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "my-hello-world-script.mjs", + "bindings": [ + { + "type": "plain_text", + "name": "MESSAGE", + "text": "Hello World!", + } + ], + }, + files={ + "my-hello-world-script.mjs": ( + "my-hello-world-script.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + async def test_script_upload_with_multiple_files(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/multi-file-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "multi-file-script", "startup_time_ms": 100}})) + + main_script = """ + import { helper } from './helper.js'; + export default { + async fetch(request, env, ctx) { + return new Response(helper(), { status: 200 }); + } + }; + """ + + helper_script = """ + export function helper() { + return 'Hello from helper!'; + } + """ + + script = await async_client.workers.scripts.update( + "multi-file-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "index.mjs", + }, + files={ + "index.mjs": ( + "index.mjs", + bytes(main_script, "utf-8"), + "application/javascript+module", + ), + "helper.js": ( + "helper.js", + bytes(helper_script, "utf-8"), + "application/javascript+module", + ), + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + async def test_script_upload_with_bindings(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/script-with-bindings" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "script-with-bindings", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + const value = await env.MY_KV.get('key'); + return new Response(value || env.MESSAGE, { status: 200 }); + } + }; + """ + + script = await async_client.workers.scripts.update( + "script-with-bindings", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + "bindings": [ + { + "type": "plain_text", + "name": "MESSAGE", + "text": "Default message", + }, + { + "type": "kv_namespace", + "name": "MY_KV", + "namespace_id": "abc123", + }, + ], + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + async def test_script_upload_with_compatibility_flags(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/nodejs-compat-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "nodejs-compat-script", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response('Node.js compatibility enabled', { status: 200 }); + } + }; + """ + + script = await async_client.workers.scripts.update( + "nodejs-compat-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + "compatibility_date": "2024-01-01", + "compatibility_flags": ["nodejs_compat"], + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + async def test_script_upload_with_source_map(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/script-with-sourcemap" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "script-with-sourcemap", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response('Hello', { status: 200 }); + } + }; + """ + + source_map = '{"version":3,"sources":["worker.js"],"names":[],"mappings":"AAAA"}' + + script = await async_client.workers.scripts.update( + "script-with-sourcemap", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ), + "worker.mjs.map": ( + "worker.mjs.map", + bytes(source_map, "utf-8"), + "application/source-map", + ), + }, + ) + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + async def test_script_upload_raw_response(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/test-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "test-script", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response('Hello', { status: 200 }); + } + }; + """ + + response = await async_client.workers.scripts.with_raw_response.update( + "test-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + script = await response.parse() + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + @parametrize + @pytest.mark.respx(base_url=base_url) + async def test_script_upload_streaming_response(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: + respx_mock.put( + "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/test-script" + ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "test-script", "startup_time_ms": 100}})) + + script_content = """ + export default { + async fetch(request, env, ctx) { + return new Response('Hello', { status: 200 }); + } + }; + """ + + async with async_client.workers.scripts.with_streaming_response.update( + "test-script", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={ + "main_module": "worker.mjs", + }, + files={ + "worker.mjs": ( + "worker.mjs", + bytes(script_content, "utf-8"), + "application/javascript+module", + ) + }, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + script = await response.parse() + assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_script_upload_missing_account_id(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.with_raw_response.update( + "test-script", + account_id="", + metadata={}, + ) + + @parametrize + async def test_script_upload_missing_script_name(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `script_name` but received ''"): + await async_client.workers.scripts.with_raw_response.update( + "", + account_id="023e105f4ecef8ad9ca31a8372d0c353", + metadata={}, + ) + From 12e25949a02e6e21565c1b31f83870cdadbeea43 Mon Sep 17 00:00:00 2001 From: Chris Thorwarth Date: Thu, 20 Nov 2025 12:57:51 -0500 Subject: [PATCH 2/2] removing mocks --- .../workers/test_script_upload.py | 116 +++++------------- 1 file changed, 29 insertions(+), 87 deletions(-) diff --git a/tests/api_resources/workers/test_script_upload.py b/tests/api_resources/workers/test_script_upload.py index 3c611c3fc2b..6c411570ee2 100644 --- a/tests/api_resources/workers/test_script_upload.py +++ b/tests/api_resources/workers/test_script_upload.py @@ -3,11 +3,9 @@ import os from typing import Any, cast -import httpx import pytest -from respx import MockRouter -from cloudflare import Cloudflare, AsyncCloudflare, BadRequestError +from cloudflare import Cloudflare, AsyncCloudflare from tests.utils import assert_matches_type from cloudflare.types.workers import ScriptUpdateResponse @@ -17,13 +15,9 @@ class TestScriptUpload: parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - def test_basic_script_upload(self, client: Cloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/my-hello-world-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "my-hello-world-script", "startup_time_ms": 100}})) - + def test_basic_script_upload(self, client: Cloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -55,13 +49,9 @@ def test_basic_script_upload(self, client: Cloudflare, respx_mock: MockRouter) - ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - def test_script_upload_with_multiple_files(self, client: Cloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/multi-file-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "multi-file-script", "startup_time_ms": 100}})) - + def test_script_upload_with_multiple_files(self, client: Cloudflare) -> None: main_script = """ import { helper } from './helper.js'; export default { @@ -98,13 +88,9 @@ def test_script_upload_with_multiple_files(self, client: Cloudflare, respx_mock: ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - def test_script_upload_with_bindings(self, client: Cloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/script-with-bindings" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "script-with-bindings", "startup_time_ms": 100}})) - + def test_script_upload_with_bindings(self, client: Cloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -142,13 +128,9 @@ def test_script_upload_with_bindings(self, client: Cloudflare, respx_mock: MockR ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - def test_script_upload_with_compatibility_flags(self, client: Cloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/nodejs-compat-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "nodejs-compat-script", "startup_time_ms": 100}})) - + def test_script_upload_with_compatibility_flags(self, client: Cloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -175,13 +157,9 @@ def test_script_upload_with_compatibility_flags(self, client: Cloudflare, respx_ ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - def test_script_upload_with_source_map(self, client: Cloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/script-with-sourcemap" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "script-with-sourcemap", "startup_time_ms": 100}})) - + def test_script_upload_with_source_map(self, client: Cloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -213,13 +191,9 @@ def test_script_upload_with_source_map(self, client: Cloudflare, respx_mock: Moc ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - def test_script_upload_raw_response(self, client: Cloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/test-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "test-script", "startup_time_ms": 100}})) - + def test_script_upload_raw_response(self, client: Cloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -248,13 +222,9 @@ def test_script_upload_raw_response(self, client: Cloudflare, respx_mock: MockRo script = response.parse() assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - def test_script_upload_streaming_response(self, client: Cloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/test-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "test-script", "startup_time_ms": 100}})) - + def test_script_upload_streaming_response(self, client: Cloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -307,13 +277,9 @@ def test_script_upload_missing_script_name(self, client: Cloudflare) -> None: class TestAsyncScriptUpload: parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - async def test_basic_script_upload(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/my-hello-world-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "my-hello-world-script", "startup_time_ms": 100}})) - + async def test_basic_script_upload(self, async_client: AsyncCloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -345,13 +311,9 @@ async def test_basic_script_upload(self, async_client: AsyncCloudflare, respx_mo ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - async def test_script_upload_with_multiple_files(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/multi-file-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "multi-file-script", "startup_time_ms": 100}})) - + async def test_script_upload_with_multiple_files(self, async_client: AsyncCloudflare) -> None: main_script = """ import { helper } from './helper.js'; export default { @@ -388,13 +350,9 @@ async def test_script_upload_with_multiple_files(self, async_client: AsyncCloudf ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - async def test_script_upload_with_bindings(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/script-with-bindings" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "script-with-bindings", "startup_time_ms": 100}})) - + async def test_script_upload_with_bindings(self, async_client: AsyncCloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -432,13 +390,9 @@ async def test_script_upload_with_bindings(self, async_client: AsyncCloudflare, ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - async def test_script_upload_with_compatibility_flags(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/nodejs-compat-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "nodejs-compat-script", "startup_time_ms": 100}})) - + async def test_script_upload_with_compatibility_flags(self, async_client: AsyncCloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -465,13 +419,9 @@ async def test_script_upload_with_compatibility_flags(self, async_client: AsyncC ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - async def test_script_upload_with_source_map(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/script-with-sourcemap" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "script-with-sourcemap", "startup_time_ms": 100}})) - + async def test_script_upload_with_source_map(self, async_client: AsyncCloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -503,13 +453,9 @@ async def test_script_upload_with_source_map(self, async_client: AsyncCloudflare ) assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - async def test_script_upload_raw_response(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/test-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "test-script", "startup_time_ms": 100}})) - + async def test_script_upload_raw_response(self, async_client: AsyncCloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) { @@ -538,13 +484,9 @@ async def test_script_upload_raw_response(self, async_client: AsyncCloudflare, r script = await response.parse() assert_matches_type(ScriptUpdateResponse, script, path=["response"]) + @pytest.mark.skip(reason="TODO: Prism multipart/form-data validation incompatible with SDK encoding") @parametrize - @pytest.mark.respx(base_url=base_url) - async def test_script_upload_streaming_response(self, async_client: AsyncCloudflare, respx_mock: MockRouter) -> None: - respx_mock.put( - "/accounts/023e105f4ecef8ad9ca31a8372d0c353/workers/scripts/test-script" - ).mock(return_value=httpx.Response(200, json={"success": True, "result": {"id": "test-script", "startup_time_ms": 100}})) - + async def test_script_upload_streaming_response(self, async_client: AsyncCloudflare) -> None: script_content = """ export default { async fetch(request, env, ctx) {