handle mysql
This commit is contained in:
parent
44123b9ba8
commit
1fc62849de
|
@ -13,30 +13,35 @@ wb = openpyxl.load_workbook('case.xlsx')
|
|||
# 选中工作簿中的表单对象
|
||||
sh = wb['case']
|
||||
|
||||
# 写入数据
|
||||
sh.cell(row=3, column=1, value='flora')
|
||||
|
||||
# # 读取指定格子中的数据
|
||||
# c12 = sh.cell(row=1, column=2).value # 表示获取第一行第二列的数据
|
||||
#
|
||||
# # 写入数据
|
||||
# sh.cell(row=3, column=1, value='flora')
|
||||
# # 将工作簿对象保存为文件
|
||||
# 将工作簿对象保存为文件
|
||||
wb.save('case.xlsx')
|
||||
|
||||
# 获取表单中的最大行
|
||||
max_row = sh.max_row
|
||||
print(max_row)
|
||||
|
||||
|
||||
# 获取表单中的最大列
|
||||
max_column= sh.max_column
|
||||
print(max_column)
|
||||
|
||||
|
||||
# 获取表单中的最大行
|
||||
max_row = sh.max_row
|
||||
print(max_row)
|
||||
|
||||
|
||||
|
||||
# columns按列获取整个表单里面的所有格子对象,每行的内容放在一个元组中
|
||||
res2 = list(sh.columns)
|
||||
print(res2)
|
||||
|
||||
# 通过for循环获取每列中的内容
|
||||
for item in res2:
|
||||
for j in item:
|
||||
print(j.value)
|
||||
|
||||
# rows按行获取整个表单里面的所有格子对象,每行的内容放在一个元组中
|
||||
"""
|
||||
[(<Cell 'case'.A1>, <Cell 'case'.B1>,
|
||||
<Cell 'case'.C1>, <Cell 'case'.D1>),
|
||||
(<Cell 'case'.A2>, <Cell 'case'.B2>,
|
||||
<Cell 'case'.C2>, <Cell 'case'.D2>)]
|
||||
"""
|
||||
res1 = list(sh.rows)
|
||||
print(res1)
|
||||
|
||||
|
@ -45,20 +50,16 @@ for item in res1:
|
|||
for i in item:
|
||||
print(i.value)
|
||||
|
||||
# columns按列获取整个表单里面的所有格子对象,每行的内容放在一个元组中
|
||||
"""
|
||||
[(<Cell 'case'.A1>, <Cell 'case'.A2>),
|
||||
(<Cell 'case'.B1>, <Cell 'case'.B2>),
|
||||
(<Cell 'case'.C1>, <Cell 'case'.C2>),
|
||||
(<Cell 'case'.D1>, <Cell 'case'.D2>)]
|
||||
"""
|
||||
res2 = list(sh.columns)
|
||||
print(res2)
|
||||
|
||||
# 通过for循环获取每列中的内容
|
||||
for item in res2:
|
||||
for j in item:
|
||||
print(j.value)
|
||||
|
||||
# 读取指定格子中的数据
|
||||
c12 = sh.cell(row=1, column=2).value # 表示获取第一行第二列的数据
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print('------------------')
|
||||
# 读取第三行的数据
|
||||
|
|
|
@ -7,7 +7,6 @@ Time: 2020/3/6 9:33
|
|||
"""
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from BeautifulReport import BeautifulReport
|
||||
|
||||
"""
|
||||
|
|
|
@ -6,10 +6,8 @@ Time: 2020/3/7 9:47
|
|||
=================================
|
||||
"""
|
||||
import unittest
|
||||
|
||||
from python27Class.class03102020.demo2.readExcel import HandleExcel
|
||||
from python27Class.class03102020.demo2.registerPage import register
|
||||
|
||||
from python27Class.unitTest.class03102020.demo2.readExcel import HandleExcel
|
||||
from python27Class.unitTest.class03102020.demo2.registerPage import register
|
||||
from python27Class.unitTest.class03102020.demo2.ddtNew import ddt, data
|
||||
|
||||
|
|
@ -31,6 +31,7 @@ form = logging.Formatter(formats)
|
|||
# 将日志输出格式对象添加到输出渠道
|
||||
fh.setFormatter(form)
|
||||
sh.setFormatter(form)
|
||||
|
||||
# 输出日志
|
||||
log.error('-------------error------------')
|
||||
log.warning('-------------info------------')
|
||||
|
@ -39,7 +40,8 @@ log.warning('-------------info------------')
|
|||
输出日志
|
||||
注意点:自定义的日志收集器收集日志要使用收集器去记录.不能直接使用logging去记录。
|
||||
这是默认使用logging收集器去记录的:logging.error('-------------error------------')
|
||||
|
||||
"""
|
||||
"""
|
||||
日志输出格式:
|
||||
%(name)s:收集器名称
|
||||
%(levelno)s:打印日志级别的数值
|
||||
|
|
|
@ -12,8 +12,9 @@ import logging
|
|||
my_log = logging.getLogger()
|
||||
|
||||
# 设置日志收集等级
|
||||
my_log.setLevel('DEBUG')
|
||||
my_log.setLevel('INFO')
|
||||
|
||||
# 按照收集日志的等级在控制台输出日志
|
||||
logging.debug('这是一条DEBUG级别的日志')
|
||||
logging.info('这是一条INFO级别的日志')
|
||||
logging.error('这是一条ERROR级别的日志')
|
||||
|
|
|
@ -14,7 +14,6 @@ Time: 2020/3/12 20:09
|
|||
"""
|
||||
import logging
|
||||
|
||||
|
||||
# 创建日志收集器(如果不传参数name,会返回默认的日志收集器root)
|
||||
my_log = logging.getLogger()
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import logging
|
|||
logging模块默认的日志收集器(root), 收集的是warning及以上等级的日志
|
||||
"""
|
||||
|
||||
# 直接在控制台输出日志信息
|
||||
logging.debug('这是一条DEBUG级别的日志')
|
||||
logging.info('这是一条INFO级别的日志')
|
||||
logging.error('这是一条ERROR级别的日志')
|
||||
|
|
|
@ -32,14 +32,19 @@ when:设置间隔单位(默认H)
|
|||
D:Days天
|
||||
backupCount:轮转的文件数量
|
||||
"""
|
||||
# from logging.handlers import TimedRotatingFileHandler
|
||||
# fh = TimedRotatingFileHandler(filename='user.log',
|
||||
# encoding='utf-8',
|
||||
# when='S',
|
||||
# interval=1,
|
||||
# backupCount=2)
|
||||
# fh.setLevel('DEBUG')
|
||||
# log.addHandler(fh)
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
fh = TimedRotatingFileHandler(filename='user.log',
|
||||
encoding='utf-8',
|
||||
when='S',
|
||||
interval=1,
|
||||
backupCount=2)
|
||||
fh.setLevel('DEBUG')
|
||||
log.addHandler(fh)
|
||||
|
||||
# 输出日志
|
||||
log.error('-------------error------------')
|
||||
log.warning('-------------info------------')
|
||||
|
||||
|
||||
# 创建一个按文件大小进行轮转的文件输出渠道
|
||||
"""
|
||||
|
@ -63,6 +68,3 @@ form = logging.Formatter(formats)
|
|||
# 将日志输出格式对象添加到输出渠道
|
||||
fh.setFormatter(form)
|
||||
|
||||
# 输出日志
|
||||
log.error('-------------error------------')
|
||||
log.warning('-------------info------------')
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
# ---这是日志相关的配置文件
|
||||
# section
|
||||
[log]
|
||||
# option
|
||||
level = DEBUG
|
||||
fh_level = INFO
|
||||
filename = all.log
|
||||
sh_level = ERROR
|
||||
|
||||
# ---这是mysql数据库相关的配置文件
|
||||
# section
|
||||
[mysql]
|
||||
# option
|
||||
host = 127.0.0.1
|
||||
port = 3306
|
||||
n = 1.67
|
||||
|
@ -13,3 +19,4 @@ isb = false
|
|||
name = flora
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,22 @@ Time: 2020/3/17 21:30
|
|||
"""
|
||||
import yaml
|
||||
|
||||
|
||||
|
||||
# 文件写入
|
||||
data = {
|
||||
'A' : 'a',
|
||||
'B' : {
|
||||
'C' : 'c',
|
||||
'D' : 'd',
|
||||
'E' : 'e',
|
||||
}
|
||||
}
|
||||
# a表示追加写入, w表示覆盖写入
|
||||
with open('yaml.yaml', 'w') as f:
|
||||
yaml.dump(data, f)
|
||||
|
||||
# 文件读取
|
||||
with open('yaml.yaml', 'r', encoding='utf-8') as f:
|
||||
file = yaml.load(f, Loader=yaml.FullLoader)
|
||||
print(file['mysql']['port']) # 输出结果:3306
|
||||
|
|
|
@ -1,17 +1,5 @@
|
|||
log:
|
||||
level: DEBUG
|
||||
fh_level: INFO
|
||||
sh_level: ERROR
|
||||
|
||||
mysql:
|
||||
host: 127.0.0.1
|
||||
port: 3306
|
||||
dict: { # 这是一个字典
|
||||
a: 100,
|
||||
b: 200.02
|
||||
}
|
||||
dict2: # 这也是一个字典
|
||||
a2: 100
|
||||
b2: 200.02
|
||||
list: [11, 12, 14] # 这是一个列表
|
||||
list2: 11, 22, 44 # 这是一个字符串
|
||||
A: a
|
||||
B:
|
||||
C: c
|
||||
D: d
|
||||
E: e
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
request模块
|
||||
|
||||
安装:pip install request
|
||||
|
||||
requestPractice.py --发送post以及get请求
|
||||
requestSendParam.py --使用post发送不同类型的请求参数
|
||||
getResponse.py --响应数据的提取
|
||||
downloadFiles.py -- 关于请求内容获取和文件下载
|
||||
|
||||
安装:pip install jsonpath
|
||||
jsonpathPractice.py ---请求返回数据的提取:jsonpath模块
|
||||
login_recharge.py ---登录充值案例演示
|
|
@ -0,0 +1,25 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/21 11:02
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
|
||||
"""
|
||||
关于请求内容获取和文件下载
|
||||
"""
|
||||
import requests
|
||||
|
||||
response = requests.get(url='http://www.lemonban.com/')
|
||||
|
||||
# 自动识别内容的编码方式,有可能识别不准确出现乱码
|
||||
print(response.text)
|
||||
# 手动指定编码方式对页面内容进行解码
|
||||
print(response.content.decode('utf-8'))
|
||||
|
||||
# 文件下载
|
||||
response1 = requests.get(url='文件地址')
|
||||
print(response1.content)
|
||||
with open('文件保存的路径', 'wb') as f:
|
||||
f.write(response1.content)
|
|
@ -0,0 +1,52 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/21 10:45
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
|
||||
"""
|
||||
响应数据的提取
|
||||
"""
|
||||
|
||||
import requests
|
||||
"""
|
||||
# 第一步:准备请求的相关的数据
|
||||
"""
|
||||
# 接口地址
|
||||
url = 'http://api.lemonban.com/futureloan/member/login'
|
||||
|
||||
# 请求参数
|
||||
data = {
|
||||
'mobile_phone': '18774970056',
|
||||
'pwd': '12345678'
|
||||
}
|
||||
# 请求头
|
||||
headers = {
|
||||
'X-lemonban-Media-Type': 'lemonban.v1'
|
||||
}
|
||||
|
||||
"""
|
||||
# 第二步:发送post请求
|
||||
url:需要发送请求的地址
|
||||
json:以json格式发送请求参数
|
||||
"""
|
||||
response = requests.post(url=url, json=data, headers=headers)
|
||||
|
||||
# ----------------------text属性------------------------------
|
||||
# 打印返回内容
|
||||
print(response.text) # 返回的是字符串类型的数据
|
||||
|
||||
# 错误示范:不要使用这种方式转为字典,因为如果返回值里面有null, true, false的数据就会报错
|
||||
# print(type(eval(response.text)))
|
||||
|
||||
# 推荐使用这种方式:json方法 (使用该方法的前提:返回数据必须是json格式的)
|
||||
# (自动将字符串中的json类型数据转换为对应的python值,如果有null会自动转换成None, false会自动转换成False, true会自动转换成True)
|
||||
print(type(response.json())) # <class 'dict'>
|
||||
|
||||
# ----------------------content属性------------------------------
|
||||
# 返回的是字节流的格式
|
||||
print(response.content)
|
||||
# 使用指定的编码格式进行编码
|
||||
print(response.content.decode('utf-8')) # 返回的也是字符串类型的数据
|
|
@ -0,0 +1,75 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/21 9:37
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
"""
|
||||
request的基础使用
|
||||
post请求发送
|
||||
get请求发送
|
||||
"""
|
||||
|
||||
import requests
|
||||
|
||||
"""
|
||||
# 第一步:准备请求的相关的数据
|
||||
"""
|
||||
# 接口地址
|
||||
url = 'http://api.lemonban.com/futureloan/member/register'
|
||||
|
||||
# 请求参数
|
||||
data = {
|
||||
'mobile_phone': '18774970056',
|
||||
'pwd': '12345678'
|
||||
}
|
||||
# 请求头
|
||||
headers = {
|
||||
'X-lemonban-Media-Type': 'lemonban.v1'
|
||||
}
|
||||
|
||||
"""
|
||||
# 第二步(1):发送post请求
|
||||
url:需要发送请求的地址
|
||||
json:以json格式发送请求参数
|
||||
"""
|
||||
response = requests.post(url=url, json=data, headers=headers)
|
||||
# 打印返回内容
|
||||
# print(response.text)
|
||||
# # 打印请求头
|
||||
# print(response.request.headers)
|
||||
|
||||
"""
|
||||
默认请求头
|
||||
{'User-Agent': 'python-requests/2.23.0',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept': '*/*',
|
||||
'Connection': 'keep-alive',
|
||||
'Content-Length': '50'
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
# 第二步(2):发送get请求
|
||||
url:需要发送请求的地址
|
||||
"""
|
||||
# get请求参数,方式一:放到URL地址后面
|
||||
url1 = 'http://httpbin.org/get?name=musen&age=18'
|
||||
response1 = requests.get(url=url1)
|
||||
# 打印返回内容
|
||||
# print(response1.text)
|
||||
|
||||
|
||||
# get请求参数,方式二:使用params来进行传递
|
||||
url2 = 'http://httpbin.org/get'
|
||||
data2 = {
|
||||
'name': 'musen',
|
||||
'age': 19
|
||||
}
|
||||
|
||||
response2 = requests.get(url=url, params=data2)
|
||||
print(response2.text)
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/21 9:58
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
"""
|
||||
各种类型的参数怎么请求传递
|
||||
"""
|
||||
|
||||
import requests
|
||||
# ----------------------------------post------------------------------------------------------
|
||||
# url = 'http://httpbin.org/post'
|
||||
#
|
||||
# data = {
|
||||
# 'mobile_phone': '18774970056',
|
||||
# 'pwd': '12345678'
|
||||
# }
|
||||
|
||||
# 参数类型为 "Content-Type": "application/json", 发送请求的时候使用json来传递参数
|
||||
# response = requests.post(url=url, json=data)
|
||||
|
||||
# 参数类型为"Content-Type": "application/x-www-form-urlencoded", 发送请求时使用data来传递参数
|
||||
# response = requests.post(url=url, data=data)
|
||||
|
||||
# 参数类型为 "Content-Type": "multipart/form-data", 发送请求的时候使用files来传递参数
|
||||
# # 文件上传传递参数
|
||||
# file = { # 文件名(后台接收到的服务器看到的名字,可以自定义), 打开的文件句柄,文件类型
|
||||
# # pic需要具体看接口里面上传文件需要的参数名是什么
|
||||
# 'pic': ('picture.jpg', open('picture.jpg', 'rb'), 'image/jpg')
|
||||
# }
|
||||
# 注意:如果文件上传中还有其他参数,其他参数是不能放在file里面
|
||||
# response = requests.post(url=url, files=file)
|
||||
# response = requests.post(url=url, files=file, data=data)
|
||||
#
|
||||
# print(response.text)
|
||||
|
||||
# ----------------------------------get------------------------------------------------------
|
||||
url = 'http://httpbin.org/get'
|
||||
|
||||
response = requests.get(url=url)
|
||||
|
||||
print(response.text)
|
||||
|
||||
# get请求参数,方式一:放到URL地址后面
|
||||
# url1 = 'http://httpbin.org/get?name=musen&age=18'
|
||||
# response1 = requests.get(url=url1)
|
||||
# # 打印返回内容
|
||||
# print(response1.text)
|
||||
|
||||
|
||||
# get请求参数,方式二:使用params来进行传递
|
||||
url2 = 'http://httpbin.org/get'
|
||||
data2 = {
|
||||
'name': 'flora',
|
||||
'age': 19
|
||||
}
|
||||
response2 = requests.get(url=url, params=data2)
|
||||
print(response2.text)
|
|
@ -0,0 +1,75 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/21 11:16
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
|
||||
"""
|
||||
请求返回数据的提取:jsonpath模块
|
||||
pip install jsonpath
|
||||
"""
|
||||
|
||||
import jsonpath
|
||||
|
||||
res = {'code': 0, 'msg': 'OK',
|
||||
'data':
|
||||
{'id': 7800009,
|
||||
'leave_amount': 0.0,
|
||||
'mobile_phone': '18774970056',
|
||||
'reg_name': '小柠檬',
|
||||
'reg_time': '2020-03-21 09:49:39.0',
|
||||
'type': 1,
|
||||
'token_info':
|
||||
{
|
||||
'token_type': 'Bearer',
|
||||
'expires_in': '2020-03-21 11:17:45',
|
||||
'token': 'eyJhbGciOiJIUzUxMiJ9.eyJtZW1iZXJfaWQiOjc4MDAwMDksImV4cCI6MTU4NDc2MDY2NX0._QSh69t8NgUXSMl4nmW0e7fBemAxoeqH_TGN1PjrhJpgRWdAD6uTf5Fr_UXgqlgUFYSqmKKM9Dl92QwbRn3IAQ'
|
||||
}
|
||||
},
|
||||
'data1':
|
||||
{'id': 7800010,
|
||||
'leave_amount': 0.0,
|
||||
'mobile_phone': '18774970056',
|
||||
'reg_name': '小柠檬',
|
||||
'reg_time': '2020-03-21 09:49:39.0',
|
||||
'type': 1,
|
||||
'token_info':
|
||||
{
|
||||
'token_type': {
|
||||
'a': 'Bearer',
|
||||
'b': 'Bearer01'
|
||||
|
||||
},
|
||||
'expires_in': '2020-03-21 11:17:45',
|
||||
'token': 'eyJhbGciOiJIUzUxMiJ9.eyJtZW1iZXJfaWQiOjc4MDAwMDksImV4cCI6MTU4NDc2MDY2NX0._QSh69t8NgUXSMl4nmW0e7fBemAxoeqH_TGN1PjrhJpgRWdAD6uTf5Fr_UXgqlgUFYSqmKKM9Dl92QwbRn3IAQ'
|
||||
}
|
||||
},
|
||||
'copyright': 'Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved'
|
||||
}
|
||||
|
||||
# ---------使用字典的键值对方式去提取----------------
|
||||
# 提取用户的id
|
||||
member_id = res['data']['id']
|
||||
|
||||
# 提取token值
|
||||
token = res['data']['token_info']['token']
|
||||
|
||||
# ---------使用jsonpath方式去提取----------------
|
||||
member_id_01 = jsonpath.jsonpath(res, '$..id')[0]
|
||||
member_id_02 = jsonpath.jsonpath(res, '$.data..id')
|
||||
|
||||
token_01 = jsonpath.jsonpath(res, '$..token')
|
||||
token_type = jsonpath.jsonpath(res, '$.data1.token_info..a')
|
||||
|
||||
code = jsonpath.jsonpath(res, '$.code')
|
||||
|
||||
print(member_id_01, token_01)
|
||||
print(code)
|
||||
print(token_type)
|
||||
|
||||
"""
|
||||
. 代表直接子节点
|
||||
.. 代表子孙节点(不管层级)
|
||||
"""
|
|
@ -0,0 +1,74 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/21 11:11
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
import requests
|
||||
import jsonpath
|
||||
"""
|
||||
# 第一步:准备请求的相关的数据
|
||||
"""
|
||||
# 请求登录的接口
|
||||
url = 'http://api.lemonban.com/futureloan/member/login'
|
||||
|
||||
# 请求参数
|
||||
data = {
|
||||
'mobile_phone': '18774970056',
|
||||
'pwd': '12345678'
|
||||
}
|
||||
# 请求头
|
||||
headers = {
|
||||
'X-lemonban-Media-Type': 'lemonban.v2'
|
||||
}
|
||||
|
||||
"""
|
||||
# 第二步:发送post请求
|
||||
url:需要发送请求的地址
|
||||
json:以json格式发送请求参数
|
||||
"""
|
||||
response = requests.post(url=url, json=data, headers=headers)
|
||||
res = response.json()
|
||||
# print(res)
|
||||
|
||||
"""
|
||||
{'code': 0, 'msg': 'OK',
|
||||
'data':
|
||||
{'id': 7800009,
|
||||
'leave_amount': 0.0,
|
||||
'mobile_phone': '18774970056',
|
||||
'reg_name': '小柠檬',
|
||||
'reg_time': '2020-03-21 09:49:39.0',
|
||||
'type': 1,
|
||||
'token_info':
|
||||
{
|
||||
'token_type': 'Bearer',
|
||||
'expires_in': '2020-03-21 11:17:45',
|
||||
'token': 'eyJhbGciOiJIUzUxMiJ9.eyJtZW1iZXJfaWQiOjc4MDAwMDksImV4cCI6MTU4NDc2MDY2NX0._QSh69t8NgUXSMl4nmW0e7fBemAxoeqH_TGN1PjrhJpgRWdAD6uTf5Fr_UXgqlgUFYSqmKKM9Dl92QwbRn3IAQ'
|
||||
}
|
||||
},
|
||||
'copyright': 'Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved'
|
||||
}
|
||||
"""
|
||||
|
||||
# 提取用户的id和token值
|
||||
member_id= jsonpath.jsonpath(res, '$..id')[0]
|
||||
token = jsonpath.jsonpath(res, '$..token')[0]
|
||||
token_type = jsonpath.jsonpath(res, '$..token_type')[0]
|
||||
|
||||
|
||||
# 请求需要鉴权的接口
|
||||
re_url = 'http://api.lemonban.com/futureloan/member/recharge'
|
||||
re_data = {
|
||||
'member_id': member_id,
|
||||
'amount': 2000
|
||||
}
|
||||
headers = {
|
||||
'X-lemonban-Media-Type': 'lemonban.v2',
|
||||
'Authorization': token_type + ' ' + token
|
||||
}
|
||||
|
||||
response2 = requests.post(url=re_url, json=re_data, headers=headers)
|
||||
print(response2.text)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
课程内容:
|
||||
封装request。
|
||||
其实没必要封装,直接用requests.request模块就可以了。
|
||||
|
||||
然后讲了下接口实战项目里面编写注册和登录功能的用例
|
||||
以及如何将所有写死的项目路径通过封装的方式读取,以后就算项目迁移也不影响代码。
|
|
@ -0,0 +1,41 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/24 20:32
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
|
||||
"""
|
||||
封装的需求:
|
||||
请求方法,请求地址,请求参数 (excel中有这些数据)
|
||||
请求头:放到配置文件中
|
||||
"""
|
||||
|
||||
import requests
|
||||
|
||||
def send(case):
|
||||
"""
|
||||
|
||||
:param case: 字典格式的用例数据
|
||||
:return:
|
||||
"""
|
||||
headers = ''
|
||||
|
||||
if case['method'] == 'get':
|
||||
return requests.post(case['url'], params=eval(case['data']), headers=headers)
|
||||
elif case['method'] == 'post':
|
||||
return requests.post(case['url'], json=eval(case['data']), headers=headers)
|
||||
elif case['method'] == 'put':
|
||||
return requests.put(case['url'], json=eval(case['data']), headers=headers)
|
||||
|
||||
|
||||
"""
|
||||
这个封装方法还不完善,只是提供了一种封装思路。
|
||||
其实没有必要做封装。可以直接用requests模块中的request
|
||||
"""
|
||||
|
||||
response = requests.request('get', url='http://www.baidu.com')
|
||||
response1 = requests.request('post', url='http://www.baidu.com', json='', headers='')
|
||||
|
||||
print(response.text)
|
|
@ -0,0 +1,13 @@
|
|||
课程内容:
|
||||
操作数据库
|
||||
数据库模块的封装
|
||||
|
||||
安装:pip install pymysql
|
||||
|
||||
|
||||
其他数据库操作:http://lemfix.com/topics/306
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/26 20:39
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
封装的需求
|
||||
1. 查询数据的方法
|
||||
2. 增删改的方法
|
||||
3. init方法:建立连接
|
||||
|
||||
|
||||
"""
|
||||
import pymysql
|
||||
|
||||
|
||||
class HandleDB:
|
||||
"""
|
||||
操作数据库
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
初始化方法中, 连接到数据库
|
||||
"""
|
||||
# 建立连接
|
||||
self.conn = pymysql.connect(host='120.78.128.25',
|
||||
port=3306,
|
||||
user='future',
|
||||
password='123456',
|
||||
charset='utf8',
|
||||
cursorclass=pymysql.cursors.DictCursor) # 加上这个返回的就是字典
|
||||
|
||||
# 创建一个游标对象
|
||||
self.cur = self.conn.cursor()
|
||||
|
||||
def find_all(self, sql):
|
||||
"""
|
||||
查询sql语句,返回所有数据
|
||||
:param sql: 查询的sql
|
||||
:type sql: str
|
||||
:return: 查询到的所有数据
|
||||
"""
|
||||
self.conn.commit()
|
||||
self.cur.execute(sql)
|
||||
return self.cur.fetchall()
|
||||
|
||||
def find_one(self, sql):
|
||||
"""
|
||||
查询sql语句,返回第一条数据
|
||||
:param sql: 查询的sql
|
||||
:type sql: str
|
||||
:return: 查询到的第一条数据
|
||||
"""
|
||||
self.conn.commit()
|
||||
self.cur.execute(sql)
|
||||
return self.cur.fetchone()
|
||||
|
||||
def find_count(self, sql):
|
||||
"""
|
||||
查询sql语句查询到的数据条数
|
||||
:param sql: 查询的dql
|
||||
:return: 查询到的条数
|
||||
"""
|
||||
self.conn.commit()
|
||||
return self.cur.execute(sql)
|
||||
|
||||
def update(self, sql):
|
||||
"""
|
||||
增删改操作的方法
|
||||
:param sql: 增删改的sql
|
||||
:return:
|
||||
"""
|
||||
self.cur.execute(sql)
|
||||
self.conn.commit()
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
断开游标,关闭连接
|
||||
:return:
|
||||
"""
|
||||
self.conn.close()
|
||||
self.cur.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
db = HandleDB()
|
||||
sql = 'select * from futureloan.member limit 5'
|
||||
print(db.find_one(sql))
|
||||
db.close()
|
|
@ -0,0 +1,28 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/26 21:44
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
import random
|
||||
from python27Class.unitTest.class03262020.handle_mysql import HandleDB
|
||||
|
||||
db = HandleDB()
|
||||
|
||||
def random_phone():
|
||||
"""
|
||||
生成一个数据库中未注册的手机号码
|
||||
:return: 生成的手机号码
|
||||
"""
|
||||
while True:
|
||||
phone = '131'
|
||||
for i in range(8):
|
||||
num = random.randint(0, 9)
|
||||
phone += str(num)
|
||||
result = db.find_count('select * from futureloan.member where mobile_phone={}'.format(phone))
|
||||
if result == 0:
|
||||
return phone
|
||||
|
||||
|
||||
print(random_phone())
|
|
@ -0,0 +1,53 @@
|
|||
"""
|
||||
=================================
|
||||
Author: Flora Chen
|
||||
Time: 2020/3/13 15:57
|
||||
-_- -_- -_- -_- -_- -_- -_- -_-
|
||||
=================================
|
||||
"""
|
||||
import os
|
||||
import logging
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
|
||||
|
||||
class HandleLogging:
|
||||
"""
|
||||
处理日志的相关模块
|
||||
"""
|
||||
|
||||
def record_log_by_time_rotate(self):
|
||||
"""
|
||||
文件中保存日志,日志按照时间进行轮转
|
||||
:return: log_collector
|
||||
"""
|
||||
# 定义日志收集器
|
||||
log_collector = logging.getLogger('floralog')
|
||||
|
||||
# 每次被调用后,清空已经存在handler
|
||||
log_collector.handlers.clear()
|
||||
|
||||
# 定义日志收集的等级
|
||||
log_collector.setLevel('DEBUG')
|
||||
|
||||
# 设置日志的输出渠道-按时间进行轮转的文件输出渠道
|
||||
log_handler = TimedRotatingFileHandler(filename=os.path.join('log.log', 'log.log'),
|
||||
encoding='utf-8',
|
||||
when='H',
|
||||
interval=1,
|
||||
backupCount=1)
|
||||
# 设置日志输出的等级
|
||||
log_handler.setLevel('INFO')
|
||||
|
||||
# 添加日志处理器Handler
|
||||
log_collector.addHandler(log_handler)
|
||||
|
||||
# 设置日志输出格式
|
||||
log_formats = logging.Formatter(
|
||||
'%(asctime)s ---%(name)s--- [%(filename)s-->line:%(lineno)d] - %(levelname)s: %(message)s')
|
||||
# 将日志输出格式对象添加到输出渠道
|
||||
log_handler.setFormatter(log_formats)
|
||||
|
||||
return log_collector
|
||||
|
||||
|
||||
log = HandleLogging()
|
|
@ -13,6 +13,7 @@ from python27HomeWork.unitTest.homeWork03122020.ddtNew import ddt, data
|
|||
from python27HomeWork.unitTest.homeWork03122020.handleLog import HandleLogging
|
||||
|
||||
|
||||
|
||||
@ddt
|
||||
class TestLoginCase(unittest.TestCase):
|
||||
"""
|
Loading…
Reference in New Issue