def print_runs_by_query(self, query, is_template=False): query_ful = 'project.id:%s AND %s' % (TestRun.default_project, query) fields = [ 'query', 'created', 'test_run_id', 'select_test_cases_by', 'status', 'plannedin', 'assignee', 'author' ] st = TestRun.search(query_ful, fields, 'created', -1, is_template) Object = '' if is_template: Object = 'Template' prestr = 'Created Time %8sAuthor %3sAssignee' % ('', '') latstr = '%sStatus %3sPlanID%10s%s' % ('', '', '', Object) preln = '------------%9s------%4s------' % ('', '') latln = '%2s--------%2s-------%9s--------' % ('', '', '') print('%s %s' % (prestr, latstr)) print('%s %s' % (preln, latln)) for tp in st: created_time = str(tp.created).split('.')[0] print('%-20s %-9s %-8s %-10s%-15s %s' % (created_time, tp.author, tp.assignee, tp.status, tp.plannedin, tp.test_run_id))
def get_template(self, temp_id): """ Gets a TestRun template :param temp_id: :return: """ from pylarion.test_run import TestRun for x in ["-", "."]: if x in temp_id: temp_id = temp_id.replace(x, "\{}".format(x)) t_runs = TestRun.search('"{}"'.format(temp_id), fields=["test_run_id", "created", "is_template"], sort="created", search_templates=True) from pylarion.exceptions import PylarionLibException tr = None for t in t_runs: tr = TestRun(uri=t.uri) try: if tr.plannedin is not None: break except PylarionLibException: pass else: raise Exception("Could not find template") return tr
def collect(): args = parse() trs = TestRun.search("project.id:{0} AND status:notrun AND isautomated:true".format(args.project_id)) jenkins_url = 'http://{}:{}'.format(args.jenkins, args.jenkins_port) jenkins_obj = jenkins.Jenkins(jenkins_url, username=args.jenkins_user, password=args.jenkins_pass) for tr in trs: jenkins_obj.build_job('PolarionTest', {'PROJECT_ID': args.project_id, 'RUN_ID': tr.test_run_id})
def test_010_search_with_custom_fields(self): """This test does the following: * Gets a TestRun * Searches using the same query as the testrun (adding project id) * and with custom_field 'plannedin' * verifies that the 'plannedin' field of the returnd TestRun is None * The purpose here is to check that it doesnt throws exception """ query = "id:%s" % (TEST_RUN_ID) lst_tr = TestRun.search(query, ["plannedin"]) self.assertEqual(lst_tr[0].plannedin, None) lst_tr[0].plannedin = self.NEW_PLAN lst_tr[0].update() lst_tr = TestRun.search(query, ["plannedin"]) self.assertEqual(lst_tr[0].plannedin, self.NEW_PLAN) lst_tr[0].plannedin = None lst_tr[0].update()
def test_012_search_with_URI_fields(self): """This test does the following: * Gets a TestRun * Searches using the same query as the testrun (adding project id) * Verify that 'author' is instantiated """ query = "id:%s" % (TEST_RUN_ID) lst_tr = TestRun.search(query, fields=["author"]) self.assertIsNotNone(lst_tr[0].author)
def update_run(self, run, template=None, plannedin=None, assignee=None, status=None, description=None, is_template=False): run = run.strip() query_ful = 'project.id:%s AND id:%s' % (TestRun.default_project, run) fields = [ 'query', 'created', 'test_run_id', 'select_test_cases_by', 'status', 'plannedin', 'assignee', 'author' ] st = TestRun.search(query_ful, fields, 'created', -1, is_template) # Update run if exists, otherwise create it. if st: print('Update the existing run: %s' % run) tr = TestRun(run, None, TestRun.default_project) # set fields if assignee != 'None': tr.assignee = assignee print('%4sSet Assignee to %s' % ('', assignee)) if plannedin is not None: tr.plannedin = plannedin print('%4sSet Plannedin to %s' % ('', plannedin)) if status is not None: tr.status = status print('%4sSet Status to %s' % ('', status)) if description is not None: tr.description = description print('%4sSet Description to %s' % ('', description)) tr.update() else: tr = TestRun.create(TestRun.default_project, run, template, assignee=assignee, plannedin=plannedin, status=status, description=description) # display fields if assignee != 'None': print('%4sSet Assignee to %s' % ('', assignee)) if plannedin is not None: print('%4sSet Plannedin to %s' % ('', plannedin)) if status is not None: print('%4sSet Status to %s' % ('', status)) if description is not None: print('%4sSet Description to %s' % ('', description)) print('Created %s:' % run)
def check_for_spare_test_runs_in_excel(): print("Test run in excel but not in Polarion already: ") test_run_ids = [""] print(test_run_ids.__len__()) for id in test_run_ids: test_run = TestRun.search(id) if not test_run.__len__(): print(id)
def test_004_search(self): """This test does the following: * Gets a TestRun * Searches using the same query as the testrun (adding project id) * verifies that there are number of records returned as are in the records attribute of the TestRun """ query = "id:%s" % (TEST_RUN_ID) lst_tr = TestRun.search(query) self.assertEqual(lst_tr[0].test_run_id, TEST_RUN_ID)
def collect(): args = parse() trs = TestRun.search( "project.id:{0} AND status:notrun AND isautomated:true".format( args.project_id)) jenkins_url = 'http://{}:{}'.format(args.jenkins, args.jenkins_port) jenkins_obj = jenkins.Jenkins(jenkins_url, username=args.jenkins_user, password=args.jenkins_pass) for tr in trs: jenkins_obj.build_job('PolarionTest', { 'PROJECT_ID': args.project_id, 'RUN_ID': tr.test_run_id })
def get_test_run(test_run_id): """ Looks for matching TestRun given a test_run_id string :param test_run_id: :return: """ from pylarion.test_run import TestRun tr = TestRun.search('"{}"'.format(test_run_id), fields=[u"test_run_id"], sort="created") tr = itz.first(tr) if tr: tr = TestRun(uri=tr.uri) return tr
def update_run(self, run, template=None, plannedin=None, assignee=None, is_template=False): qrun = run.replace('-', '\-') query_ful = 'project.id:%s AND id:%s' % (TestRun.default_project, qrun.strip()) fields = ['query', 'created', 'test_run_id', 'select_test_cases_by', 'status', 'plannedin', 'assignee', 'author'] st = TestRun.search(query_ful, fields, 'created', -1, is_template) # Update run if exists, otherwise create it. if st: print 'Update the existing run: %s' % run tr = TestRun(run.strip(), None, TestRun.default_project) else: tr = TestRun.create(TestRun.default_project, run.strip(), template) print '\nCreated %s:' % run # set customer filed of plannedin if plannedin: tr.plannedin = plannedin print '%4sSet Plannedin to %s' % ('', plannedin) if assignee == 'None': tr.assignee = TestRun.logged_in_user_id else: tr.assignee = assignee print '%4sSet Assignee to %s' % ('', tr.assignee) tr.update()
def get_latest_test_run(test_run_name): """ Gets the most recent TestRun based on the test_run_name NOTE: the test_run_name should be the name of a test run without the integer. For example, if your TestRun id is normally "Jenkins Run 1", then test_run_name should be "Jenkins Run". :param test_run_name: test run id string :return: TestRun """ from pylarion.test_run import TestRun s = TestRun.search('"{}"'.format(test_run_name), fields=["test_run_id", "created", "status"], sort="created") current = None if s: latest = itz.last(s) current = TestRun(uri=latest.uri) return current
def print_runs_by_query(self, query, is_template=False): query_ful = 'project.id:%s AND %s' % (TestRun.default_project, query) fields = ['query', 'created', 'test_run_id', 'select_test_cases_by', 'status', 'plannedin', 'assignee', 'author'] st = TestRun.search(query_ful, fields, 'created', -1, is_template) Object = '' if is_template: Object = 'Template' prestr = 'Created Time %8sAuthor %3sAssignee' % ('', '') latstr = '%sStatus %3sPlanID%10s%s' % ('', '', '', Object) preln = '------------%9s------%4s------' % ('', '') latln = '%2s--------%2s-------%9s--------' % ('', '', '') print '%s %s' % (prestr, latstr) print '%s %s' % (preln, latln) for tp in st: created_time = str(tp.created).split('.')[0] print '%-20s %-9s %-8s %-10s%-15s %s' % (created_time, tp.author, tp.assignee, tp.status, tp.plannedin, tp.test_run_id)
def main(): isUpdateAutomationValue = False # access excel file and update results credentials = get_credentials() http = credentials.authorize(httplib2.Http()) discoveryUrl = ('https://sheets.googleapis.com/$discovery/rest?version=v4') service = discovery.build('sheets', 'v4', http=http, discoveryServiceUrl=discoveryUrl) # https://docs.google.com/spreadsheets/d/1y4eBJhcZ0HsB5JUH5MPcFXWtc2zbP9XbgdCIF0S4iHs/edit#gid=1503195790 spreadsheetId = '1y4eBJhcZ0HsB5JUH5MPcFXWtc2zbP9XbgdCIF0S4iHs' # Get all test runs by Polarion query, extract test run id and test run results (pass, fail, pending block, total...) test_runs_uris = TestRun.search( 'NOT status:invalid AND plannedin.KEY:RHOS16' ) #updated:[20190627 TO 20190630]') # # test_runs_uris = TestRun.search('20180625-0836') print("Number of items %s" % len(test_runs_uris)) loop_counter = 1 missing_test_run_in_excel = '' non_test_cases_item = 0 for test_run_uri in test_runs_uris: # for i in range(106,130): # test_run_uri = test_runs_uris[i] #get excel values rangeName = 'RHOS 16!A2:X' result = service.spreadsheets().values().get( spreadsheetId=spreadsheetId, range=rangeName).execute() values = result.get('values', []) value_input_option = 'RAW' print('Updating test run number: ' + str(loop_counter)) loop_counter += 1 print(test_run_uri.uri) test_run = TestRun(uri=test_run_uri.uri) test_run_id = test_run.test_run_id print('Test run title: ' + test_run.title) print('Test run ID: ' + test_run.test_run_id) records = test_run.records pass_counter = 0 fail_counter = 0 pending_counter = 0 automation_counter = 0.0 critical_counter = 0 critical_auto_counter = 0 #automation_percentage = 0 blocked_counter = 0 total_counter = 0 #Collect inforamtion about test runs, how many test pass if test_run.TestRunType == 'Acceptance': for record in records: if record.result == 'passed': pass_counter += 1 elif record.result == 'failed': fail_counter += 1 elif record.result == 'blocked': blocked_counter += 1 else: pending_counter += 1 else: for record in records: # print record.result #check if test is automated test = TestCase.query(record.test_case_id) # print('Test case ID: ' + record.test_case_id) # Check if the object type is a testcase and not a header for example! if test and not Requirement.query(record.test_case_id): #calculate critical automated and rest automated if isUpdateAutomationValue: if test[0].caseautomation.lower() == 'automated': automation_counter += 1 if test[0].caseimportance.lower() == 'critical': critical_auto_counter += 1 #count number of critical cases if test[0].caseimportance.lower() == 'critical': critical_counter += 1 if record.result == 'passed': pass_counter += 1 elif record.result == 'failed': fail_counter += 1 elif record.result == 'blocked': blocked_counter += 1 else: pending_counter += 1 else: non_test_cases_item += 1 total_counter = pass_counter + fail_counter + blocked_counter + pending_counter # if total_counter > 0: # automation_percentage = int(float(automation_counter)/float(total_counter)) #*100 print('Total pass:'******'Total fail:', fail_counter) print('Total blocked:', blocked_counter) print('Total pending:', pending_counter) print('Total automated:', automation_counter) print('Number of critical:', critical_counter) print('Number of critical auto:', critical_auto_counter) #print ('Automation percentage:', automation_percentage) print('Total number of test cases:', total_counter) #column number in excel file and thier representation as hard coded value row_counter = 1 # offset due to headers title_column_number = 2 total_column_number = 8 pass_column_number = 9 fail_column_number = 10 blocked_column_number = 11 test_run_id_column_number = 20 automation_percentage_column_number = 18 critical_test_number = 22 is_test_run_exist_in_excel = None if not values: print('No data found.') else: for row in values: is_test_run_exist_in_excel = False row_counter += 1 # print(row_counter) # if(row_counter==134): # print('stop') # Check that row contains test run id in cell R AND check that test_run_id is match if row.__len__() >= test_run_id_column_number and row[ test_run_id_column_number] == test_run_id: print('Row number is: ' + str(row_counter)) is_test_run_exist_in_excel = True # print('%s, %s, %s, %s, %s, %s, %s :' % (row[title_column_number], row[total_column_number], row[pass_column_number], row[fail_column_number], row[blocked_column_number],row[automation_percentage_column_number], row[critical_test_number])) values = [[ total_counter, total_counter, pass_counter, fail_counter, blocked_counter ]] body = {'values': values} rangeName = 'RHOS 15!H' + str(row_counter) + ':L' + str( row_counter) result = service.spreadsheets().values().update( spreadsheetId=spreadsheetId, range=rangeName, valueInputOption=value_input_option, body=body).execute() # # update automation percentage field # values = [ # [automation_percentage] # ] # body = { # 'values': values # } # rangeName = 'RHOS 13!S' + str(row_counter) # result = service.spreadsheets().values().update(spreadsheetId=spreadsheetId, range=rangeName, valueInputOption='USER_ENTERED',body=body).execute() # update PQI values... if isUpdateAutomationValue and test_run.TestRunType != 'Acceptance': values = [[ automation_counter, critical_counter, critical_auto_counter ]] body = {'values': values} rangeName = 'RHOS 15!V' + str( row_counter) + ':X' + str(row_counter) result = service.spreadsheets().values().update( spreadsheetId=spreadsheetId, range=rangeName, valueInputOption=value_input_option, body=body).execute() # done with update, move to next test run break #Check if test run exist in excel file and was updated if not is_test_run_exist_in_excel: missing_test_run_in_excel += test_run_id + ", " print("Missing Test Runs in Excel: " + missing_test_run_in_excel) print("Number of headers or requirements in test runs: ", non_test_cases_item)