-
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
Closed
Closed
vs/testrail-api-ex #542
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
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", "Startup and Profile", "Reader View"] | ||
PROJECT_ID = 17 | ||
|
||
# Define what field to update and its new value | ||
FIELD_TO_UPDATE = "custom_automation_coverage" | ||
NEW_FIELD_VALUE = 3 # 3 might represent 'Covered' | ||
|
||
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.get("custom_automated_test_names") and case.get("custom_automation_status") == 4 | ||
] | ||
matching_case_ids = [case["id"] for case in matching_cases] | ||
|
||
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.") | ||
|
||
logging.info(f"Total collected case IDs: {case_ids}") | ||
|
||
# Perform updates to TestRail | ||
for case_id in case_ids: | ||
response = tr.update_case_field(case_id, FIELD_TO_UPDATE, NEW_FIELD_VALUE) | ||
logging.info(f"Updated case ID {case_id}: {response}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.