def update_null_automation_status()

in modules/testrail_script_set_null_automation_status_to_untriaged.py [0:0]


def update_null_automation_status(tr, project_id, dry_run=True):
    """Update test cases with None automation status to Untriaged"""
    try:
        # Get all suites in the project
        suites = get_all_suites(tr, project_id)

        # Track statistics
        total_null_cases = 0
        updated_count = 0

        # Process each suite
        for suite in suites:
            suite_id = suite["id"]
            suite_name = suite["name"]
            logging.info(f"Processing suite {suite_name} (ID: {suite_id})...")

            # Retrieve test cases for this suite
            try:
                cases = get_all_test_cases(tr, project_id, suite_id)

                # Filter cases with null automation status
                null_status_cases = [
                    case
                    for case in cases
                    if case.get("custom_automation_status") is None
                ]

                suite_null_count = len(null_status_cases)
                total_null_cases += suite_null_count

                logging.info(
                    f"Found {suite_null_count} cases with null automation status in suite {suite_name}"
                )

                # Update each case that meets the criteria
                for case in null_status_cases:
                    case_id = case["id"]
                    try:
                        if dry_run:
                            logging.info(
                                f"[DRY RUN] Would update case {case_id}: set automation status to Untriaged (1)"
                            )
                        else:
                            # Perform the update
                            tr.update_case_field(
                                case_id, "custom_automation_status", "1"
                            )
                            logging.info(
                                f"Updated case {case_id}: set automation status to Untriaged (1)"
                            )
                            updated_count += 1
                    except Exception as e:
                        logging.error(f"Error updating case {case_id}: {e}")
            except Exception as e:
                logging.error(f"Error processing suite {suite_id}: {e}")
                continue

        # Log summary
        logging.info(
            f"Summary: Found {total_null_cases} cases with null automation status across all suites"
        )
        if not dry_run:
            logging.info(f"Updated {updated_count} cases to Untriaged")
        else:
            logging.info(
                f"Would update {total_null_cases} cases to Untriaged (dry run)"
            )

    except Exception as e:
        logging.error(f"Error processing cases: {e}")