original_docstring: Assert and Clean Up: verify the metadata and delete the object.
docstring: Assert and Clean Up: verify the metadata and delete the object.
docstring_tokens: Assert and Clean Up : verify the metadata and delete the object .
code: def event_handler(event, _context):
      """Assert and Clean Up: verify the metadata and delete the object."""
      # If the arrange / act step returned an error, bail early
      if not event["arrange_act_payload"]["act_success"]:
          return error_response(event["arrange_act_payload"]["error_message"])
  
      test_user_key = event["arrange_act_payload"]["test_user_key"]
      test_user_pk = test_user_key["PK"]
      test_user_sk = test_user_key["SK"]
  
      expected_json = {
          "EventType": "UserCreated",
          "PK": {"S": test_user_pk},
          "SK": {"S": test_user_sk},
      }
  
      # 3. Assert
  
      # Filter the sought event from the CloudWatch Log Group
      filter_pattern = (
          f'{{ ($.EventType = "UserCreated") && ($.SK.S = "{test_user_pk}") '
          f'&& ($.PK.S = "{test_user_sk}") }}'
      )
  
      # Set the search horizon to one minute ago
      start_time = int((datetime.today() - timedelta(minutes=1)).timestamp()) * 1000
  
      # Execute the search
      response = logs_client.filter_log_events(
          logGroupName=log_group_name, startTime=start_time, filterPattern=filter_pattern
      )
  
      # Assert exactly one event matching the pattern is found
      if "events" not in response:
          return clean_up_with_error_response(
              test_user_pk, test_user_sk, "events not found"
          )
  
      if len(response["events"]) == 0:
          return clean_up_with_error_response(
              test_user_pk, test_user_sk, "event not found"
          )
  
      if len(response["events"]) != 1:
          return clean_up_with_error_response(
              test_user_pk, test_user_sk, "more than one event found"
          )
  
      if json.loads(response["events"][0]["message"]) != expected_json:
          return clean_up_with_error_response(
              test_user_pk, test_user_sk, "log event does not match expected JSON"
          )
  
      # Return success
      return clean_up_with_success_response(test_user_pk, test_user_sk)
code_tokens: def event_handler ( event , _context ) : if not event [ "arrange_act_payload" ] [ "act_success" ] : return error_response ( event [ "arrange_act_payload" ] [ "error_message" ] ) test_user_key = event [ "arrange_act_payload" ] [ "test_user_key" ] test_user_pk = test_user_key [ "PK" ] test_user_sk = test_user_key [ "SK" ] expected_json = { "EventType" : "UserCreated" , "PK" : { "S" : test_user_pk } , "SK" : { "S" : test_user_sk } , } filter_pattern = ( f'{{ ($.EventType = "UserCreated") && ($.SK.S = "{test_user_pk}") ' f'&& ($.PK.S = "{test_user_sk}") }}' ) start_time = int ( ( datetime . today ( ) - timedelta ( minutes = 1 ) ) . timestamp ( ) ) * 1000 response = logs_client . filter_log_events ( logGroupName = log_group_name , startTime = start_time , filterPattern = filter_pattern ) if "events" not in response : return clean_up_with_error_response ( test_user_pk , test_user_sk , "events not found" ) if len ( response [ "events" ] ) == 0 : return clean_up_with_error_response ( test_user_pk , test_user_sk , "event not found" ) if len ( response [ "events" ] ) != 1 : return clean_up_with_error_response ( test_user_pk , test_user_sk , "more than one event found" ) if json . loads ( response [ "events" ] [ 0 ] [ "message" ] ) != expected_json : return clean_up_with_error_response ( test_user_pk , test_user_sk , "log event does not match expected JSON" ) return clean_up_with_success_response ( test_user_pk , test_user_sk )
short_docstring: Assert and Clean Up: verify the metadata and delete the object.
short_docstring_tokens: Assert and Clean Up : verify the metadata and delete the object .
comment: """Assert and Clean Up: verify the metadata and delete the object."""$SEP$# If the arrange / act step returned an error, bail early$SEP$# 3. Assert$SEP$# Filter the sought event from the CloudWatch Log Group$SEP$# Set the search horizon to one minute ago$SEP$# Execute the search$SEP$# Assert exactly one event matching the pattern is found$SEP$# Return success