Beispiel #1
0
 def handle(info=None,path=None):
     #load test setting
     _isUpload = TestBuilder.getBuilder().isUploadResult()
     _isLocal = TestBuilder.getBuilder().isLocalResult()
     if info:
         _sortTestCaseResult(info)
     if _isUpload:
         ResultSender.getInstance().addTask(info,path) 
     if _isLocal:
         pass
Beispiel #2
0
 def __init__(self,options=None):
     '''
     init looger,builder,and DeviceManager before testing start
     '''
     self.logger = Logger.getLogger()
     self.builder = TestBuilder.getBuilder(options)
     self.runner = TestRunner.getRunner(self.builder)
Beispiel #3
0
def _sortTestCaseResult(info):
    '''Sort test case result from "all" folder.
    Keyword arguments:
    info -- tuple of test case object description.(should not be none)
     '''
    logger=Logger.getLogger()
    #logger.debug('copy failures result to fail or error folder')
    #logger.debug('name:'+info[1][1]._testMethodName+' time:'+info[1][1].starttime)
    if not info[0] in ['addFailure','addError']:
        return 
    case_name = '%s.%s' %(type( info[1][1]).__name__,  info[1][1]._testMethodName)
    case_starttime = info[1][1].starttime
    testcase_result_folder = '%s-%s'%(case_name,case_starttime)
    result_path = os.path.join(TestBuilder.getBuilder().getWorkspace(),'result-%s'%TestBuilder.getBuilder().getStartTime())
    src =  os.path.join(os.path.join(result_path,'all'),testcase_result_folder)
    if info[0] == 'addFailure':
        #logger.debug('distribute add failed')
        dest = os.path.join(os.path.join(result_path,'fail',testcase_result_folder))
    elif info[0] == 'addError':
        #logger.debug('distribute add error:')
        dest = os.path.join(os.path.join(result_path,'error',testcase_result_folder))
    if (src is not None and dest is not None):
        _copyFilesToOtherFolder(src, dest)
        _saveLog(dest)
Beispiel #4
0
    def parseMessage(msg_type=None,
                     session_id=None,
                     caseresult_id=None,
                     test_info=None,
                     file_path=None):
        logger = Logger.getLogger()
        if msg_type == 'sessiondata':
            logger.debug(
                '********************session request***********************')
            url = SendUtils._session_create_url % session_id
            sessionStarttime = TestBuilder.getBuilder().getStartTime()
            deviceId = DeviceManager.getInstance().getDevice().getDeviceId()
            properties = DeviceManager.getInstance().getDevice().getDeviceInfo(
            )
            logger.debug(
                '********************session starttime*********************' +
                sessionStarttime)
            postData = {
                'planname': 'plan',
                'starttime': sessionStarttime,
                'deviceid': deviceId,
                'deviceinfo': properties
            }
            contentType = 'application/json'
            method = 'POST'
            return {
                'url': url,
                'data': postData,
                'content_type': contentType,
                'method': method
            }
        if msg_type == 'caseresult':
            logger.debug(
                '********************case result*********************')
            sid = session_id
            tid = caseresult_id
            info = test_info
            path = file_path
            if info:
                if info[0] == 'startTest':
                    logger.debug(
                        '********************start test*********************')
                    url = (SendUtils._caseresult_create_url) % (sid, tid)
                    caseName = info[1][1]._testMethodName
                    startTime = time.strftime('%Y-%m-%d %H:%M:%S  ',
                                              time.localtime(time.time()))
                    postData = {'casename': caseName, 'starttime': startTime}
                    contentType = 'application/json'
                    method = 'POST'
                    return [{
                        'url': url,
                        'data': postData,
                        'content_type': contentType,
                        'method': method
                    }]
                elif info[0] == 'addSuccess':
                    logger.debug(
                        '********************add success***********************'
                    )
                    url = (SendUtils._caseresult_update_url) % (sid, tid)
                    _time = time.strftime('%Y-%m-%d %H:%M:%S  ',
                                          time.localtime(time.time()))
                    postData = {'result': 'pass', 'time': _time}
                    contentType = 'application/json'
                    method = 'POST'
                    return [{
                        'url': url,
                        'data': postData,
                        'content_type': contentType,
                        'method': method
                    }]
                elif info[0] == 'addFailure':
                    logger.debug(
                        '********************add failure***********************'
                    )
                    resultUrl = (SendUtils._caseresult_update_url) % (sid, tid)
                    resultTime = time.strftime('%Y-%m-%d %H:%M:%S  ',
                                               time.localtime(time.time()))
                    resultPostData = {'result': 'fail', 'time': resultTime}
                    resultContentType = 'application/json'
                    resultMethod = 'POST'
                    resultRequest = {
                        'url': resultUrl,
                        'data': resultPostData,
                        'content_type': resultContentType,
                        'method': resultMethod
                    }
                    #log file
                    logUrl = (SendUtils._upload_file_url) % (sid, tid)
                    logfolder = os.path.join(
                        info[1][1].worker.store.getFailDir(), 'log')
                    zipName = '%s_%s.%s' % (sid, tid, 'zip')
                    zipFolder(logfolder, zipName)
                    logPostData = _openFile(zipName)
                    logContentType = 'application/zip'
                    logMethod = 'PUT'
                    fileRequest = {
                        'url': logUrl,
                        'data': logPostData,
                        'content_type': logContentType,
                        'method': logMethod
                    }
                    return [resultRequest, fileRequest]

                elif info[0] == 'addError':
                    logger.debug(
                        '********************add error***********************')
                    resultUrl = (SendUtils._caseresult_update_url) % (sid, tid)
                    resultTime = time.strftime('%Y-%m-%d %H:%M:%S  ',
                                               time.localtime(time.time()))
                    resultPostData = {'result': 'error', 'time': resulTime}
                    resultContentType = 'application/json'
                    resultMethod = 'POST'
                    resultRequest = {
                        'url': resultUrl,
                        'data': resultPostData,
                        'content_type': resultContentType,
                        'method': resultMethod
                    }
                    #log file
                    #logUrl = (SendUtils._upload_file_url) % (sid,tid)
                    #logfolder = os.path.join(info[1][1].device.workspace_result_fail,'log')
                    #zipName = '%s_%s.%s'%(sid,tid,'zip')
                    #zipFolder(logfolder,_zipname)
                    #logPostData = _openFile(_zipname)
                    #logContentType = 'application/zip'
                    #logMethod = 'PUT'
                    #fileRequest = {'url':logUrl,'data':logPostData,'content_type':logContentType,'method':logMethod}
                    return [resultRequest]
            elif file_path:
                logger.debug(
                    '********************upload snapshot***********************'
                )
                sid = session_id
                tid = caseresult_id
                url = (SendUtils._upload_file_url) % (sid, tid)
                postData = _openFile(file_path)
                contentType = 'image/png'
                method = 'PUT'
                return [{
                    'url': url,
                    'data': postData,
                    'content_type': contentType,
                    'method': method
                }]
Beispiel #5
0
 def setUp(self):
     super(TestCaseBase, self).setUp()
     self.tid = str(uuid.uuid1()) 
     self.starttime = time.strftime('%Y.%m.%d-%H.%M.%S', time.localtime(time.time()))
     self.worker = testWorker(TestBuilder.getBuilder(), self)
     self.logger = Logger.getLogger()
    def test_001(self):
        history = History.getInstance("testDB.sqlite")
        builder = TestBuilder(history)

        assert isinstance(builder, Builder)
        rtn = builder.build()
Beispiel #7
0
    def parseMessage(msg_type=None,session_id=None,caseresult_id=None,test_info=None,file_path=None):
        logger = Logger.getLogger()
        if msg_type == 'sessiondata':
            logger.debug('********************session request***********************')
            url = SendUtils._session_create_url % session_id
            sessionStarttime = TestBuilder.getBuilder().getStartTime()
            deviceId = DeviceManager.getInstance().getDevice().getDeviceId()
            properties = DeviceManager.getInstance().getDevice().getDeviceInfo()
            logger.debug('********************session starttime*********************'+sessionStarttime)
            postData = {'planname':'plan','starttime':sessionStarttime,'deviceid':deviceId,'deviceinfo':properties}
            contentType = 'application/json'
            method = 'POST'            
            return {'url':url,'data':postData,'content_type':contentType,'method':method}
        if msg_type == 'caseresult':
            logger.debug('********************case result*********************')
            sid = session_id
            tid = caseresult_id
            info = test_info
            path = file_path
            if info:
                if info[0] == 'startTest':
                    logger.debug('********************start test*********************')
                    url = (SendUtils._caseresult_create_url) % (sid,tid)
                    caseName = info[1][1]._testMethodName
                    startTime = time.strftime('%Y-%m-%d %H:%M:%S  ', time.localtime(time.time()))
                    postData = {'casename':caseName,'starttime':startTime}
                    contentType = 'application/json'
                    method = 'POST'            
                    return [{'url':url,'data':postData,'content_type':contentType,'method':method}]
                elif info[0] == 'addSuccess':
                    logger.debug('********************add success***********************')
                    url = (SendUtils._caseresult_update_url) % (sid,tid)
                    _time = time.strftime('%Y-%m-%d %H:%M:%S  ', time.localtime(time.time()))
                    postData = {'result':'pass','time':_time}
                    contentType = 'application/json'
                    method = 'POST'
                    return [{'url':url,'data':postData,'content_type':contentType,'method':method}]
                elif info[0] == 'addFailure':
                    logger.debug('********************add failure***********************')
                    resultUrl = (SendUtils._caseresult_update_url) % (sid,tid)
                    resultTime = time.strftime('%Y-%m-%d %H:%M:%S  ', time.localtime(time.time()))
                    resultPostData = {'result':'fail','time':resultTime}
                    resultContentType = 'application/json'
                    resultMethod = 'POST'
                    resultRequest = {'url':resultUrl,'data':resultPostData,'content_type':resultContentType,'method':resultMethod}
                    #log file
                    logUrl = (SendUtils._upload_file_url) % (sid,tid)
                    logfolder = os.path.join(info[1][1].worker.store.getFailDir(),'log')
                    zipName = '%s_%s.%s'%(sid,tid,'zip')
                    zipFolder(logfolder,zipName)
                    logPostData = _openFile(zipName)
                    logContentType = 'application/zip'
                    logMethod = 'PUT'
                    fileRequest = {'url':logUrl,'data':logPostData,'content_type':logContentType,'method':logMethod}
                    return [resultRequest,fileRequest]

                elif info[0] == 'addError':
                    logger.debug('********************add error***********************')
                    resultUrl = (SendUtils._caseresult_update_url) % (sid,tid)
                    resultTime = time.strftime('%Y-%m-%d %H:%M:%S  ', time.localtime(time.time()))
                    resultPostData = {'result':'error','time':resulTime}
                    resultContentType = 'application/json'
                    resultMethod = 'POST'
                    resultRequest = {'url':resultUrl,'data':resultPostData,'content_type':resultContentType,'method':resultMethod}
                    #log file
                    #logUrl = (SendUtils._upload_file_url) % (sid,tid)
                    #logfolder = os.path.join(info[1][1].device.workspace_result_fail,'log')
                    #zipName = '%s_%s.%s'%(sid,tid,'zip')
                    #zipFolder(logfolder,_zipname)
                    #logPostData = _openFile(_zipname)
                    #logContentType = 'application/zip'
                    #logMethod = 'PUT'
                    #fileRequest = {'url':logUrl,'data':logPostData,'content_type':logContentType,'method':logMethod}
                    return [resultRequest]
            elif file_path:
                logger.debug('********************upload snapshot***********************')
                sid = session_id
                tid = caseresult_id
                url = (SendUtils._upload_file_url) % (sid,tid)
                postData = _openFile(file_path)
                contentType = 'image/png'
                method = 'PUT'
                return [{'url':url,'data':postData,'content_type':contentType,'method':method}]