Add media workflow helpers and resource ID extraction; enhance tests for video and document status polling
This commit is contained in:
parent
1307d5691a
commit
ee539e8189
4 changed files with 138 additions and 6 deletions
|
|
@ -35,7 +35,7 @@ from ebay_client.generated.notification.models import (
|
|||
UpdateSubscriptionRequest,
|
||||
)
|
||||
from ebay_client.inventory.client import InventoryClient
|
||||
from ebay_client.media.client import CreatedMediaResource, MediaClient
|
||||
from ebay_client.media.client import CreatedMediaResource, MediaClient, extract_resource_id
|
||||
from ebay_client.notification.client import NotificationClient
|
||||
|
||||
|
||||
|
|
@ -430,6 +430,13 @@ def test_media_wrapper_returns_created_resource_location_for_video(httpx_mock: H
|
|||
|
||||
assert isinstance(result, CreatedMediaResource)
|
||||
assert result.location == "https://api.ebay.com/commerce/media/v1_beta/video/VIDEO-1"
|
||||
assert result.resource_id == "VIDEO-1"
|
||||
|
||||
|
||||
def test_extract_media_resource_id_handles_location_header() -> None:
|
||||
assert extract_resource_id("https://api.ebay.com/commerce/media/v1_beta/video/VIDEO-1") == "VIDEO-1"
|
||||
assert extract_resource_id("https://api.ebay.com/commerce/media/v1_beta/document/DOC-1/") == "DOC-1"
|
||||
assert extract_resource_id(None) is None
|
||||
|
||||
|
||||
def test_media_wrapper_returns_video_model(httpx_mock: HTTPXMock) -> None:
|
||||
|
|
@ -520,4 +527,39 @@ def test_media_wrapper_returns_document_models(httpx_mock: HTTPXMock) -> None:
|
|||
upload_request = httpx_mock.get_requests()[3]
|
||||
assert upload_request.headers["Content-Type"].startswith("multipart/form-data;")
|
||||
assert b"filename=\"guide.pdf\"" in upload_request.content
|
||||
assert b"%PDF-1.7" in upload_request.content
|
||||
assert b"%PDF-1.7" in upload_request.content
|
||||
|
||||
|
||||
def test_media_wait_for_video_returns_live_payload(monkeypatch) -> None:
|
||||
client = MediaClient(build_transport())
|
||||
states = iter(
|
||||
[
|
||||
Video(videoId="VIDEO-1", status="PENDING_UPLOAD"),
|
||||
Video(videoId="VIDEO-1", status="PROCESSING"),
|
||||
Video(videoId="VIDEO-1", status="LIVE"),
|
||||
]
|
||||
)
|
||||
|
||||
monkeypatch.setattr(client, "get_video", lambda _video_id: next(states))
|
||||
monkeypatch.setattr("ebay_client.media.client.sleep", lambda _seconds: None)
|
||||
|
||||
result = client.wait_for_video("VIDEO-1", poll_interval_seconds=0.0)
|
||||
|
||||
assert result.status == "LIVE"
|
||||
|
||||
|
||||
def test_media_wait_for_document_raises_on_terminal_failure(monkeypatch) -> None:
|
||||
client = MediaClient(build_transport())
|
||||
|
||||
monkeypatch.setattr(
|
||||
client,
|
||||
"get_document",
|
||||
lambda _document_id: DocumentResponse(documentId="DOC-1", documentStatus="REJECTED"),
|
||||
)
|
||||
|
||||
try:
|
||||
client.wait_for_document("DOC-1", poll_interval_seconds=0.0)
|
||||
except ValueError as exc:
|
||||
assert "REJECTED" in str(exc)
|
||||
else:
|
||||
raise AssertionError("Expected wait_for_document to raise on terminal failure status")
|
||||
Loading…
Add table
Add a link
Reference in a new issue