@@ -364,6 +364,103 @@ def handler(request: httpx.Request) -> httpx.Response:
364364 assert client .accept_invite (token , payload , idempotency_key = "invite-accept-1" )["status" ] == "accepted"
365365
366366
367+ def test_create_media_upload_success () -> None :
368+ upload_id = "77777777-7777-4777-8777-777777777777"
369+ payload = {
370+ "owner_agent" : "agent://owner" ,
371+ "filename" : "contract.pdf" ,
372+ "mime_type" : "application/pdf" ,
373+ "size_bytes" : 12345 ,
374+ }
375+
376+ def handler (request : httpx .Request ) -> httpx .Response :
377+ assert request .method == "POST"
378+ assert request .url .path == "/v1/media/create-upload"
379+ assert request .headers ["idempotency-key" ] == "media-create-1"
380+ body = json .loads (request .read ().decode ("utf-8" ))
381+ assert body == payload
382+ return httpx .Response (
383+ 200 ,
384+ json = {
385+ "ok" : True ,
386+ "upload_id" : upload_id ,
387+ "owner_agent" : "agent://owner" ,
388+ "bucket" : "axme-media" ,
389+ "object_path" : "agent-owner/contract.pdf" ,
390+ "upload_url" : "https://upload.example/media/1" ,
391+ "status" : "pending" ,
392+ "expires_at" : "2026-03-01T00:00:00Z" ,
393+ "max_size_bytes" : 10485760 ,
394+ },
395+ )
396+
397+ client = _client (handler )
398+ assert client .create_media_upload (payload , idempotency_key = "media-create-1" )["upload_id" ] == upload_id
399+
400+
401+ def test_get_media_upload_success () -> None :
402+ upload_id = "77777777-7777-4777-8777-777777777777"
403+
404+ def handler (request : httpx .Request ) -> httpx .Response :
405+ assert request .method == "GET"
406+ assert request .url .path == f"/v1/media/{ upload_id } "
407+ return httpx .Response (
408+ 200 ,
409+ json = {
410+ "ok" : True ,
411+ "upload" : {
412+ "upload_id" : upload_id ,
413+ "owner_agent" : "agent://owner" ,
414+ "bucket" : "axme-media" ,
415+ "object_path" : "agent-owner/contract.pdf" ,
416+ "mime_type" : "application/pdf" ,
417+ "filename" : "contract.pdf" ,
418+ "size_bytes" : 12345 ,
419+ "sha256" : None ,
420+ "status" : "pending" ,
421+ "created_at" : "2026-02-28T00:00:00Z" ,
422+ "expires_at" : "2026-03-01T00:00:00Z" ,
423+ "finalized_at" : None ,
424+ "download_url" : None ,
425+ "preview_url" : None ,
426+ },
427+ },
428+ )
429+
430+ client = _client (handler )
431+ assert client .get_media_upload (upload_id )["upload" ]["status" ] == "pending"
432+
433+
434+ def test_finalize_media_upload_success () -> None :
435+ upload_id = "77777777-7777-4777-8777-777777777777"
436+ payload = {"upload_id" : upload_id , "size_bytes" : 12345 }
437+
438+ def handler (request : httpx .Request ) -> httpx .Response :
439+ assert request .method == "POST"
440+ assert request .url .path == "/v1/media/finalize-upload"
441+ assert request .headers ["idempotency-key" ] == "media-finalize-1"
442+ body = json .loads (request .read ().decode ("utf-8" ))
443+ assert body == payload
444+ return httpx .Response (
445+ 200 ,
446+ json = {
447+ "ok" : True ,
448+ "upload_id" : upload_id ,
449+ "owner_agent" : "agent://owner" ,
450+ "bucket" : "axme-media" ,
451+ "object_path" : "agent-owner/contract.pdf" ,
452+ "mime_type" : "application/pdf" ,
453+ "size_bytes" : 12345 ,
454+ "sha256" : None ,
455+ "status" : "ready" ,
456+ "finalized_at" : "2026-02-28T00:00:10Z" ,
457+ },
458+ )
459+
460+ client = _client (handler )
461+ assert client .finalize_media_upload (payload , idempotency_key = "media-finalize-1" )["status" ] == "ready"
462+
463+
367464@pytest .mark .parametrize (
368465 ("status_code" , "expected_exception" ),
369466 [
0 commit comments