MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_sigv4_binary_file_upload

Function test_sigv4_binary_file_upload

tests/lib/test_aws.py:536–555  ·  view source on GitHub ↗
(sync: bool, respx_mock: MockRouter)

Source from the content-addressed store, hash-verified

534@pytest.mark.asyncio()
535@pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"])
536async def test_sigv4_binary_file_upload(sync: bool, respx_mock: MockRouter) -> None:
537 respx_mock.post(re.compile(r"https://aws-external-anthropic\.us-east-1\.api\.aws/.*")).mock(
538 return_value=httpx2.Response(200, json={"id": "file_123", "type": "file"})
539 )
540 png = b"\x89PNG\r\n\x1a\n\x00\xff\xfe"
541
542 if sync:
543 AnthropicAWS(
544 aws_access_key="AKID", aws_secret_key="secret", aws_region="us-east-1", workspace_id="ws-123"
545 ).files.upload(file=("x.png", png, "image/png"))
546 else:
547 await AsyncAnthropicAWS(
548 aws_access_key="AKID", aws_secret_key="secret", aws_region="us-east-1", workspace_id="ws-123"
549 ).files.upload(file=("x.png", png, "image/png"))
550
551 calls = cast("list[MockRequestCall]", respx_mock.calls)
552 assert len(calls) == 1
553 assert str(calls[0].request.url) == "https://aws-external-anthropic.us-east-1.api.aws/v1/files"
554 assert png in calls[0].request.content
555 assert calls[0].request.headers["Authorization"].startswith("AWS4-HMAC-SHA256 ")
556
557
558def respond_to_user_profiles(request: httpx2.Request) -> httpx2.Response:

Callers

nothing calls this directly

Calls 4

AnthropicAWSClass · 0.90
AsyncAnthropicAWSClass · 0.90
postMethod · 0.45
uploadMethod · 0.45

Tested by

no test coverage detected