Пример #1
0
def getTestLogTimelineEvents_ajax(request, pid):
    """Create json-formatted arrays for the testlog timeline events"""
    
    planned_exec = Planned_Exec.objects.get(id=pid)
    testlogs = TestLog.objects.filter(testplan=planned_exec)
    
    # Create the dictionary for the timeline
    timelineDict = dict()
    
    timelineDict['date-time-format'] = "Gregorian"
    timelineDict['events'] = []
    
    # Test log events
    for test in testlogs:
        event = {}
        event['durationEvent'] = False
        
        if not test.passed:
            event['title'] = "Fail"
            event['icon'] = "/static/site/timeline_2.3.1/src/webapp/api/images/dark-red-circle.png"
            event['classname'] = "timeline_failure"        
        else:
            event['title'] = "Pass"
            event['icon'] = "/static/site/timeline_2.3.1/src/webapp/api/images/dark-green-circle.png"
            
        # Add the build to the title if there is one specified
        if test.build:
            event['title']+= " ("+test.build+")"
            
        event['start'] =  test.test_starttime.strftime("%a %b %d %Y %H:%M:%S GMT-0000")

        # Dialog Box information
        event['description'] = "Verifications: %s Verify Failures: %s<br />" % (test.verify_pass, test.verify_fail)
        event['description']+= "Ensurances: %s Ensure Failures: %s<br />" %  (test.ensure_pass, test.ensure_fail)
        event['description']+= "Validations: %s Validate Failures: %s<br />" % (test.validate_pass, test.validate_fail)
        event['description']+= "System Errors: %s<br />" % test.sys_error
        if test.exception_json is not None and test.exception_json != "null":
            excpt = json.loads(test.exception_json)
            event['description']+= "Exception: <br /><pre>%s: %s in %s</pre><br />line %s of %s<br />" % (excpt['etype'], excpt['etext'], excpt['caller'], excpt['line'], excpt['file'])
        
        reqList = test.failed_reqs.rsplit(",")
        reqListGroomedList = list(set([i.upper().strip() for i in reqList]))
        reqListGroomedList.sort()
        event['description']+= "Failed Reqs: %s<br />" % ", ".join(reqListGroomedList) or "None"
        event['description']+= "Run time (sec): %s<br />" % test.test_runtime
        event['description']+= "Tester: %s<br />" % convert_gnumber(test.test_engineer)
        event['description']+= "Test Station: %s <br />" % test.test_station
        
        timelineDict['events'].append(event)
        
    # Duration events (Sprints), correspond to project phases
    sprints = ProjectSchedule.objects.filter(project=planned_exec.release.project)
    
    for sprint in sprints:
        event = {}
        event['title'] = sprint.name
        event['start'] =  sprint.start_date.strftime("%a %b %d %Y %H:%M:%S GMT-0000")
        event['end'] = sprint.end_date.strftime("%a %b %d %Y %H:%M:%S GMT-0000")
        event['description'] = sprint.name
        event['durationEvent'] = True
        timelineDict['events'].append(event)
        
    return HttpResponse(JSONEncoder().encode(timelineDict), mimetype='application/json; charset=utf8')    
Пример #2
0
def updateCaseDetail_ajax(request):
    """
    Given a field that has been changed for a case option via ajax, set it and return status.
    """
    respDict = {'error':False}
    cid = request.POST.get('cid')

    try:
        thisCase = Case.objects.get(id=cid)
    except:
        respDict['error'] = True
        return HttpResponse("Error setting parameter", status=500)

    # Get the id of the field that was changed (only one can be changed at a time
    field_id = request.POST.get('id')
    value = request.POST.get('value')

    # Get the (*) part of id_* from the edited field
    field_name = field_id.split('id_')[1]

    if str(field_name) == "auto_state":
        if value != thisCase.auto_state:
            thisCase.auto_state = value
            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[16][0], 
                                       case_name=thisCase.name, 
                                       auto_state=thisCase.get_auto_state_display())

        return HttpResponse(thisCase.get_auto_state_display())
    
    elif str(field_name) == "prebaselined":
        
        true = True
        false = False
        options = {true: 'True', false: 'False'}
        old_state = request.POST.get('state', None)
        msg = options[eval(value)]
        respDict['pb'] = options[thisCase.prebaselined]
        respDict['state'] = old_state
        respDict['msg'] = ''
    
        try:
            old = eval(value)
            if old != thisCase.prebaselined:
                thisCase.prebaselined = old
                thisCase.save()
                respDict['pb'] = options[old]
                respDict['state'] = Case.objects.get(id=cid).get_auto_state_display()
            
        except Exception as e:
            respDict['msg'] = "Failure: %s" % e.args[0]
            respDict['error'] = True
    
        return JSONHttpResponse(respDict)        
        
        
    elif str(field_name) == "exec_type":
        if value != thisCase.exec_type:
            thisCase.exec_type = value
            
            if setupFlagIfAllRequiredParamsAreSet(thisCase):
                thisCase.setup = True

            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[15][0], 
                                       case_name=thisCase.name, 
                                       exec_type=thisCase.get_exec_type_display())            
            
        return HttpResponse(thisCase.get_exec_type_display())

    elif str(field_name) == "comm_connect_type":
        if value != thisCase.comm_connect_type:
            thisCase.comm_connect_type = value
            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[22][0], 
                                       case_name=thisCase.name, 
                                       comm_connect_type=thisCase.get_comm_connect_type_display())

        return HttpResponse(thisCase.get_comm_connect_type_display())
    
    elif str(field_name) == "comm_mode":
        if value != thisCase.comm_mode:
            thisCase.comm_mode = value
            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[30][0], 
                                       case_name=thisCase.name, 
                                       comm_mode=thisCase.get_comm_mode_display())

        return HttpResponse(thisCase.get_comm_mode_display())    

    elif str(field_name) == "pg_type":
        if value != thisCase.pg_type:
            thisCase.pg_type = value
            if setupFlagIfAllRequiredParamsAreSet(thisCase):
                thisCase.setup = True            

            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[12][0], 
                                       case_name=thisCase.name, 
                                       pg_type=thisCase.get_pg_type_display())
            
            # If there are command line options for any already existing planned
            # executions, make sure to update those as well
            pes = Planned_Exec.objects.filter(case=thisCase)
            if pes.exists():
                for pe in pes:
                    cla = CommandLineArgs.objects.filter(planned_exec=pe)
                    if cla.exists():
                        for c in cla:
                            if thisCase.pg_type == "SI":
                                c.komodo_pgsim = True
                            else:
                                c.komodo_pgsim = False
                            c.save()
                                                         

        return HttpResponse(thisCase.get_pg_type_display())

    elif str(field_name) == "sensor_type":
        if value != thisCase.sensor_type:
            thisCase.sensor_type = value
            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[13][0], 
                                       case_name=thisCase.name, 
                                       sensor_type=thisCase.get_sensor_type_display())
        return HttpResponse(thisCase.get_sensor_type_display())

    elif str(field_name) == "usbrelay_type":
        if value != thisCase.usbrelay_type:
            thisCase.usbrelay_type = value
            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[28][0], ################
                                       case_name=thisCase.name, 
                                       usbrelay_type=thisCase.get_usbrelay_type_display())
        return HttpResponse(thisCase.get_usbrelay_type_display())

    elif str(field_name) == "comm_cellular_type":
        if value != thisCase.comm_cellular_type:
            thisCase.comm_cellular_type = value
            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[29][0], ###################
                                       case_name=thisCase.name, 
                                       comm_cellular_type=thisCase.get_comm_cellular_type_display())
        return HttpResponse(thisCase.get_comm_cellular_type_display())

    elif str(field_name) == "centricity":
        if value != thisCase.centricity:
            thisCase.centricity = value
            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[21][0], 
                                       case_name=thisCase.name, 
                                       centricity=thisCase.get_centricity_display())
        return HttpResponse(thisCase.get_centricity_display())

    elif str(field_name) == "env_type":
        if value != thisCase.env_type:
            thisCase.env_type = value
            if setupFlagIfAllRequiredParamsAreSet(thisCase):
                thisCase.setup = True                

            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[14][0], 
                                       case_name=thisCase.name, 
                                       env_type=thisCase.get_env_type_display())
        return HttpResponse(thisCase.get_env_type_display())
    
    elif str(field_name) == "auto_owner":
        if value != thisCase.automation_owner:
            thisCase.automation_owner = value
            if setupFlagIfAllRequiredParamsAreSet(thisCase):
                thisCase.setup = True                

            thisCase.save()
            utils_protocol.logProtocol(request.user,
                                       thisCase.protocol,
                                       LOG_MSG_TYPES[24][0], 
                                       case_name=thisCase.name, 
                                       auto_owner=thisCase.automation_owner)
        return HttpResponse(convert_gnumber(thisCase.automation_owner))

    # For boolean fields, Use the id_(***) portion of the field id to update the 
    # case value instead of accessing the member directly
    else:
        currentValue = str(thisCase.__dict__[field_name])

        # Don't hit the database or log this change if the values are the same
        if value != currentValue:
            thisCase.__dict__[field_name] = {'True':1,'False':0}[value]
            thisCase.save()

            # Log the change to the protocol activity log
            if str(field_name) == "prm":
                utils_protocol.logProtocol(request.user,
                                           thisCase.protocol,
                                           LOG_MSG_TYPES[9][0], 
                                           case_name=thisCase.name, 
                                           prm=boolean_convert(value))

            elif str(field_name) == "machsim":
                utils_protocol.logProtocol(request.user,
                                           thisCase.protocol,
                                           LOG_MSG_TYPES[10][0], 
                                           case_name=thisCase.name, 
                                           machsim=boolean_convert(value))

            elif str(field_name) == "shield_box":
                utils_protocol.logProtocol(request.user,
                                           thisCase.protocol,
                                           LOG_MSG_TYPES[11][0], 
                                           case_name=thisCase.name, 
                                           shield_box=boolean_convert(value))

            elif str(field_name) == "svmachsim":
                utils_protocol.logProtocol(request.user,
                                           thisCase.protocol,
                                           LOG_MSG_TYPES[17][0], 
                                           case_name=thisCase.name, 
                                           svmachsim=boolean_convert(value))

            elif str(field_name) == "teltone":
                utils_protocol.logProtocol(request.user,
                                           thisCase.protocol,
                                           LOG_MSG_TYPES[18][0], 
                                           case_name=thisCase.name, 
                                           teltone=boolean_convert(value))

            elif str(field_name) == "telephone":
                utils_protocol.logProtocol(request.user,
                                           thisCase.protocol,
                                           LOG_MSG_TYPES[19][0], 
                                           case_name=thisCase.name, 
                                           telephone=boolean_convert(value))

        return HttpResponse(boolean_convert(thisCase.__dict__[field_name]))