diff --git a/__main__.py b/__main__.py index 3630a32..04f176e 100644 --- a/__main__.py +++ b/__main__.py @@ -1,9 +1,9 @@ import argparse import sys -from bugz import BugzillaClient -from github import GithubClient -from jira import JiraClient +#from bugz import BugzillaClient +#from github import GithubClient +#from jira import JiraClient from testrail import TestRailClient from utils.constants import PROJECTS_MOBILE, PROJECTS_ECOSYSTEM, PLATFORM, REPORT_TYPES # noqa @@ -29,7 +29,7 @@ def parse_args(cmdln_args): parser.add_argument( "--report-type", help="Indicate report type", - required=True, + required=False, choices=REPORT_TYPES ) @@ -46,7 +46,8 @@ def parse_args(cmdln_args): def validate_project(platform, project, report_type): # Conditionally require --platform and --project # if --report-type is 'test-case-coverage' - if report_type == 'test-case-coverage': + # if report_type == 'test-case-coverage': + if report_type in ('test-case-coverage', 'milestones'): if not project: print("--project is required for the report selected") if not platform: @@ -63,7 +64,7 @@ def validate_project(platform, project, report_type): def main(): args = parse_args(sys.argv[1:]) validate_project(args.platform, args.project, args.report_type) - + if args.report_type == 'test-case-coverage': h = TestRailClient() h.data_pump(args.project.lower()) @@ -74,10 +75,15 @@ def main(): else: num_days = '' h.testrail_run_counts_update(args.project, num_days) + if args.report_type == 'milestones': + h = TestRailClient() + h.test_rail_milestones('59') + ''' if args.report_type == 'issue-regression': h = GithubClient() h.github_issue_regression(args.project) h = GithubClient() + if args.report_type == 'jira-qa-requests': h = JiraClient() h.jira_qa_requests() @@ -87,7 +93,7 @@ def main(): if args.report_type == 'bugzilla-qe-verify': h = BugzillaClient() h.bugzilla_qe_verify() - + ''' if __name__ == '__main__': main() diff --git a/lib/testrail_conn.py b/lib/testrail_conn.py index a0205f7..fee250a 100644 --- a/lib/testrail_conn.py +++ b/lib/testrail_conn.py @@ -84,6 +84,7 @@ def __send_request(self, method, uri, data): while True: response = requests.get(f"{url}&limit={limit}&offset={offset}", headers=headers) data = response.json() + print(data) # Check if 'cases' key exists in the response if 'cases' in data: @@ -92,6 +93,12 @@ def __send_request(self, method, uri, data): # Break if fewer items are returned than the limit, indicating the last page if len(data['cases']) < limit: break + if 'milestones' in data: + all_items.extend(data['milestones']) + + # Break if fewer items are returned than the limit, indicating the last page + if len(data['milestones']) < limit: + break else: all_items = data break # If 'cases' key is not present, exit the loop diff --git a/testrail.py b/testrail.py index d4b8b96..7cdce3c 100644 --- a/testrail.py +++ b/testrail.py @@ -4,6 +4,7 @@ import pandas as pd from lib.testrail_conn import APIClient +''' from database import ( Database, Projects, @@ -11,7 +12,7 @@ ReportTestCaseCoverage, # ReportTestRunCounts ) - +''' from utils.datetime_utils import DatetimeUtils as dt @@ -21,12 +22,17 @@ def __init__(self): try: TESTRAIL_HOST = os.environ['TESTRAIL_HOST'] self.client = APIClient(TESTRAIL_HOST) - self.client.user = os.environ['TESTRAIL_USERNAME'] + self.client.user = os.environ['TESTRAIL_USERNAME'] self.client.password = os.environ['TESTRAIL_PASSWORD'] except KeyError: print("ERROR: Missing testrail env var") sys.exit(1) + # API: Milestones + # https://mozilla.testrail.io/index.php?/api/v2/get_milestones/59 + def milestones(self, project_id): + return self.client.send_get('get_milestones/{0}'.format(project_id)) + # API: Projects def projects(self): return self.client.send_get('get_projects') @@ -81,8 +87,8 @@ class TestRailClient(TestRail): def __init__(self): super().__init__() - self.db = DatabaseTestRail() - + #self.db = DatabaseTestRail() + ''' def data_pump(self, project='all', suite='all'): # call database for 'all' values # convert inputs to a list so we can easily @@ -157,7 +163,7 @@ def testrail_coverage_update(self, projects_id, # Insert data in 'totals' array into DB self.db.report_test_coverage_insert(projects_id, payload) - + def testrail_run_counts_update(self, project, num_days): start_date = dt.start_date(num_days) @@ -181,7 +187,30 @@ def testrail_run_counts_update(self, project, num_days): # Insert data in 'totals' array into DB self.db.report_test_runs_insert(projects_id, totals) - +''' + def test_rail_milestones(self, project_id): + payload = self.milestones('59') + + df = pd.json_normalize(payload) + + selected_columns = { + "id": "id", + "project_id": "project_id", + "name": "name", + "started_on": "started_on", + "is_completed": "is_completed", + "description": "description", + "completed_on": "completed_on", + "url": "url" + } + # Select specific columns + df_selected = df[selected_columns.keys()] + df_selected['started_on'] = df_selected['started_on'].apply(dt.convert_epoch_to_datetime) # noqa + + df_selected.to_csv('output.csv', index=False) + print(df_selected) + +''' class DatabaseTestRail(Database): def __init__(self): @@ -294,7 +323,7 @@ def report_test_runs_insert(self, project_id, payload): if t['testrail_completed_on']: created_on = dt.convert_epoch_to_datetime(t['testrail_created_on']) # noqa completed_on = dt.convert_epoch_to_datetime(t['testrail_completed_on']) # noqa - ''' + report = ReportTestRunCounts( projects_id=project_id, testrail_run_id=t['testrail_run_id'], @@ -304,6 +333,8 @@ def report_test_runs_insert(self, project_id, payload): test_case_blocked_count=t['blocked_count'], testrail_created_on=created_on, testrail_completed_on=completed_on) - ''' + + # self.session.add(report) self.session.commit() +''' \ No newline at end of file diff --git a/utils/constants.py b/utils/constants.py index 1e8e285..db8f4c2 100644 --- a/utils/constants.py +++ b/utils/constants.py @@ -22,7 +22,8 @@ 'issue-regression', 'jira-qa-requests', 'jira-qa-needed', - 'bugzilla-qe-verify' + 'bugzilla-qe-verify', + 'milestones' ] # JQL query All QA Requests since 2022 filter_id: 13856