@@ -87,7 +87,12 @@ def test_sync_rate_limit_uses_retry_after_from_response(mock_request, mock_sleep
8787
8888 # Verify that we got a successful response
8989 assert response .response .success is True
90- assert response .response .data .message_id == "test-message-id"
90+ # Validate returned message ID handles dict or model
91+ data = response .response .data
92+ if isinstance (data , dict ):
93+ assert data .get ("messageId" ) == "test-message-id"
94+ else :
95+ assert data .message_id == "test-message-id"
9196
9297 # Verify that requests.request was called twice (first rate limited, then success)
9398 assert mock_request .call_count == 2
@@ -138,7 +143,12 @@ def test_sync_rate_limit_uses_default_sleep_when_no_retry_after(mock_request, mo
138143
139144 # Verify that we got a successful response
140145 assert response .response .success is True
141- assert response .response .data .message_id == "test-message-id"
146+ # Validate returned message ID handles dict or model
147+ data = response .response .data
148+ if isinstance (data , dict ):
149+ assert data .get ("messageId" ) == "test-message-id"
150+ else :
151+ assert data .message_id == "test-message-id"
142152
143153 assert mock_request .call_count == 2
144154
@@ -264,10 +274,15 @@ async def test_async_rate_limit_uses_retry_after_from_response(mock_sleep, async
264274
265275 # Verify that asyncio.sleep was called with the retry_after value
266276 mock_sleep .assert_called_once_with (3 )
267-
277+
268278 # Verify that we got a successful response
269279 assert response .response .success is True
270- assert response .response .data .message_id == "test-message-id"
280+ # Validate returned message ID handles dict or model
281+ data = response .response .data
282+ if isinstance (data , dict ):
283+ assert data .get ("messageId" ) == "test-message-id"
284+ else :
285+ assert data .message_id == "test-message-id"
271286
272287 # Verify that HTTP client was called twice
273288 assert mock_http_client .request .call_count == 2
@@ -319,7 +334,12 @@ async def test_async_rate_limit_uses_default_sleep_when_no_retry_after(mock_slee
319334
320335 # Verify that we got a successful response
321336 assert response .response .success is True
322- assert response .response .data .message_id == "test-message-id"
337+ # Validate returned message ID handles dict or model
338+ data = response .response .data
339+ if isinstance (data , dict ):
340+ assert data .get ("messageId" ) == "test-message-id"
341+ else :
342+ assert data .message_id == "test-message-id"
323343 # Verify that HTTP client was called twice
324344 assert mock_http_client .request .call_count == 2
325345
@@ -434,11 +454,16 @@ async def test_async_rate_limit_retry_after_zero_uses_default(mock_sleep, async_
434454
435455 # Verify that asyncio.sleep was called with default 1 second since retry_after was 0
436456 mock_sleep .assert_called_once_with (1 )
437-
457+
438458 # Verify that we got a successful response
439459 assert response .response .success is True
440- assert response .response .data .message_id == "test-message-id"
441- # Verify that HTTP client was called twice
460+ # Validate returned message ID handles dict or model
461+ data = response .response .data
462+ if isinstance (data , dict ):
463+ assert data .get ("messageId" ) == "test-message-id"
464+ else :
465+ assert data .message_id == "test-message-id"
466+ # Verify that HTTP client was called twice
442467 assert mock_http_client .request .call_count == 2
443468
444469
@@ -481,11 +506,15 @@ def test_sync_rate_limit_retry_after_zero_uses_default(mock_request, mock_sleep,
481506
482507 # Make the request
483508 response = client .send_text (to = "+1234567890" , text_body = "Test message" )
484- # Verify that sleep was called with default 1 second since retry_after=0
509+ # Verify that sleep was called with default 1 second since retry_after=0
485510 mock_sleep .assert_called_once_with (1 )
486-
487511 # Verify that we got a successful response
488512 assert response .response .success is True
489- assert response .response .data .message_id == "test-message-id"
490-
513+ # Validate returned message ID handles dict or model
514+ data = response .response .data
515+ if isinstance (data , dict ):
516+ assert data .get ("messageId" ) == "test-message-id"
517+ else :
518+ assert data .message_id == "test-message-id"
519+ # Verify that requests.request was called twice
491520 assert mock_request .call_count == 2
0 commit comments