-
Notifications
You must be signed in to change notification settings - Fork 10
vs/testrail-api-ex #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vs/testrail-api-ex #542
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import logging | ||
import os | ||
from dotenv import load_dotenv | ||
from modules.testrail_integration import testrail_init | ||
|
||
# Set up logging | ||
logging.basicConfig( | ||
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" | ||
) | ||
|
||
# Load env file from project root | ||
script_dir = os.path.dirname(__file__) | ||
project_root = os.path.abspath(os.path.join(script_dir, "..")) | ||
env_file_path = os.path.join(project_root, "api_credentials.env") | ||
load_dotenv(dotenv_path=env_file_path) | ||
|
||
MY_SUITES = ["Printing UI", "Profile", "Reader View"] | ||
PROJECT_ID = 17 | ||
|
||
DRY_RUN = True # Set to False when performing actual run | ||
|
||
def main(): | ||
# Read credentials from environment | ||
base_url = os.environ.get("TESTRAIL_BASE_URL") | ||
username = os.environ.get("TESTRAIL_USERNAME") | ||
api_key = os.environ.get("TESTRAIL_API_KEY") | ||
|
||
if not all([base_url, username, api_key]): | ||
logging.error("Missing TestRail credentials. Check your .env file.") | ||
return | ||
|
||
logging.info(f"Loaded TestRail credentials for user: {username}") | ||
logging.info(f"TestRail Base URL: {base_url}") | ||
|
||
tr = testrail_init() | ||
|
||
logging.info(f"Fetching suite IDs for suites: {MY_SUITES}") | ||
suites = list(tr.get_suites(PROJECT_ID)) | ||
suite_ids = [ | ||
suite["id"] | ||
for suite in suites | ||
if suite["name"] in MY_SUITES | ||
] | ||
logging.info(f"Suite IDs to process: {suite_ids}") | ||
|
||
case_ids = [] | ||
for suite_id in suite_ids: | ||
val = tr._get_test_cases(PROJECT_ID, suite_id) | ||
if val["size"] < val["limit"]: | ||
matching_cases = [ | ||
case for case in val["cases"] if case["custom_automated_test_names"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting way to check if automation is done. Let's see if it works! |
||
] | ||
vsangereanMOZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
matching_case_ids = [case["id"] for case in matching_cases] | ||
|
||
if DRY_RUN: | ||
logging.info( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, run a dry run and post the ids of the cases you would have updated here. If they look good, I'll give you the go-ahead to run the script live. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still have some issues with this. I will handle it ASAP. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you dealt with these issues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2025-04-08 10:20:11,390 - INFO - TestRail Base URL: https://mozilla.testrail.io Process finished with exit code 0 THis is what I currently have. Is this ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that looks good, go ahead and run the script! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did run it. Must I do something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, seems like that didn't change the coverage values in TR. Did you only run the dry run, or have you also run it with dry run disabled (i.e. live)? If not, go ahead and do that. If so, there may be something wrong with the script. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the update logic wasn't added and DRY_RUN wasn't turned off |
||
f"[DRY RUN] Suite {suite_id} would process cases: {matching_case_ids}" | ||
) | ||
else: | ||
case_ids.extend(matching_case_ids) | ||
logging.info( | ||
f"Suite {suite_id} processed and added case IDs: {matching_case_ids}" | ||
) | ||
else: | ||
logging.warning(f"Suite {suite_id} test cases exceed retrieval limit.") | ||
|
||
if DRY_RUN: | ||
logging.info("[DRY RUN] No actual updates performed.") | ||
logging.info(f"[DRY RUN] Total collected case IDs (not updated): {case_ids}") | ||
else: | ||
logging.info(f"Total collected case IDs: {case_ids}") | ||
# Add here actual logic for updates if necessary | ||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the correct suite list names are:
["Printing", "Startup and Profile", "Reader View"]
but I would confirm with @ben-c-at-mozThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I already updated this in my local change.