def sendemai(filename, title): smtp = smtplib.SMTP_SSL(host=conf.get('email', 'host'), port=conf.getint('email', 'port')) smtp.login(user=conf.get('email', 'user'), password=conf.get('email', 'password')) #创建一个组件 msg = MIMEMultipart() #第二步构建一个邮件 with open(os.path.join(REPORTPATH, filename), 'rb') as f: content = f.read() #创建邮件文本内容 text_msg = MIMEText(content, _subtype='html', _charset='utf8') #添加到多组件的邮件中 msg.attach(text_msg) #创建附件 report_msg = MIMEApplication(content) report_msg.add_header('content-disposition', 'attachment', filename=filename) #将附件添加到多组件的邮件中 msg.attach(report_msg) #主题 msg['Subject'] = title #发件人 msg['From'] = '*****@*****.**' #收件人 msg['To'] = '*****@*****.**' #第三步发送邮件 smtp.send_message(msg, from_addr=conf.get('email', 'from_addr'), to_addrs=eval(conf.get('email', 'to_addrs'))) #sendemai('result.html','测试报告')
def __init__(self): # 链接数据库 self.con = pymysql.connect(host=conf.get('mysql', 'host'), port=conf.getint('mysql', 'port'), user=conf.get('mysql', 'user'), password=conf.get('mysql', 'password'), database=conf.get('mysql', 'database'), charset='utf8') # 创建游标 self.cur = self.con.cursor()
def __init__(self): self.con = psycopg2.connect( host=conf.get('sql', 'host'), port=conf.getint('sql', 'port'), user=conf.get('sql', 'user'), password=conf.get('sql', 'password'), database=conf.get('sql', 'database'), ) #创建游标 self.cur = self.con.cursor()
def __init__(self): # 数据库连接对象 self.conn = pymysql.connect(host=conf.get("db", "host"), port=conf.getint("db", "port"), user=conf.get("db", "user"), password=conf.get("db", "pwd"), charset=conf.get("db", "charset"), cursorclass=pymysql.cursors.DictCursor) # 创建数据库游标对象 self.cur = self.conn.cursor()
def __init__(self): # 连接数据库 self.con = pymysql.connect(host=conf.get("mysql", "host"), port=conf.getint("mysql", "port"), user=conf.get("mysql", 'user'), password=conf.get("mysql", "password"), database=conf.get("mysql", "database"), charset="utf8") # 创建游标 self.cur = self.con.cursor()
def __init__(self): # 连接数据库 self.con = pymysql.connect( host=conf.get("mysql", "host"), # 端口号必须为整型int port=conf.getint("mysql", "port"), user=conf.get("mysql", "user"), password=conf.get("mysql", "password"), database=conf.get("mysql", "database"), charset="utf8") # 创建游标,通过游标来查询sql语句 self.cur = self.con.cursor()
def __init__(self): self.host = conf.get('mysql', 'host') self.port = conf.getint('mysql', 'port') self.user = conf.get('mysql', 'user') self.password = conf.get('mysql', 'password') self.charset = conf.get('mysql', 'charset') self.connot = pymysql.connect(host=self.host, port=self.port, user=self.user, password=self.password, charset=self.charset, cursorclass=pymysql.cursors.DictCursor) self.cursor = self.connot.cursor()
def setUpClass(cls): #登录并创建项目 #普通用户登录 login_api = 'http://api.lemonban.com/futureloan/member/login' headers=eval(conf.get('env','headers')) login_data ={'mobile_phone':conf.getint('soso','phone'), 'pwd':conf.get('soso','pwd')} login_res=cls.send.sendrequest(method='post',url=login_api,headers=headers,json=login_data) login_resp=login_res.json() token = jsonpath.jsonpath(login_resp,'$..token')[0] token_type = jsonpath.jsonpath(login_resp,'$..token_type')[0] headers['Authorization']='{} {}'.format(token_type,token) member_id=jsonpath.jsonpath(login_resp,'$..id')[0] #普通用户添加项目 add_api = 'http://api.lemonban.com/futureloan/loan/add' add_data ={"member_id":member_id,"title":"添加001","amount":6300.00,"loan_rate":"12.0","loan_term":12,"loan_date_type":1,"bidding_days":1} add_res=cls.send.sendrequest(method='post',url=add_api,headers=headers,json=add_data) add_resp=add_res.json() ReplaceData.loan_id=jsonpath.jsonpath(add_resp,'$..id')[0]