@@ -39,10 +39,7 @@ def test_update_function_concurrency_success(service, mock_lambda_client, mock_l
3939 ReservedConcurrentExecutions = reserved_concurrency
4040 )
4141
42- assert result ["statusCode" ] == 200
43- assert result ["body" ]["message" ] == "Concurrency updated successfully"
44- assert result ["body" ]["function" ] == target_function
45- assert result ["body" ]["reservedConcurrency" ] == reserved_concurrency
42+ assert result == reserved_concurrency
4643
4744 mock_logger .info .assert_any_call (
4845 f"Updating reserved concurrency for function '{ target_function } ' to { reserved_concurrency } "
@@ -64,20 +61,11 @@ def test_update_function_concurrency_function_not_found(service, mock_lambda_cli
6461 'Error' : {
6562 'Code' : 'ResourceNotFoundException' ,
6663 'Message' : 'Function not found'
67- }
64+ },
65+ 'ResponseMetadata' : {'HTTPStatusCode' : 404 }
6866 }
6967
70- # Create proper exception classes that inherit from ClientError
71- resource_not_found_exception = type ('ResourceNotFoundException' , (ClientError ,), {})
72- invalid_param_exception = type ('InvalidParameterValueException' , (ClientError ,), {})
73-
74- # Create a mock exceptions object with both exception types
75- mock_exceptions = MagicMock ()
76- mock_exceptions .ResourceNotFoundException = resource_not_found_exception
77- mock_exceptions .InvalidParameterValueException = invalid_param_exception
78- mock_client_instance .exceptions = mock_exceptions
79-
80- mock_client_instance .put_function_concurrency .side_effect = resource_not_found_exception (
68+ mock_client_instance .put_function_concurrency .side_effect = ClientError (
8169 error_response , 'PutFunctionConcurrency'
8270 )
8371
@@ -102,20 +90,11 @@ def test_update_function_concurrency_invalid_parameter(service, mock_lambda_clie
10290 'Error' : {
10391 'Code' : 'InvalidParameterValueException' ,
10492 'Message' : 'Reserved concurrency value must be non-negative'
105- }
93+ },
94+ 'ResponseMetadata' : {'HTTPStatusCode' : 400 }
10695 }
10796
108- # Create proper exception classes that inherit from ClientError
109- resource_not_found_exception = type ('ResourceNotFoundException' , (ClientError ,), {})
110- invalid_param_exception = type ('InvalidParameterValueException' , (ClientError ,), {})
111-
112- # Create a mock exceptions object with both exception types
113- mock_exceptions = MagicMock ()
114- mock_exceptions .ResourceNotFoundException = resource_not_found_exception
115- mock_exceptions .InvalidParameterValueException = invalid_param_exception
116- mock_client_instance .exceptions = mock_exceptions
117-
118- mock_client_instance .put_function_concurrency .side_effect = invalid_param_exception (
97+ mock_client_instance .put_function_concurrency .side_effect = ClientError (
11998 error_response , 'PutFunctionConcurrency'
12099 )
121100
@@ -124,9 +103,9 @@ def test_update_function_concurrency_invalid_parameter(service, mock_lambda_clie
124103 with pytest .raises (ClientError ):
125104 service .update_function_concurrency (target_function , reserved_concurrency )
126105
127- assert mock_logger .error .call_count == 1
128- error_call_args = str ( mock_logger . error . call_args )
129- assert "Invalid concurrency value" in error_call_args
106+ mock_logger .error .assert_called_once_with (
107+ f"Failed to update concurrency: An error occurred (InvalidParameterValueException) when calling the PutFunctionConcurrency operation: Reserved concurrency value must be non-negative"
108+ )
130109
131110
132111def test_update_function_concurrency_with_zero_value (service , mock_lambda_client , mock_logger ):
@@ -144,8 +123,7 @@ def test_update_function_concurrency_with_zero_value(service, mock_lambda_client
144123
145124 result = service .update_function_concurrency (target_function , reserved_concurrency )
146125
147- assert result ["statusCode" ] == 200
148- assert result ["body" ]["reservedConcurrency" ] == 0
126+ assert result == 0
149127
150128
151129def test_update_function_concurrency_with_large_value (service , mock_lambda_client , mock_logger ):
@@ -163,12 +141,53 @@ def test_update_function_concurrency_with_large_value(service, mock_lambda_clien
163141
164142 result = service .update_function_concurrency (target_function , reserved_concurrency )
165143
166- assert result ["statusCode" ] == 200
167- assert result ["body" ]["reservedConcurrency" ] == 1000
144+ assert result == 1000
168145
169146
170147def test_init_creates_lambda_client (mock_lambda_client ):
171148 service = ConcurrencyControllerService ()
172149
173150 mock_lambda_client .assert_called_once_with ("lambda" )
174151 assert service .lambda_client is not None
152+
153+
154+ def test_update_function_concurrency_missing_response_field (service , mock_lambda_client , mock_logger ):
155+ target_function = "test-lambda-function"
156+ reserved_concurrency = 10
157+
158+ mock_client_instance = MagicMock ()
159+ mock_lambda_client .return_value = mock_client_instance
160+
161+ # Response missing ReservedConcurrentExecutions field
162+ mock_client_instance .put_function_concurrency .return_value = {}
163+
164+ service .lambda_client = mock_client_instance
165+
166+ with pytest .raises (ValueError ) as exc_info :
167+ service .update_function_concurrency (target_function , reserved_concurrency )
168+
169+ assert str (exc_info .value ) == "Failed to confirm concurrency update from AWS response"
170+ mock_logger .error .assert_called_with ("Response did not contain ReservedConcurrentExecutions" )
171+
172+
173+ def test_update_function_concurrency_value_mismatch (service , mock_lambda_client , mock_logger ):
174+ target_function = "test-lambda-function"
175+ reserved_concurrency = 10
176+
177+ mock_client_instance = MagicMock ()
178+ mock_lambda_client .return_value = mock_client_instance
179+
180+ # AWS returned different value than requested
181+ mock_client_instance .put_function_concurrency .return_value = {
182+ "ReservedConcurrentExecutions" : 5
183+ }
184+
185+ service .lambda_client = mock_client_instance
186+
187+ with pytest .raises (ValueError ) as exc_info :
188+ service .update_function_concurrency (target_function , reserved_concurrency )
189+
190+ assert str (exc_info .value ) == "Concurrency update verification failed"
191+ mock_logger .error .assert_called_with (
192+ f"Concurrency mismatch: requested { reserved_concurrency } , AWS returned 5"
193+ )
0 commit comments