eg:例如你调用了一个新增的接口,以往功能测试的话,你再web端新增一个店铺之后,你肯定要去数据库中查看,这些数据插入的对不对,是否正确的插入了每个字段

# 比较两个字典部分是否相等
def compare_two_dict(dict1, dict2, key_list):
flag = True
keys1 = dict1.keys()
keys2 = dict2.keys()
if len(key_list) != 0:
for key in key_list:
if key in keys1 and key in keys2:
if dict1[key] == dict2[key]:
flag = flag & True
else:
flag = flag & False
else:
raise Exception('key_list contains error key')
else:
raise Exception('key_list is null')
if flag:
result = 'PASS'
else:
result = 'FAILED'
return result if __name__ == '__main__':
dict1 = {
'a': 1,
'b': 2,
'c': 3,
'd': 4
}
dict2 = {
'a': 1,
'b': 2,
'c': 3,
'd': 8
}
key_list = ['a', 'c', 'b', 'd']
result = compare_two_dict(dict1, dict2, key_list)
print(result)

按照上面的列子我写出了自己的代码:前置条件:

但是有个前提条件:

'''
table:表名
key:要查找的字段名称
value:要查找的字段值
**kwargs:要检验的字段值,通过我新增的数据与数据库中的对比
例如你调用了一个新增的接口,以往功能测试的话,你再web端新增一个店铺之后,你肯定要去数据库中查看,这些数据插入的对不对,是否正确的插入了每个字段
'''
def assert_add_contents(db,cursor,table,key,value,**kwargs):
sql = 'select * from {} where {}={}'.format(table,key,value)
num = cursor.execute(sql)
result = cursor.fetchall()
print("查找到%d条数据" % num)
print("数据库查询数据为:{}".format(result))
# 这个是要对比的字段
field_list = list(kwargs.keys())
if num > 0:
print("kwargs:{}".format(kwargs))
print("result:{}".format(result[0]))
flag = True
keys1 = kwargs.keys()
keys2 = result[0].keys()
if len(field_list) != 0:
for key in field_list:
if key in keys1 and key in keys2:
if kwargs[key] == result[0][key]:
flag = flag & True
else:
flag = flag & False
else:
raise Exception('key_list contains error key')
else:
raise Exception('key_list is null')
if flag:
result = 'PASS'
else:
result = 'FAILED'
print("result============================={}".format(result))
return result
else:
pass db = config.db
cursor = db.cursor(cursor = pymysql.cursors.DictCursor) param = PostParameter().post_param(path,"shop","add_shop.json", "case001")
print("param[data]:{}".format(param["data"]))
shop_name = param["data"]["shop_name"]
shop_short_name = param["data"]["shop_short_name"]
shop_phone = param["data"]["shop_phone"]
province = param["data"]["province"]
city = param["data"]["city"]
district = param["data"]["district"]
town = param["data"]["town"]
address = param["data"]["address"] assert_add_contents(db,cursor,"t_shop_info","id","",shop_name = shop_name,shop_short_name = shop_short_name,shop_phone = shop_phone,province = province,city = city,district = district,town = town,address = address)

最新文章

  1. 反编译.NET工程
  2. Maven生命周期小记
  3. spring-data-redis 用法
  4. Unity5版本的AssetBundle打包方案之打包Scene场景
  5. JMeter学习(六)集合点
  6. MongoDB查询并更新一粟
  7. B-tree解释
  8. PHP负载均衡
  9. JavaScript高级程序设计(学习笔记)
  10. codeforces 316F3 Suns and Rays
  11. POJ 3342 Party at Hali-Bula / HDU 2412 Party at Hali-Bula / UVAlive 3794 Party at Hali-Bula / UVA 1220 Party at Hali-Bula(树型动态规划)
  12. koa2 controller中实现类似sleep的延迟功能
  13. Template Method 模板设计模式
  14. 转摘: MySQL详解--锁
  15. 使用IdentityServer4,在一个ASPNetCore项目中,配置oidc和api的AccessToken两种认证授权
  16. 【.NET架构】BIM软件架构01:Revit插件产品架构梳理
  17. laravel5 报错419,form 添加crrf_field 后让然失败,本地环境配置问题
  18. 黑马day17 ajax&实现username自己主动刷新
  19. Linux下DIR,dirent,stat等结构体详解(转)
  20. 一:My Batis快速入门

热门文章

  1. 题解 【洛谷P1332】血色先锋队
  2. 插件与App的跳转,及路由的关系
  3. 10个Spring Boot快速开发的项目,接私活利器(快速、高效)
  4. python之pandas简介
  5. Itext相关知识
  6. sendmail邮件服务器
  7. HTML备忘
  8. ts中的类
  9. AcWing 差分一维加二维
  10. 前端框架vue.js系列(9):Vue.extend、Vue.component与new Vue