Пример #1
0
 def send(self,
          url,
          method,
          params=None,
          data=None,
          header=None,
          cookie=None,
          **kwargs):
     method = method.upper()
     if method not in METHODS:
         raise UnSupportMethodException(
             '不支持的method:{0},请检查传入参数!'.format(method))
     if header is not None:
         self.set_headers(header)
     if cookie is not None:
         self.set_cookies(cookie)
     response = self.session.request(method=method,
                                     url=url,
                                     params=params,
                                     data=data,
                                     headers=header,
                                     cookies=cookie,
                                     verify=self.verify,
                                     timeout=self.timeout,
                                     **kwargs)
     response.encoding = 'utf-8'
     LOG.debug('{0} {1}'.format(method, url))
     LOG.debug('请求成功: {0}\n{1}'.format(response, response.text))
     return response
Пример #2
0
 def send_email(self, to_list, cc_list, sub=None, content=None, file_path=None, subtype='html'):
     msg = MIMEMultipart()
     if sub is None:
         msg['Subject'] = '无标题邮件'
     else:
         msg['Subject'] = sub
     msg['From'] = self._me
     msg['To'] = ";".join(to_list)
     msg['Cc'] = ";".join(cc_list)
     if content is None:
         puretext = MIMEText('该邮件未输入任何内容')
         msg.attach(puretext)
     else:
         puretext = MIMEText(content, _subtype=subtype, _charset='utf-8')
         msg.attach(puretext)
     if file_path is not None:
         for tuple_path in tuple(file_path):
             mail_file = MIMEApplication(open(tuple_path, 'rb').read())
             mail_file.add_header('Content-Disposition', 'attachment', filename='%s' % tuple_path.split('/')[-1])
             msg.attach(mail_file)
     try:
         self._server.sendmail(self._me, to_list, msg.as_string())
         return True
     except Exception as e:
         LOG.error(str(e))
         return False
Пример #3
0
 def do_select(self, query):
     try:
         result_db = self.cur.execute(query)
     except Exception as e:
         LOG.error('查询命令错误', e)
         result_db = False
     return result_db
Пример #4
0
 def delete(self, k):
     tag = self.r.exists(k)
     # 判断这个key是否存在,相对于get到这个key他只是传回一个存在火灾不存在的信息,
     # 而不用将整个k值传过来(如果k里面存的东西比较多,那么传输很耗时)
     if tag:
         self.r.delete(k)
     else:
         LOG.error('这个key不存在')
Пример #5
0
 def wrapper(*args, **kw):
     for i in range(n):
         try:
             r = func(*args, **kw)
             return r
         except AssertionError as err:
             LOG.info('用例第%d次失败原因:%s' % (i + 1, err))
     raise AssertionError
Пример #6
0
 def hash_del(self, name, k):
     res = self.r.hdel(name, k)
     if res:
         LOG.info('删除成功')
         return 1
     else:
         LOG.info('删除失败,该key不存在')
         return 0
Пример #7
0
 def getresult(self):
     try:
         result = HessianProxy(self.url + self.interface)
         return_result = getattr(result, self.method)(self.interface_param)
         LOG.info('测试返回结果:%s' % return_result)
         res = {'code': 0, 'result': return_result}
     except Exception as e:
         LOG.info('测试失败,原因:%s' % e)
         res = {'code': 1, 'result': e}
     return res
Пример #8
0
 def test_sign_params_null(self, _, data_params):
     '''验证报名各字段参数为空'''
     uri = '/bentley/api/applyForTcjAsyn/'
     response = requests.post(self.url + uri,
                              data=data_params,
                              headers=self.headers)
     LOG.info('请求{0},参数{1},状态{2},\n 响应数据{3}'.format(uri, data_params,
                                                    response,
                                                    response.text))
     self.assertEqual(response.status_code, 200, '断言响应结果为200')
     self.assertEqual(response.json()['code'], 100000, '断言结果为100001')
     self.assertEqual(response.json()['msg'], '参数异常', '断言参数异常')
Пример #9
0
 def do_update(self, query):
     """
     update和delete\insert
     :param query:
     :return:
     """
     try:
         result_db = self.cur.execute(query)
         self.commit()
     except Exception as e:
         LOG.error('查询命令错误', e)
         result_db = False
     return result_db
Пример #10
0
 def __init__(self):
     conf = ConfigOperate('DB_config')
     self.host = conf.get_config('mysql_conf', 'host')
     self.port = int(conf.get_config('mysql_conf', 'port'))
     self.user = conf.get_config('mysql_conf', 'username')
     self.passwd = conf.get_config('mysql_conf', 'password')
     try:
         self.conn = pymysql.connect(host=self.host,
                                     port=self.port,
                                     user=self.user,
                                     passwd=self.passwd)
         self.cur = self.conn.cursor()
     except Exception as e:
         LOG.error('数据库连接错误', e)
Пример #11
0
 def test_signed(self):
     '''验证已经报名过重复报名'''
     uri = '/bentley/api/applyForTcjAsyn/'
     data_params = {
         'name': 'linlang66',
         'phone': '15633996699',
         'cityId': 10,
         'carStyleId': 32,
         'brandId': 67,
         'groupbyType': 1,
         'groupbyNum': 2001
     }
     response = requests.post(self.url + uri,
                              data=data_params,
                              headers=self.headers)
     LOG.info('请求{0},参数{1},状态{2},\n 响应数据{3}'.format(uri, data_params,
                                                    response,
                                                    response.text))
     self.assertEqual(response.status_code, 200, '断言响应结果为200')
     self.assertEqual(response.json()['code'], 100000, '断言结果为100000')
Пример #12
0
 def setOptionValue(self, name,  value):
     val = None
     if name in self._options :
         if self._options[name]['type'] == 'bool' :
             if value == "true" or value == "1":
                 val = True
             elif value == "false" or value == "0":
                 val = False
         elif self._options[name]['type'] == 'int' :
             try :
                 val == int(value)
             except :
                 if LOG : LOG.write(LogLevel.Warning,  "Option '{0}' not valid int type : {1}".format(name, value))
                 else :
                     print "Option '{0}' not valid int type : {1}".format(name, value)
         elif self._options[name]['type'] == 'str' :
             val = str(value)
         else :
             if LOG : LOG.write(LogLevel.Warning,  "Option '{0}' not valid type : {1}".format(name, value))
             else :
                 print "Option '{0}' not valid type : {1}".format(name, value)
         if val : self._options[name]['value'] = value
     else :
         if LOG : LOG.write(LogLevel.Warning,  "Option '{0}' not valid : {1}".format(name, value))
         else :
             print "Option '{0}' not valid : {1}".format(name, value)
Пример #13
0
def send_mail():
    suite_result = test_runner()
    to_list = ConfigOperate('global').get_config('email_send',
                                                 'to_list').split(';')
    cc_list = ConfigOperate('global').get_config('email_send',
                                                 'cc_list').split(';')
    file_path_tuple = (report_file_name, )
    email_username = ConfigOperate('global').get_config(
        'email_base', 'username')
    email_passwd = ConfigOperate('global').get_config('email_base', 'passwd')
    email_smtp = ConfigOperate('global').get_config('email_base', 'smtp')
    send_conf = SendEmail(email_smtp, email_username, email_passwd)
    content = 'http接口自动化测试完成,测试通过:%s,测试失败:%s,未知错误:%s,详情见附件' % (
        suite_result.success_count, suite_result.failure_count,
        suite_result.error_count)
    if send_conf.send_email(to_list,
                            cc_list,
                            sub='接口自动化测试报告' + now,
                            content=content,
                            file_path=file_path_tuple
                            ):  # content=open(report_file_name, 'rb').read()
        LOG.info('测试报告邮件发送成功')
    else:
        LOG.info('邮件发送失败')
Пример #14
0
 def __init__(self, ip, password, port=6379, db=1):  # 构造函数
     try:
         self.r = redis.Redis(host=ip, password=password, port=port, db=db)  # 连接redis固定方法,这里的值必须固定写死
     except Exception as e:
         LOG.error('redis连接失败,错误信息%s' % e)
Пример #15
0
# information
# Spot Market Collector : TradingEconomics
# 화폐단위 : USD
# output : resource/*.json
# WorkFlow :
# Before connect socketIO open file with append mode,
#  append each row to file when get response from socket
import datetime
import time
import websocket
import json
from lib.log import LOG
log = LOG()

te_url = "ws://stream.tradingeconomics.com/"
client_key = "guest"  #API_CLIENT_KEY
client_secret = "guest"  #API_CLIENT_KEY


class Crawler:
    def __init__(self, DB):
        self.url = "ws://stream.tradingeconomics.com/"
        self.key = "guest"  #API_CLIENT_KEY
        self.secret = "guest"  #API_CLIENT_KEY
        websocket.enableTrace(False)
        self.db = DB
        self.start_sc()

    def start_sc(self):
        self.ws = websocket.WebSocketApp(self.url + "?client=" + self.key +
                                         ":" + self.secret,
Пример #16
0
 def clean_redis(self):
     self.r.flushdb()  # 清空 redis
     LOG.info('清空redis成功!')
     return 0
Пример #17
0
import database.mongodb as MDB
import dataSource.bithumb_c as connect_b
import dataSource.investf_c as connect_n
import dataSource.nf_c as connect_k
import dataSource.te_c_v1 as connect_s

import threading
import time
from lib.log import LOG
log = LOG()

cc_cw = connect_b.Crawler()
nasdaq_cw = connect_n.Crawler('NYSE')
k_cw = connect_k.Crawler()

start = True
n = 0


class spmThread(threading.Thread):
    def __init__(self, threadID, name, DB):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.DB = DB

    def run(self):
        connect_s.Crawler(self.DB)


class sbmThread(threading.Thread):