def populateFailingLogs_ajax(request): """Returns the failing tests list table of a project, listing all current failing tests""" team, release = getTeamAndReleaseIDFromSession(request.session) releaseObj = Release.objects.get(id=release) isActive = releaseObj.project.isActive() # Get all logs from active planned executions within current team/release which have failing requirements latestTestLogs = LatestTestLog.objects.select_related( #'planned_exec', 'planned_exec__case', 'planned_exec__case__test', 'planned_exec__protocol', 'planned_exec__plm', 'testlog', ).filter( planned_exec__team=team, planned_exec__release=release, planned_exec__end_date=None, testlog__passed=False ) issues = Issue.active.filter( #testlog__testplan__team=team, #testlog__testplan__release=release, end_date=None ) issueDict = defaultdict(list) [issueDict[issue.testlog_id].append(issue) for issue in issues] dataTables = {'aaData': [], 'status': False} for ltl in latestTestLogs: ptcase = cleanEOLCharacters(render_to_string('issues/view_protocol_test_case.html', {'pe': ltl.planned_exec})) plannedExec = cleanEOLCharacters(render_to_string('issues/view_planned_exec.html', {'planned_exec': ltl.planned_exec})) gnum = cleanEOLCharacters(convert_gnumber_link(ltl.planned_exec.owner)) reqs = cleanEOLCharacters(reduce_to_set(ltl.testlog.failed_reqs)) viewLog = cleanEOLCharacters(render_to_string('issues/view_log_button.html', {'testLogId': ltl.testlog_id})) issues = ltl.testlog.issue_set.all() if issueDict.has_key(ltl.testlog_id): issueLink = cleanEOLCharacters(render_to_string('issues/view_tracker_links.html', {'issues': issueDict[ltl.testlog_id], 'JIRA_URL_PREFIX': settings.JIRA_URL_PREFIX, 'RTC_URL_PREFIX': settings.RTC_URL_PREFIX})) elif isActive: issueLink = cleanEOLCharacters(render_to_string('issues/report_issues_button.html', {'testlog_id': ltl.testlog_id})) else: issueLink = "N/A" dataTables['aaData'].append([ptcase, plannedExec, gnum, reqs, ltl.testlog.test_starttime.strftime("%m/%d/%y %H:%M:%S"), issueLink, viewLog]) return JSONHttpResponse(dataTables)
def populateIssueList(request, user=None): """Returns the current issues in a project""" team, release = getTeamAndReleaseIDFromSession(request.session) latestTestLogs = LatestTestLog.objects.all().values('testlog') query = Q(testlog__testplan__team=team) & \ Q(testlog__testplan__release=release) & \ Q(testlog__in=latestTestLogs) & \ Q(end_date=None) if user: username = FortyTwoUser.objects.get(id=user).username query.add(Q(owner=username), Q.AND) issues = Issue.objects.filter(query) dataTables = {'aaData': []} for issue in issues: link = cleanEOLCharacters(render_to_string('issues/view_tracker_link.html', {'issue': issue, 'JIRA_URL_PREFIX': settings.JIRA_URL_PREFIX, 'RTC_URL_PREFIX': settings.RTC_URL_PREFIX})) viewLog = cleanEOLCharacters(render_to_string('issues/view_log_button.html', {'testLogId': issue.testlog_id})) plannedExec = cleanEOLCharacters(render_to_string('issues/view_planned_exec.html', {'planned_exec': issue.testlog.testplan})) ptcase = cleanEOLCharacters(render_to_string('issues/view_protocol_test_case.html', {'pe': issue.testlog.testplan})) if issue.expected_failure: expected = 'Yes' else: expected = 'No' dataTables['aaData'].append([convert_gnumber_link(issue.owner), link, issue.get_issue_type_display(), ptcase, plannedExec, issue.requirements, issue.testlog.build, expected, viewLog,]) return JSONHttpResponse(dataTables)
def populateTestLogTable_ajax(request,pid): """Retrieves all of the test logs for a given planned execution id as JSON objects for datatables""" try: test_logs = TestLog.objects.filter(testplan=pid) except TestLog.DoesNotExist: msg = 'No Test Logs exist for this planned execution' return HttpResponse(JSONEncoder().encode({'status': False,'message': msg}), status=500) except: msg = 'Unknown Error' return HttpResponse(JSONEncoder().encode({'status': False,'message': msg}), status=500) # Get controller information for link to controller logfile dir team, release = getTeamAndReleaseIDFromSession(request.session) try: controller = ControllerInfo.objects.get(team=team, release=release) workOrdersForPID = WorkOrder.objects.filter(testplan = pid) workOrdersDict = {w.testlog_id : w for w in workOrdersForPID if w.testlog_id} except: controller = None # dataTables plugin requires only a JSON-formatted list named "aaData" # http://www.datatables.net/examples/data_sources/ajax.html dataTables = {"aaData": []} # Loop through the logs and output what the table needs for log in test_logs: if log.exception_json is None or log.exception_json == '': exception_text = json.dumps({'etext': 'None found', 'etype': None}) elif json.loads(log.exception_json) is None: exception_text = json.dumps({'etext': 'None found', 'etype': None}) else: exception_text = log.exception_json # If this team/release uses dolphin, and this log was executed on dolphin, and the result was parsed successfully if controller and workOrdersDict.has_key(log.id) and workOrdersDict[log.id].result_test_starttime: workorderDir = os.path.join(controller.hostname, controller.loglocation, workOrdersDict[log.id].result_test_starttime.strftime("%m_%d_%Y").lstrip('0').replace('_0', '_'), workOrdersDict[log.id].workorder_id) workorderDir = r'\\' + workorderDir dolphinLogDir = cleanEOLCharacters(render_to_string('testplan/dolphin_logfolder_cell.html', {'dir':workorderDir})) else: dolphinLogDir = None dataTables['aaData'].append([{True:'Pass', False:'Fail'}[log.passed], log.build or "", log.test_version or "", log.test_starttime.strftime("%m/%d/%y %H:%M:%S"), "{0:.2f}".format(log.test_runtime/60.0), dolphinLogDir or "", convert_gnumber_link(log.test_engineer), log.test_station, log.test_system_name or "", "Verify: %s-%s<br />Ensure: %s-%s</br />Validate: %s-%s<br />SysErr: %s" % (log.verify_pass, log.verify_fail, log.ensure_pass, log.ensure_fail, log.validate_pass, log.validate_fail, log.sys_error), render_to_string('batch/exception_text_cell.html', { 'model': log, 'exception': json.loads(exception_text)}), log.id]) return HttpResponse(json.dumps(dataTables), content_type = 'application/json; charset=utf8')
def getDataTablesPLMBrowserStr(self,browser=False): """Formats the planned execution pg/comm/geography to put into a datatables <td>""" return cleanEOLCharacters(render_to_string('testplan/datatables_plm_structure.html', { 'testplan': self, 'browser': browser }))
def getDataTablesPlannedExecStructureStr(self, show_detail_link=False): """Formats the planned execution protocol/test/case to put into a dataTables <td>""" return cleanEOLCharacters(render_to_string('testplan/datatables_ptc_structure.html', { 'testplan': self, 'show_detail_link': show_detail_link }))
def getStationInfo_ajax(request): """ Retrieves the test station info from the Dolphin system and formats the data for a dataTable. Additionally, retrieves the Dolphin controller info. """ team, release = getTeamAndReleaseIDFromSession(request.session) controller = ControllerInfo.objects.get(team_id=team, release_id=release) try: tsSvc = RegressionServices.objects.get(service_type=RegressionServices.SERVICE_TYPE_TESTSTATION_INFO) except RegressionServices.MultipleObjectsReturned: tsSvc = RegressionServices.objects.get(controller=controller, service_type=RegressionServices.SERVICE_TYPE_TESTSTATION_INFO) stations = controller.getRequest(tsSvc.service_url) or [] try: mSvc = RegressionServices.objects.get(service_type=RegressionServices.SERVICE_TYPE_CONTROLLER_MODE) except RegressionServices.MultipleObjectsReturned: mSvc = RegressionServices.objects.get(controller=controller, service_type=RegressionServices.SERVICE_TYPE_CONTROLLER_MODE) mode = controller.getRequest(mSvc.service_url) or None # Begin formatting the data dataTables = {'aaData': [], 'status': False, 'controller': controller.hostname, 'controller_mode': ControllerModes.CONTROLLER_MODES_MAPPING_DICT[mode]} # Test station staus tsStatus = TestStationModes.objects.all() # Keys to mine from response data tsKeys = { 'pg': { 'type': 'Details.Hardware.PulseGenerator.Type', 'status': 'Details.Hardware.PulseGenerator.Status', 'family': 'Details.Hardware.PulseGenerator.PGFamily', 'band': 'Details.Hardware.PulseGenerator.RFBand', 'version': 'Details.Hardware.PulseGenerator.FirmwareVersion', 'model': 'Details.Hardware.PulseGenerator.ModelNumber', }, 'comm': { 'id': 'Details.Hardware.Communicator.ID', 'status': 'Details.Hardware.Communicator.Status', 'model': 'Details.Hardware.Communicator.ModelNumber', 'region': 'Details.Hardware.Communicator.Region', 'version': 'Details.Hardware.Communicator.BundleVersion' }, 'bpm': { 'status': 'Details.Hardware.BloodPressureMonitor.Status', }, 'ws': { 'status': 'Details.Hardware.WeightScale.Status' }, 'testlibs_list': { 'libs': 'Details.Software.TestLibs', }, 'testlib': { 'name': 'Name', 'version': 'Version' } } # Loop through the test stations sent by the regression system for s in stations: # only the stations in this team/release cluster if controller.cluster_name not in s['ClusterNames']: continue # PG Type/Info pgInfo = render_to_string('dolphace/pginfo.html', {'pg': safeDictLookup(tsKeys['pg'], s)}) # Communicator Info commInfo = render_to_string('dolphace/comminfo.html', {'device': safeDictLookup(tsKeys['comm'], s)}) # Sensor Info sensorInfo = render_to_string('dolphace/sensorinfo.html', {'bpm': safeDictLookup(tsKeys['bpm'], s), 'ws': safeDictLookup(tsKeys['ws'], s)}) # Test Libraries testLibs = safeDictLookup(tsKeys['testlibs_list'], s) testLibsList = [] if testLibs['libs']: for lib in testLibs['libs']: testLibsList.append(safeDictLookup(tsKeys['testlib'], lib)) versionInfo = getAgentProductInfo(s['Name'], controller) if versionInfo: version = versionInfo['Version'] else: version = "Not Found" try: theStatus = tsStatus.get(mode_num=s['Status']) if theStatus: status = theStatus.get_mode_display() else: raise Exception() except: status = "Unknown status: %s" % s['Status'] # Fill the table out dataTables['aaData'].append([ cleanEOLCharacters(render_to_string('dolphace/teststation_detail_link.html', {'ts': s, 'version': version})), cleanEOLCharacters(status), cleanEOLCharacters(commInfo), cleanEOLCharacters(pgInfo), cleanEOLCharacters(sensorInfo), cleanEOLCharacters(render_to_string('dolphace/testlibinfo.html', {'testlibs': testLibsList}))]) dataTables['status'] = True return JSONHttpResponse(dataTables)
def getWorkorderQueue_ajax(request): """ Retrieves the workorder queue from the Dolphin system and formats the data for a dataTable """ team, release = getTeamAndReleaseIDFromSession(request.session) controller = ControllerInfo.objects.get(team_id=team, release_id=release) try: qSvc = RegressionServices.objects.get(service_type=RegressionServices.SERVICE_TYPE_WORKORDER_JOBS) except RegressionServices.MultipleObjectsReturned: qSvc = RegressionServices.objects.get(controller=controller, service_type=RegressionServices.SERVICE_TYPE_WORKORDER_JOBS) queue = controller.getRequest(qSvc.service_url) or [] dataTables = {'aaData': [], 'status': False, 'msg': ''} attrs = ['testplan__case__env_type', 'testplan__case__pg_type', 'batch__name', 'batch_id', 'workorder_id', 'workorder_text', 'submission_time', 'testplan__protocol__name', 'testplan__protocol_id', 'testplan__case_id', 'testplan__case__test__name', 'testplan__case__name', 'testplan__plm__comm_model', 'testplan__plm__pg_model', 'testplan__plm__geography', 'testplan__country__name', 'testplan_id', ] wos = WorkOrder.objects.filter(workorder_id__in=queue).values(*attrs) # Loop through the workorders sent by the regression system try: for wo in wos: batch = cleanEOLCharacters(render_to_string('batch/batch_name.html', \ {'batch_name': wo['batch__name'], 'batch_id': wo['batch_id']})) ptc = cleanEOLCharacters(render_to_string('testplan/datatables_ptc_structure.html',\ {'protocol_id': wo['testplan__protocol_id'], 'protocol_name': wo['testplan__protocol__name'], 'test_name': wo['testplan__case__test__name'], 'case_id': wo['testplan__case_id'], 'case_name': wo['testplan__case__name'], 'show_detail_link': True, 'testplan_id': wo['testplan_id']})) plm = cleanEOLCharacters(render_to_string('testplan/datatables_plm_structure.html',\ {'geography': wo['testplan__plm__geography'], 'testplan_country': wo['testplan__country__name'], 'pg_model': wo['testplan__plm__pg_model'], 'comm_model': wo['testplan__plm__comm_model']})) try: woDict = ast.literal_eval(wo['workorder_text']) pgType = woDict['Hardware']['PulseGenerator']['Type'] except: pgType = EQUIP_PG_CHOICES_DICT[wo['testplan__case__pg_type']] dataTables['aaData'].append([ wo['workorder_id'], ptc, plm, Case.ENVIRONMENT_CHOICES_DICT[wo['testplan__case__env_type']], pgType, batch, wo['submission_time'].strftime('%m/%d/%Y %H:%M') ]) except Exception as e: dataTables['msg'] = "An error occurred: " + e.message return JSONHttpResponse(dataTables, status=500) dataTables['status'] = True return JSONHttpResponse(dataTables)