Skip to content

Commit e13cf3e

Browse files
authored
Merge pull request #593 from mozilla/as/testrail-integration-empty-to-none-automation-coverage
Anca/ Set automation coverage to None for empty coverage fields and non-completed automation statuses
2 parents 0276320 + 6852e82 commit e13cf3e

File tree

2 files changed

+60
-67
lines changed

2 files changed

+60
-67
lines changed

modules/testrail_scripts/testrail_script_set_untriaged_suitable_to_null_coverage.py renamed to modules/testrail_scripts/set_coverage_none_for_untriaged_suitable_unsuitable_disabled_automation.py

Lines changed: 60 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,48 @@
77
from modules.testrail_integration import testrail_init
88

99
# Set up logging
10-
logging.basicConfig(
11-
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
12-
)
10+
logging.basicConfig(level=logging.INFO, format="%(message)s")
1311

1412
# Load env file from project root
1513
script_dir = os.path.dirname(__file__)
16-
project_root = os.path.abspath(os.path.join(script_dir, ".."))
14+
project_root = os.path.abspath(os.path.join(script_dir, "..", ".."))
1715
env_file_path = os.path.join(project_root, "testrail_credentials.env")
1816
load_dotenv(dotenv_path=env_file_path)
1917

2018
# TestRail project ID (Fx Desktop)
2119
PROJECT_ID = 17
2220

23-
# Specific suites to process
24-
SUITES = [
25-
("18215", "Address Bar and Search"),
26-
("1731", "Audio/Video"),
27-
("2525", "Bookmarks and History"),
28-
("29219", "Downloads"),
29-
("5259", "Drag and Drop"),
30-
("2085", "Find Toolbar"),
31-
("2054", "Form Autofill"),
32-
("498", "Geolocation"),
33-
("22801", "Language Packs"),
34-
("85", "Menus"),
35-
("6066", "Networking"),
36-
("1907", "Notifications"),
37-
("65", "PDF Viewer"),
38-
("43517", "Password Manager"),
39-
("5403", "Pocket"),
40-
("2241", "Preferences"),
41-
("2119", "Profile"),
42-
("73", "Printing UI"),
43-
("2126", "Reader View"),
44-
("102", "Scrolling"),
45-
("5833", "Security and Privacy"),
46-
("2130", "Sync & Firefox Account"),
47-
("2103", "Tabs"),
48-
("1997", "Theme and Toolbar"),
49-
]
50-
5121
# Automation status values
52-
AUTOMATION_STATUS = {"UNTRIAGED": 1, "SUITABLE": 2, "NOT_SUITABLE": 3, "COMPLETED": 4}
22+
AUTOMATION_STATUS = {
23+
"UNTRIAGED": 1,
24+
"SUITABLE": 2,
25+
"NOT_SUITABLE": 3,
26+
"COMPLETED": 4,
27+
"DISABLED": 5,
28+
}
5329

5430
# Automation coverage values
5531
AUTOMATION_COVERAGE = {"NONE": 1, "PARTIAL": 2, "FULL": 3}
5632

5733
# Coverage value to name mapping for better logging
5834
COVERAGE_NAMES = {1: "None", 2: "Partial", 3: "Full"}
5935

36+
# Status value to name mapping for better logging
37+
STATUS_NAMES = {
38+
1: "Untriaged",
39+
2: "Suitable",
40+
3: "Unsuitable",
41+
4: "Completed",
42+
5: "Disabled",
43+
}
44+
45+
46+
def get_all_suites(tr, project_id):
47+
"""Get all suites from the project"""
48+
suites = tr.client.send_get(f"get_suites/{project_id}")
49+
logging.info(f"Found {len(suites)} suites in project {project_id}")
50+
return suites
51+
6052

6153
def get_all_test_cases(tr, project_id, suite_id):
6254
"""Fetch all test cases from a suite by handling pagination."""
@@ -83,11 +75,10 @@ def get_all_test_cases(tr, project_id, suite_id):
8375
return all_cases
8476

8577

86-
def set_untriaged_suitable_to_null_coverage(
87-
tr, project_id, dry_run=True, batch_size=25
88-
):
78+
def update_coverage_to_none(tr, project_id, dry_run=True, batch_size=25):
8979
"""
90-
Set automation coverage to None for test cases that have automation status of Untriaged or Suitable
80+
Set automation coverage to None for all test cases that have automation status of
81+
Untriaged, Suitable, or Not Suitable, regardless of their current coverage value
9182
"""
9283
start_time = time.time()
9384
try:
@@ -97,10 +88,14 @@ def set_untriaged_suitable_to_null_coverage(
9788
updated_count = 0
9889
changed_case_ids = [] # Track all case IDs that will be changed
9990

100-
# Process each specified suite
101-
total_suites = len(SUITES)
102-
for index, (suite_id, suite_name) in enumerate(SUITES, 1):
103-
# Show progress
91+
# Get all suites in the project
92+
suites = get_all_suites(tr, project_id)
93+
total_suites = len(suites)
94+
95+
# Process each suite
96+
for index, suite in enumerate(suites, 1):
97+
suite_id = suite["id"]
98+
suite_name = suite["name"]
10499
logging.info(f"Processing suite {index}/{total_suites}: {suite_name}")
105100

106101
try:
@@ -112,18 +107,17 @@ def set_untriaged_suitable_to_null_coverage(
112107
status = case.get("custom_automation_status")
113108
coverage = case.get("custom_automation_coverage")
114109

115-
# Check if status is Untriaged or Suitable
110+
# Check if status is one that should have None coverage
116111
if status in [
117112
AUTOMATION_STATUS["UNTRIAGED"],
118113
AUTOMATION_STATUS["SUITABLE"],
114+
AUTOMATION_STATUS["NOT_SUITABLE"],
115+
AUTOMATION_STATUS["DISABLED"],
119116
]:
120-
# Check coverage value
121-
if coverage in [
122-
AUTOMATION_COVERAGE["FULL"],
123-
AUTOMATION_COVERAGE["PARTIAL"],
124-
]:
117+
# If coverage is not None, add to update targets
118+
if coverage != AUTOMATION_COVERAGE["NONE"]:
125119
update_targets.append(case)
126-
elif coverage == AUTOMATION_COVERAGE["NONE"]:
120+
else:
127121
skipped_cases += 1
128122

129123
suite_update_count = len(update_targets)
@@ -143,14 +137,12 @@ def set_untriaged_suitable_to_null_coverage(
143137
batch_ids = []
144138
for case in batch:
145139
case_id = case["id"]
146-
coverage = case.get("custom_automation_coverage")
147-
coverage_name = COVERAGE_NAMES.get(coverage)
148-
149-
if coverage_name is None:
150-
logging.warning(
151-
f"Case {case_id} has unexpected coverage value: {coverage}"
152-
)
153-
coverage_name = "Unknown"
140+
current_coverage = case.get(
141+
"custom_automation_coverage"
142+
)
143+
coverage_name = COVERAGE_NAMES.get(
144+
current_coverage, "Empty"
145+
)
154146

155147
try:
156148
tr.update_case_field(
@@ -175,17 +167,18 @@ def set_untriaged_suitable_to_null_coverage(
175167
)
176168
for case in batch:
177169
case_id = case["id"]
178-
coverage = case.get("custom_automation_coverage")
179-
coverage_name = COVERAGE_NAMES.get(coverage)
180-
181-
if coverage_name is None:
182-
logging.warning(
183-
f"Case {case_id} has unexpected coverage value: {coverage}"
184-
)
185-
coverage_name = "Unknown"
186-
170+
current_status = case.get("custom_automation_status")
171+
current_coverage = case.get(
172+
"custom_automation_coverage"
173+
)
174+
status_name = STATUS_NAMES.get(
175+
current_status, "Unknown"
176+
)
177+
coverage_name = COVERAGE_NAMES.get(
178+
current_coverage, "Empty"
179+
)
187180
logging.info(
188-
f" Case {case_id} - {coverage_name} → None"
181+
f" Case {case_id} - Status: {status_name}, Coverage: {coverage_name} → None"
189182
)
190183
changed_case_ids.append((case_id, suite_name))
191184

@@ -242,7 +235,7 @@ def main():
242235

243236
# Process all cases in the project
244237
logging.info(f"Processing project ID: {PROJECT_ID}...")
245-
set_untriaged_suitable_to_null_coverage(tr, PROJECT_ID, dry_run)
238+
update_coverage_to_none(tr, PROJECT_ID, dry_run)
246239

247240

248241
if __name__ == "__main__":

0 commit comments

Comments
 (0)