示例#1
0
    def RunHttpClientELong(self, url, *requests):
        u'''
        Examples:

        | @{responses}= | Run Http Client E Long |  url |  ./request1.xml   | ./request2.xml  |  ......  |
        | @{responses}= | Run Http Client E Long |  url | <root>....</root> |

        '''
        responses = []
        for request in requests:
            dlog.write(request, level='DEBUG')
            if type(request) is unicode:
                request = request.encode('utf-8')
            if Common.check_file(CONTEXT.get_path(request)):
                message = ''.join(open(CONTEXT.get_path(request), 'rb').readlines())
                message = urllib.quote(str(message))
            else:
                message = urllib.quote(str(request))
            dlog.write(message, level='DEBUG')
            h = httplib2.Http()
            resp, content = h.request(url, 'POST'
                                      , 'Message=%s' % message
                                      , headers={'content-type': 'application/x-www-form-urlencoded'})
            responses.append(content)

        return responses
示例#2
0
 def Http_MeiTuan_Request(self, url, request, key="meituanhotelopen", **headers):
     u'''
     Examples:
     | Http MeiTuan Request | http://10.200.152.6:8080/hotel | request.xml |
     '''
     if Common.check_file(CONTEXT.get_path(request)):
         message = open(CONTEXT.get_path(request), 'r').read()
     else:
         message = request
     newheards = {}
     for k, v in headers.items():
         newheards[k.encode('utf-8')] = v.encode('utf-8')
     h = httplib2.Http()
     obj = AES.new(key, AES.MODE_ECB)
     x = AES.block_size - (len(message) % AES.block_size)
     if x != 0:
         message = message + chr(x) * x
     message = obj.encrypt(message)
     body = base64.urlsafe_b64encode(message).replace('=', '')
     resp, enStr = h.request(url.encode('utf-8'), 'POST', body, headers=newheards)
     try:
         cipher = AES.new(key, AES.MODE_ECB)
         enStr += (len(enStr) % 4) * "="
         decryptByts = base64.urlsafe_b64decode(enStr)
         msg = cipher.decrypt(decryptByts)
         paddingLen = ord(msg[len(msg) - 1])
         try:
             content = (msg[0:-paddingLen]).decode('gbk')
         except Exception:
             content = (msg[0:-paddingLen])
         return content
     except Exception, e:
         return e, enStr, resp
示例#3
0
 def Http_CNBooking_Request(self, url, request, key="U+qFnPhJbiOTkX+e", iv="U+qFnPhJbiOTkX+e"):
     u'''
     Examples:
     | Http CNBooking Request | http://10.200.152.6:8080/hotel | request.xml |
     '''
     if Common.check_file(CONTEXT.get_path(request)):
         message = b''.join(open(CONTEXT.get_path(request), 'rb').read())
     else:
         message = request
     h = httplib2.Http()
     obj = AES.new(key, AES.MODE_CBC, iv)
     if len(message) % 16 != 0:
         message += chr((16 - len(message) % 16)) * (16 - len(message) % 16)
     body = obj.encrypt(message).encode('hex')
     resp, content = h.request(url, 'POST', body)
     return content
示例#4
0
    def Perf_Set_Path(self, logfile, logpath='log'):
        u'''
        Set performance log file Path

        default path: log/${appName}.perf.log

        Examples:
        perf log path is : trunk/log/${appname}.perf.log

        | Perf_Set_Path  | app/WEB_INF/classes/logback.xml |

        set path : trunk/perflog/${appname}.perf.log

        | Perf_Set_Path  | app/WEB_INF/classes/logback.xml | perflog |

        '''
        logfile = CONTEXT.get_path(logfile)
        tree = etree.parse(logfile)
        root = tree.getroot()
        els = root.findall(".//appender/file")
        for el in els:
            if str(el.text).find(".perf.log") != -1:
                el.text = "%s/%s" % (logpath, ((el.text).split('/'))[-1])
                break
        etree.ElementTree(root).write(logfile, pretty_print=True)
示例#5
0
 def Perf_Check_PaymentCard(self, logfile, *PaymentCards):
     logfile = CONTEXT.get_path(logfile)
     lines = open(logfile, 'r')
     for line in lines:
         for pc in PaymentCards:
             if pc in line:
                 dlog.fail("Perf Log Check PaymentCard Error:%s" % line)
示例#6
0
 def _deal(self, logfile):
     self.requests = []
     self.responses = []
     self.lines = []
     self.token = []
     logfile = CONTEXT.get_path(logfile)
     self.logfile = logfile
     self._read_stream_log()
     self.token = list(set(self.token))
示例#7
0
def check_deps():
    try:
        output_deps = os.path.join(CONTEXT.get_variables('${OUTPUT_DIR}'),
                                   env.deps)
        if os.path.exists(output_deps):
            return
        else:
            Common.copyFiles(env.depsDir, output_deps)
    except Exception, e:
        print e
示例#8
0
 def _getlogs(self, logfile):
     if not self.plogs:
         logfile = CONTEXT.get_path(logfile)
         lines = open(logfile, 'r')
         for line in lines:
             self.plogs.append(Plog(line))
         if len(self.plogs) == 0:
             raise BaseException("Performance log is empty")
         else:
             return self.plogs
     return self.plogs
示例#9
0
 def _runhttpclient(self, hc, url, method, requests, myheaders):
     for myrequest in requests:
         request = None
         newheards = {}
         if type(myrequest) is unicode:
             request = myrequest.encode('utf-8')
         if Common.check_file(CONTEXT.get_path(myrequest)):
             request = open(CONTEXT.get_path(myrequest), 'rb').read()
         for k, v in myheaders.items():
             newheards[k.encode('utf-8')] = v.encode('utf-8')
         if newheards.has_key('content-encoding'):
             if newheards['content-encoding'] == 'gzip':
                 request = Common.Compress_gzip(myrequest)
         dlog.write(request, console=True)
         h = httplib2.Http()
         try:
             resp, content = h.request(url.encode('utf-8'), method.encode('utf-8'), request, headers=newheards)
             hc.responses.append(content)
             hc.headers = resp
         except Exception, e:
             hc.responses.append(e)
             dlog.write('Run http Client Error:%s' % e, level="WARN", console=True)
示例#10
0
    def Stream_Log_clean(self, logfile):
        u'''
        Clean Stream_Log file

        Examples:

        | Stream Log clean  |  logfiel |

        '''
        try:
            logfile = CONTEXT.get_path(logfile)
            file1 = open(logfile, 'w+')
            file1.truncate()
        except Exception, e:
            dlog.write(e, "WARN")
示例#11
0
    def Perf_Clean(self, logfile):
        u'''
        Clean performance log file

        Examples:

        | Perf_Clean  | logfile |

        '''
        try:
            logfile = CONTEXT.get_path(logfile)
            if os.path.exists(logfile):
                file1 = open(logfile, 'w+')
                file1.truncate()
            else:
                dlog.fail("log file(%s) is not exist" % logfile)
        except Exception, e:
            dlog.write(e, "WARN")
示例#12
0
 def write(self, htmlfile):
     fh = open(
         os.path.join(CONTEXT.get_variables('${OUTPUT_DIR}'), htmlfile),
         'w')
     fh.write(self.htmlContents.encode('utf8'))
     fh.close()
示例#13
0
 def _get_request_path(self, Request):
     if not Common.check_file(CONTEXT.get_path(Request)):
         Request_path = Common.CreateTempFile(Request)
     else:
         Request_path = CONTEXT.get_path(Request)
     return Request_path