Skip to content

Commit 4ef4937

Browse files
Hani YacoubHani Yacoub
authored andcommitted
set smoke tests to smoke and sanity
1 parent d68788b commit 4ef4937

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

modules/testrail.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def get_test_case(self, case_id):
160160
"""Get a given Test Case"""
161161
return self.client.send_get(f"get_case/{case_id}")
162162

163+
def get_suites(self, project_id):
164+
"""Get all suites for project"""
165+
return self.client.send_get(f"get_suites/{project_id}")
166+
163167
def update_cases_in_suite(self, suite_id, case_ids, **kwargs):
164168
"""Given a suite and a list of test cases, update all listed
165169
test cases according to keyword args"""
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import logging
2+
from dotenv import load_dotenv
3+
from modules.testrail_integration import testrail_init
4+
5+
# Load environment variables from .env file
6+
load_dotenv()
7+
8+
# Configuration Constants
9+
PROJECT_ID = 17 # The ID of the TestRail project to work with
10+
SUITE_NAMES = ["PDF Viewer"] # List of suite names to process
11+
12+
CUSTOM_SUB_TEST_SUITES = [2] # Value to set for the 'custom_sub_test_suites' field
13+
TEST_SUB_SUITES = {
14+
1: "functional",
15+
2: "smoke",
16+
3: "accessibility",
17+
4: "l10n",
18+
5: "security",
19+
6: "fxa",
20+
7: "other"
21+
}
22+
updated_count = 0
23+
DRY_RUN = True # If True, only log actions without making changes
24+
25+
26+
def get_all_cases_from_suite(tr, project_id, suite_id):
27+
"""
28+
Fetch all test cases from a given TestRail suite using pagination.
29+
30+
Args:
31+
tr: TestRail API client instance.
32+
project_id (int): The ID of the TestRail project.
33+
suite_id (int): The ID of the suite to fetch cases from.
34+
35+
Returns:
36+
list: A list of test case dictionaries.
37+
"""
38+
all_cases = [] # List to store all fetched test cases
39+
offset = 0 # Starting point for pagination
40+
limit = 240 # Maximum number of cases to fetch in each API call
41+
42+
while True:
43+
# Build the API endpoint with pagination parameters
44+
endpoint = f"get_cases/{project_id}&suite_id={suite_id}&limit={limit}&offset={offset}"
45+
response = tr.client.send_get(endpoint) # Send API request to TestRail
46+
cases = response.get("cases", []) # Extract the list of test cases
47+
48+
if not cases:
49+
# If no more cases are found, break the loop
50+
break
51+
52+
# Add the fetched cases to the complete list
53+
all_cases.extend(cases)
54+
55+
if len(cases) < limit:
56+
# If the number of fetched cases is less than the limit, we are at the last page
57+
break
58+
59+
# Increment offset to fetch the next batch of cases
60+
offset += limit
61+
62+
# Log the total number of fetched cases
63+
logging.info(f"Total cases fetched from suite {suite_id}: {len(all_cases)}")
64+
return all_cases
65+
66+
67+
if __name__ == "__main__":
68+
# Initialize logging to display info messages
69+
logging.basicConfig(level=logging.INFO)
70+
71+
# Initialize the TestRail API client
72+
tr = testrail_init()
73+
74+
# Fetch suite IDs matching the given suite names
75+
suites = tr.get_suites(PROJECT_ID)
76+
suite_ids = [suite["id"] for suite in suites if suite["name"] in SUITE_NAMES]
77+
logging.info(f"Found suites: {suite_ids}")
78+
79+
# Fetch all test cases from the selected suites
80+
all_cases = [] # List to store all fetched test cases
81+
for suite_id in suite_ids:
82+
# Fetch and add cases from each suite
83+
cases = get_all_cases_from_suite(tr, PROJECT_ID, suite_id)
84+
all_cases.extend(cases)
85+
86+
# Log the total number of test cases found
87+
logging.info(f"Total test cases found for selected suites: {len(all_cases)}")
88+
89+
updated_count = 0 # Counter for the number of cases updated
90+
91+
# Iterate through all cases
92+
for case in all_cases:
93+
case_id = case["id"]
94+
sub_test_suites_value = case.get("sub_test_suites", [])
95+
96+
logging.info(f"Case ID {case_id} sub_test_suites: {sub_test_suites_value}")
97+
98+
case_id = case["id"]
99+
sub_test_suites_value = case.get("sub_test_suites", []) # Fallback to empty list
100+
custom_value = case.get("custom_sub_test_suites", "Not Set")
101+
102+
# Check if 2 is present in sub_test_suites
103+
if 2 not in sub_test_suites_value:
104+
logging.info(f"Skipping case {case_id} – sub_test_suites = {sub_test_suites_value}")
105+
continue
106+
107+
logging.info(
108+
f"Case ID {case_id} matches (contains 2 in sub_test_suites). Current custom_sub_test_suites: {custom_value}")
109+
110+
if not DRY_RUN:
111+
# Perform the update
112+
result = tr.update_case_field(case_id, "custom_sub_test_suites", CUSTOM_SUB_TEST_SUITES)
113+
logging.info(f"Updated case {case_id} to '{CUSTOM_SUB_TEST_SUITES}', Result: {result}")
114+
else:
115+
logging.info(f"[DRY RUN] Would update case {case_id} from '{custom_value}' to '{CUSTOM_SUB_TEST_SUITES}'.")
116+
117+
updated_count += 1
118+
119+
logging.info(f"Total cases {'updated' if not DRY_RUN else 'to be updated'}: {updated_count}")

0 commit comments

Comments
 (0)