@@ -260,6 +260,27 @@ def test_http_request_from_bytes_standard_json() -> None:
260260 assert request .body == test_data
261261
262262
263+ def test_http_get_request_from_bytes_ignore_body () -> None :
264+ """Test HTTPRequest.from_bytes with standard JSON deserialization."""
265+ test_data = {"key" : "value" , "number" : 42 }
266+ body_bytes = json .dumps (test_data ).encode ("utf-8" )
267+
268+ path = Route .from_string ("/test" )
269+ request = HTTPRequest .from_bytes (
270+ body_bytes = body_bytes ,
271+ method = "GET" ,
272+ path = path ,
273+ headers = {"Content-Type" : "application/json" },
274+ query_params = {"param" : ["value" ]},
275+ )
276+
277+ assert request .method == "GET"
278+ assert request .path == path
279+ assert request .headers == {"Content-Type" : "application/json" }
280+ assert request .query_params == {"param" : ["value" ]}
281+ assert request .body == {}
282+
283+
263284def test_http_request_from_bytes_minimal_params () -> None :
264285 """Test HTTPRequest.from_bytes with minimal parameters."""
265286 test_data = {"message" : "hello" }
@@ -413,33 +434,6 @@ def test_http_response_body_to_bytes_compact_format() -> None:
413434 assert "\n " not in body_str # No newlines
414435
415436
416- def test_http_response_body_to_bytes_aws_operation_fallback () -> None :
417- """Test body_to_bytes with AWS operation that falls back to JSON."""
418- test_data = {"ExecutionId" : "test-execution-id" , "Status" : "SUCCEEDED" }
419- response = HTTPResponse (status_code = 200 , headers = {}, body = test_data )
420-
421- # Use a non-existent operation name to trigger fallback
422- body_bytes = response .body_to_bytes (operation_name = "NonExistentOperation" )
423-
424- # Should still work via JSON fallback
425- assert isinstance (body_bytes , bytes )
426- parsed_data = json .loads (body_bytes .decode ("utf-8" ))
427- assert parsed_data == test_data
428-
429-
430- def test_http_response_body_to_bytes_invalid_data () -> None :
431- """Test body_to_bytes with data that can't be JSON serialized."""
432- # Create data with non-serializable object
433-
434- test_data = {"timestamp" : datetime .datetime .now (datetime .UTC )}
435- response = HTTPResponse (status_code = 200 , headers = {}, body = test_data )
436-
437- with pytest .raises (
438- InvalidParameterValueException , match = "JSON serialization failed"
439- ):
440- response .body_to_bytes ()
441-
442-
443437def test_http_response_body_to_bytes_empty_body () -> None :
444438 """Test body_to_bytes with empty body."""
445439 response = HTTPResponse (status_code = 204 , headers = {}, body = {})
@@ -465,28 +459,6 @@ def test_http_response_body_to_bytes_complex_data() -> None:
465459 assert parsed_data == complex_data
466460
467461
468- def test_http_response_body_to_bytes_aws_operation_success () -> None :
469- """Test body_to_bytes with valid AWS operation (if available)."""
470- # This test will use AWS serialization if available, otherwise fall back to JSON
471- test_data = {
472- "ExecutionId" : "test-execution-id" ,
473- "Status" : "SUCCEEDED" ,
474- "Result" : "test-result" ,
475- }
476- response = HTTPResponse (status_code = 200 , headers = {}, body = test_data )
477-
478- # Try with a real AWS operation name
479- body_bytes = response .body_to_bytes (operation_name = "StartDurableExecution" )
480-
481- # Should get valid bytes regardless of AWS vs JSON serialization
482- assert isinstance (body_bytes , bytes )
483- assert len (body_bytes ) > 0
484-
485- # Should be valid JSON (either from AWS serialization or fallback)
486- parsed_data = json .loads (body_bytes .decode ("utf-8" ))
487- assert isinstance (parsed_data , dict )
488-
489-
490462# Tests for HTTPResponse.from_dict method
491463
492464
@@ -627,47 +599,21 @@ def test_http_request_from_bytes_aws_deserialization_fallback_error() -> None:
627599 )
628600
629601
630- def test_http_response_body_to_bytes_aws_serialization_success () -> None :
631- """Test HTTPResponse.body_to_bytes with successful AWS serialization."""
632-
633- test_data = {"ExecutionId" : "test-id" , "Status" : "SUCCEEDED" }
634- response = HTTPResponse (status_code = 200 , headers = {}, body = test_data )
635- expected_bytes = b'{"ExecutionId":"test-id","Status":"SUCCEEDED"}'
636-
637- # Mock successful AWS serialization
638- mock_serializer = Mock ()
639- mock_serializer .to_bytes .return_value = expected_bytes
640-
641- with patch (
642- "aws_durable_execution_sdk_python_testing.web.models.AwsRestJsonSerializer.create" ,
643- return_value = mock_serializer ,
644- ):
645- result = response .body_to_bytes (operation_name = "StartDurableExecution" )
646-
647- assert result == expected_bytes
648- mock_serializer .to_bytes .assert_called_once_with (test_data )
649-
650-
651- def test_http_response_body_to_bytes_aws_serialization_fallback_error () -> None :
652- """Test HTTPResponse.body_to_bytes when both AWS and JSON serialization fail."""
602+ def test_http_response_body_to_bytes_serialization_error () -> None :
603+ """Test HTTPResponse.body_to_bytes when JSON serialization fail."""
653604
654605 # Create data that can't be JSON serialized
655- test_data = { "timestamp" : datetime . datetime . now ( datetime . UTC )}
656- response = HTTPResponse ( status_code = 200 , headers = {}, body = test_data )
606+ class CustomObject :
607+ pass
657608
658- # Mock AWS serialization failure
659- mock_serializer = Mock ()
660- mock_serializer .to_bytes .side_effect = InvalidParameterValueException ("AWS failed" )
609+ test_data = {"custom" : CustomObject ()}
610+ response = HTTPResponse (status_code = 200 , headers = {}, body = test_data )
661611
662- with patch (
663- "aws_durable_execution_sdk_python_testing.web.models.AwsRestJsonSerializer.create" ,
664- return_value = mock_serializer ,
612+ with pytest . raises (
613+ InvalidParameterValueException ,
614+ match = "Failed to serialize data to JSON: Object of type CustomObject is not JSON serializable" ,
665615 ):
666- with pytest .raises (
667- InvalidParameterValueException ,
668- match = "Both AWS and JSON serialization failed" ,
669- ):
670- response .body_to_bytes (operation_name = "StartDurableExecution" )
616+ response .body_to_bytes ()
671617
672618
673619# Tests for HTTPResponse.create_error_from_exception method
0 commit comments