1212
1313import pytest
1414import requests
15+ from botocore .exceptions import ConnectionError # type: ignore
1516
1617from aws_durable_execution_sdk_python_testing .cli import CliApp , CliConfig , main
1718from aws_durable_execution_sdk_python_testing .exceptions import (
1819 DurableFunctionsLocalRunnerError ,
20+ InvalidParameterValueException ,
21+ ResourceNotFoundException ,
22+ ServiceException ,
23+ TooManyRequestsException ,
1924)
2025
2126
@@ -777,15 +782,25 @@ def test_get_durable_execution_command_handles_resource_not_found() -> None:
777782
778783 with patch .object (app , "_create_boto3_client" ) as mock_create_client :
779784 mock_client = mock_create_client .return_value
780- mock_client .get_durable_execution .side_effect = Exception (
781- "ResourceNotFoundException: Execution not found"
785+
786+ mock_client .exceptions .ResourceNotFoundException = ResourceNotFoundException
787+ mock_client .exceptions .InvalidParameterValueException = (
788+ InvalidParameterValueException
782789 )
790+ mock_client .exceptions .TooManyRequestsException = TooManyRequestsException
791+ mock_client .exceptions .ServiceException = ServiceException
783792
784- exit_code = app . get_durable_execution_command (
785- argparse . Namespace ( durable_execution_arn = "nonexistent-arn" )
793+ mock_client . get_durable_execution . side_effect = ResourceNotFoundException (
794+ "Resource not found"
786795 )
787796
788- assert exit_code == 1
797+ with patch ("sys.stderr" , new_callable = StringIO ) as mock_stderr :
798+ exit_code = app .get_durable_execution_command (
799+ argparse .Namespace (durable_execution_arn = "nonexistent-arn" )
800+ )
801+
802+ assert exit_code == 1
803+ assert "Error: Execution not found" in mock_stderr .getvalue ()
789804
790805
791806def test_get_durable_execution_command_handles_invalid_parameter () -> None :
@@ -794,15 +809,79 @@ def test_get_durable_execution_command_handles_invalid_parameter() -> None:
794809
795810 with patch .object (app , "_create_boto3_client" ) as mock_create_client :
796811 mock_client = mock_create_client .return_value
797- mock_client .get_durable_execution .side_effect = Exception (
798- "InvalidParameterValueException: Invalid ARN format"
812+
813+ mock_client .exceptions .ResourceNotFoundException = ResourceNotFoundException
814+ mock_client .exceptions .InvalidParameterValueException = (
815+ InvalidParameterValueException
799816 )
817+ mock_client .exceptions .TooManyRequestsException = TooManyRequestsException
818+ mock_client .exceptions .ServiceException = ServiceException
800819
801- exit_code = app . get_durable_execution_command (
802- argparse . Namespace ( durable_execution_arn = "invalid-arn" )
820+ mock_client . get_durable_execution . side_effect = InvalidParameterValueException (
821+ "Invalid parameters"
803822 )
804823
805- assert exit_code == 1
824+ with patch ("sys.stderr" , new_callable = StringIO ) as mock_stderr :
825+ exit_code = app .get_durable_execution_command (
826+ argparse .Namespace (durable_execution_arn = "invalid-arn" )
827+ )
828+
829+ assert exit_code == 1
830+ assert "Error: Invalid parameter" in mock_stderr .getvalue ()
831+
832+
833+ def test_get_durable_execution_command_handles_too_many_requests () -> None :
834+ """Test that get-durable-execution command handles InvalidParameterValueException."""
835+ app = CliApp ()
836+
837+ with patch .object (app , "_create_boto3_client" ) as mock_create_client :
838+ mock_client = mock_create_client .return_value
839+
840+ mock_client .exceptions .ResourceNotFoundException = ResourceNotFoundException
841+ mock_client .exceptions .InvalidParameterValueException = (
842+ InvalidParameterValueException
843+ )
844+ mock_client .exceptions .TooManyRequestsException = TooManyRequestsException
845+ mock_client .exceptions .ServiceException = ServiceException
846+
847+ mock_client .get_durable_execution .side_effect = TooManyRequestsException (
848+ "Too many requests"
849+ )
850+
851+ with patch ("sys.stderr" , new_callable = StringIO ) as mock_stderr :
852+ exit_code = app .get_durable_execution_command (
853+ argparse .Namespace (durable_execution_arn = "my-arn" )
854+ )
855+
856+ assert exit_code == 1
857+ assert "Error: Too many requests" in mock_stderr .getvalue ()
858+
859+
860+ def test_get_durable_execution_command_handles_service_exception () -> None :
861+ """Test that get-durable-execution command handles InvalidParameterValueException."""
862+ app = CliApp ()
863+
864+ with patch .object (app , "_create_boto3_client" ) as mock_create_client :
865+ mock_client = mock_create_client .return_value
866+
867+ mock_client .exceptions .ResourceNotFoundException = ResourceNotFoundException
868+ mock_client .exceptions .InvalidParameterValueException = (
869+ InvalidParameterValueException
870+ )
871+ mock_client .exceptions .TooManyRequestsException = TooManyRequestsException
872+ mock_client .exceptions .ServiceException = ServiceException
873+
874+ mock_client .get_durable_execution .side_effect = ServiceException (
875+ "Service exception"
876+ )
877+
878+ with patch ("sys.stderr" , new_callable = StringIO ) as mock_stderr :
879+ exit_code = app .get_durable_execution_command (
880+ argparse .Namespace (durable_execution_arn = "my-arn" )
881+ )
882+
883+ assert exit_code == 1
884+ assert "Error: Service error" in mock_stderr .getvalue ()
806885
807886
808887def test_get_durable_execution_command_handles_connection_error () -> None :
@@ -811,15 +890,29 @@ def test_get_durable_execution_command_handles_connection_error() -> None:
811890
812891 with patch .object (app , "_create_boto3_client" ) as mock_create_client :
813892 mock_client = mock_create_client .return_value
814- mock_client .get_durable_execution .side_effect = Exception (
815- "Could not connect to endpoint"
893+
894+ mock_client .exceptions .ResourceNotFoundException = ResourceNotFoundException
895+ mock_client .exceptions .InvalidParameterValueException = (
896+ InvalidParameterValueException
816897 )
898+ mock_client .exceptions .TooManyRequestsException = TooManyRequestsException
899+ mock_client .exceptions .ServiceException = ServiceException
817900
818- exit_code = app . get_durable_execution_command (
819- argparse . Namespace ( durable_execution_arn = "test-arn" )
901+ mock_client . get_durable_execution . side_effect = ConnectionError (
902+ error = "Mocked connection error"
820903 )
821904
822- assert exit_code == 1
905+ with patch (
906+ "aws_durable_execution_sdk_python_testing.cli.logger"
907+ ) as mock_logger :
908+ exit_code = app .get_durable_execution_command (
909+ argparse .Namespace (durable_execution_arn = "my-arn" )
910+ )
911+
912+ assert exit_code == 1
913+ mock_logger .exception .assert_called_once_with (
914+ "Error: Could not connect to the local runner server. Is it running?"
915+ )
823916
824917
825918def test_get_durable_execution_history_command_uses_boto3_client () -> None :
@@ -987,15 +1080,27 @@ def test_get_durable_execution_command_handles_general_exception() -> None:
9871080
9881081 with patch .object (app , "_create_boto3_client" ) as mock_create_client :
9891082 mock_client = mock_create_client .return_value
1083+ mock_client .exceptions .ResourceNotFoundException = ResourceNotFoundException
1084+ mock_client .exceptions .InvalidParameterValueException = (
1085+ InvalidParameterValueException
1086+ )
1087+ mock_client .exceptions .TooManyRequestsException = TooManyRequestsException
1088+ mock_client .exceptions .ServiceException = ServiceException
9901089 mock_client .get_durable_execution .side_effect = ValueError (
9911090 "Some unexpected error"
9921091 )
9931092
994- exit_code = app .get_durable_execution_command (
995- argparse .Namespace (durable_execution_arn = "test-arn" )
996- )
1093+ with patch (
1094+ "aws_durable_execution_sdk_python_testing.cli.logger"
1095+ ) as mock_logger :
1096+ exit_code = app .get_durable_execution_command (
1097+ argparse .Namespace (durable_execution_arn = "my-arn" )
1098+ )
9971099
998- assert exit_code == 1
1100+ assert exit_code == 1
1101+ mock_logger .exception .assert_called_once_with (
1102+ "Unexpected error in get-durable-execution command"
1103+ )
9991104
10001105
10011106def test_get_durable_execution_history_command_handles_general_exception () -> None :
0 commit comments