def test_urine_v2_recommendGoodsInfo_list(self): """ 推荐商品列表 :return: """ func_name = sys._getframe().f_code.co_name query_type = self.get_request_data(func_name) expect_result = self.get_expect_result(func_name) """默认查询所有推荐商品""" res = self.get_result(func_name) actual_result = res[0].json()['errmsg'] recommend_goodsInfo_list = res[0].json()['data'] gl.set_value('recommend_goodsInfo_list', recommend_goodsInfo_list) self.assertIn(actual_result, expect_result) self.assertIsNotNone(recommend_goodsInfo_list) """根据图片类型、使用类型查询""" for show_type in range(2): for use_type in range(3): query_type['useType'] = use_type query_type['showType'] = show_type res = self.get_result(func_name, var_params=query_type) actual_result = res[0].json()['errmsg'] recommend_goodsInfo_list = res[0].json()['data'] self.assertIn(actual_result, expect_result) self.assertIsNotNone(recommend_goodsInfo_list)
def test_urine_v2_bannerInfo_update(self): """ 修改小程序banner :return: """ func_name = sys._getframe().f_code.co_name row = self.get_case_row_index(func_name) # banner_list = self.get_depend_params(func_name) banner_list = gl.get_value('banner_list') # gl.set_value('banner_list', banner_list) update_banner_info = self.get_request_data(func_name) banner_name = update_banner_info['bannerName'] query_banner_info = None for banner in banner_list: if banner['bannerName'] == banner_name: query_banner_info = banner gl.set_value('banner_info', query_banner_info) for data in query_banner_info: update_banner_info[data] = query_banner_info[data] update_banner_info['imgs'][0]['url'] = query_banner_info[ 'bannerPicUrl'] update_banner_info['imgs'][0]['uid'] = int(time.time() * 1000) for date in [ 'bannerShowStartDate', 'bannerShowEndDate', 'bannerStartDate', 'bannerEndDate' ]: banner_time = time.strftime( "%Y.%m.%d", time.localtime(query_banner_info[date] / 1000)) start_end_time = 'showStartEndTime' if 'Show' in date else 'startEndTime' update_banner_info[start_end_time].append(banner_time) res = self.get_result(func_name, var_params=update_banner_info) actual_result = res[0].json()['data'] expect_result = self.get_expect_result(func_name) self.update_result(row, actual_result, expect_result)
def test_urine_v2_adPlanInfo_adPlanList(self): """ 查询策略列表 :return: """ func_name = sys._getframe().f_code.co_name res = self.get_result(func_name) totalCount = res[0].json()['data']['totalCount'] ad_plan_list = res[0].json()['data']['list'] gl.set_value('ad_plan_list', ad_plan_list) expect_result = self.get_expect_result(func_name) self.assertTrue(eval(expect_result))
def test_urine_v2_goodsInfo_queryGoodsInfos(self): """ 查询商品信息 :return: """ func_name = sys._getframe().f_code.co_name res = self.get_result(func_name) actual_result = res[0].json()['errmsg'] row = self.get_case_row_index(func_name) expect_result = self.get_expect_result(func_name) self.update_result(row, actual_result, expect_result) gl.set_value('goods_list', res[0].json()['data']['list'])
def test_urine_v2_adImageStrategy_listByPage(self): """ 查询图片广告策略列表 :return: """ func_name = sys._getframe().f_code.co_name res = self.get_result(func_name) actual_result = res[0].json()['errmsg'] gl.set_value('adPlanList', res[0].json()['data']['list']) row = self.get_case_row_index(func_name) expect_result = self.get_expect_result(func_name) self.update_result(row, actual_result, expect_result)
def test_urine_v2_MacActvImageMainInfo_query(self): """ 查询广告图组列表 :return: """ func_name = sys._getframe().f_code.co_name res = self.get_result(func_name) actual_result = res[0].json()['errmsg'] row = self.get_case_row_index(func_name) expect_result = self.get_expect_result(func_name) gl.set_value('adImagePackList', res[0].json()['data']['list']) self.update_result(row, actual_result, expect_result)
def test_urine_v2_bannerInfo_list(self): """ 小程序banner列表 :return: """ func_name = sys._getframe().f_code.co_name res = self.get_result(func_name) actual_result = res[0].json()['errmsg'] row = self.get_case_row_index(func_name) expect_result = self.get_expect_result(func_name) self.update_result(row, actual_result, expect_result) gl.set_value('banner_list', res[0].json()['data'])
def test_urine_v2_activityInfo_list(self): """ 运营活动配置列表 :return: """ func_name = sys._getframe().f_code.co_name res = self.get_result(func_name) expect_result = self.get_expect_result(func_name) activityInfo_list = res[0].json()['data'] actual_result = res[0].json()['errmsg'] self.assertIn(actual_result, expect_result) self.assertIsNotNone(activityInfo_list) gl.set_value('activityInfo_list', activityInfo_list)
def test_urine_v2_urineInfoList_getRecords(self): """ 查询尿液健康检测记录 :return: """ func_name = sys._getframe().f_code.co_name row = self.get_case_row_index(func_name) query_urineinfo = self.get_request_data(func_name) urineinfo_copy = query_urineinfo.copy() for k in urineinfo_copy.keys(): urineinfo_copy[k] = None for data in ['pageNum', 'pageSize', 'totalCount']: urineinfo_copy[data] = query_urineinfo[data] query = urineinfo_copy """默认查询所有记录""" res = self.get_result(func_name, var_params=urineinfo_copy) totalCount = res[0].json()['data']['totalCount'] expect_result = self.get_expect_result(func_name) default_result = eval(expect_result) self.assertTrue(default_result) """根据手机号查询""" query['phone'] = query_urineinfo['phone'] res = self.get_result(func_name, var_params=query) totalCount = res[0].json()['data']['totalCount'] query['pageSize'] = totalCount res = self.get_result(func_name, var_params=query) check_list = res[0].json()['data']['list'] for check in check_list: self.assertEqual(query['phone'], check['phone']) """根据手机号、检测机器查询""" query['machineID'] = query_urineinfo['machineID'] res = self.get_result(func_name, var_params=query) check_list = res[0].json()['data']['list'] for check in check_list: self.assertEqual(query['phone'], check['phone']) self.assertEqual(query['machineID'], check['machineID']) """根据手机号、检测机器、检测状态查询""" query['checkStatus'] = query_urineinfo['checkStatus'] res = self.get_result(func_name, var_params=query) check_list = res[0].json()['data']['list'] for check in check_list: self.assertEqual(query['phone'], check['phone']) self.assertEqual(query['machineID'], check['machineID']) self.assertEqual(query['checkStatus'], check['checkStatus']) urineinfolist = res[0].json()['data']['list'] for urineinfo in urineinfolist: if urineinfo['checkStatus'] != 1: urineinfolist.remove(urineinfo) gl.set_value('urineinfolist', urineinfolist)
def test_urine_v2_adminInfo_login(self): """ 登录系统 :return: """ func_name = sys._getframe().f_code.co_name gl._init() res = self.get_result(func_name) actual_result = res[0].json()['errmsg'] row = self.get_case_row_index(func_name) expect_result = self.get_expect_result(func_name) self.update_result(row, actual_result, expect_result) hash = self.upload()['hash'] gl.set_value('cookies', res[1]) gl.set_value('hash', hash)
def test_urine_v2_machineInfo_addMachine(self): """ 添加机器 :return: """ func_name = sys._getframe().f_code.co_name row = self.get_case_row_index(func_name) add_machine_info = self.get_request_data(func_name) gl.set_value('machineID', add_machine_info['machineID']) add_machine_info['addTime'] = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.localtime()) res = self.get_result(func_name, var_params=add_machine_info) actual_result = res[0].json()['data'] expect_result = self.get_expect_result(func_name) self.update_result(row, actual_result, expect_result)
def test_urine_v2_goodsInfo_updateGoodsInfo(self): """ 更新商品信息 :return: """ func_name = sys._getframe().f_code.co_name row = self.get_case_row_index(func_name) update_goods_info = self.get_request_data(func_name) goods_name = update_goods_info['goodsName'] # goods_list = self.get_depend_params(func_name) goods_list = gl.get_value('goods_list') for goods in goods_list: if goods['goodsName'] == goods_name: gl.set_value('goods_info', goods) for data in update_goods_info: gl.get_value('goods_info')[data] = update_goods_info[data] res = self.get_result(func_name, var_params=gl.get_value('goods_info')) actual_result = res[0].json()['data'] expect_result = self.get_expect_result(func_name) self.update_result(row, actual_result, expect_result)
def test_urine_v2_adPlanInfo_canBeDelete(self): """ 视频广告策略能否被删除 :return: """ func_name = sys._getframe().f_code.co_name ad_plan_name = self.get_request_data(func_name) plan_name = ad_plan_name['planName'] ad_plan_list = gl.get_value('ad_plan_list') expect_result = self.get_expect_result(func_name) key_id_list = [] for ad in ad_plan_list: if ad['planName'] == plan_name: key_id = {} key_id['keyId'] = ad['keyID'] res = self.get_result(func_name, var_params=key_id) actual_result = res[0].json()['errmsg'] self.assertIn(actual_result, expect_result) data = res[0].json()['data'] self.assertEqual(data, 0) key_id_list.append(key_id['keyId']) gl.set_value('key_id_list', key_id_list)
def test_urine_v2_machineInfo_machineInfoList(self): """ 查询机器 :return: """ func_name = sys._getframe().f_code.co_name row = self.get_case_row_index(func_name) query_machineinfo = self.get_request_data(func_name) machineinfo_copy = query_machineinfo.copy() for k in machineinfo_copy.keys(): machineinfo_copy[k] = None for data in ['pageNum', 'pageSize', 'totalCount']: machineinfo_copy[data] = query_machineinfo[data] query = machineinfo_copy """默认查询所有机器""" res = self.get_result(func_name, var_params=machineinfo_copy) totalCount = res[0].json()['data']['totalCount'] assert totalCount > 0 """根据机器编号查询""" query['machineID'] = query_machineinfo['machineID'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] expect_result = self.get_expect_result(func_name) self.assertIn(actual_machineinfo['machineID'], expect_result) gl.set_value('activityId', res[0].json()['data']['list'][0]['activityId']) gl.set_value('keyID', res[0].json()['data']['list'][0]['keyID']) """根据机器编号、网络状态查询""" query['isOnline'] = query_machineinfo['isOnline'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) """根据机器编号、网络状态、故障状态查询""" query['troubleStatus'] = query_machineinfo['troubleStatus'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) self.assertEqual(query['troubleStatus'], actual_machineinfo['troubleStatus']) """根据机器编号、网络状态、故障状态、1号库存查询""" query['firstStockStatus'] = query_machineinfo['firstStockStatus'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) self.assertEqual(query['troubleStatus'], actual_machineinfo['troubleStatus']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstNoGoods']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstOutOfstock']) """根据机器编号、网络状态、故障状态、1号库存、2号库存查询""" query['secondStockStatus'] = query_machineinfo['secondStockStatus'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) self.assertEqual(query['troubleStatus'], actual_machineinfo['troubleStatus']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstNoGoods']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstOutOfstock']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondNoGoods']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondOutOfstock']) """根据机器编号、网络状态、故障状态、1号库存、2号库存、启用状态查询""" query['isEnable'] = query_machineinfo['isEnable'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) self.assertEqual(query['troubleStatus'], actual_machineinfo['troubleStatus']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstNoGoods']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstOutOfstock']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondNoGoods']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondOutOfstock']) self.assertEqual(query['isEnable'], actual_machineinfo['isEnable']) """根据机器编号、网络状态、故障状态、1号库存、2号库存、启用状态、城市查询""" query['cityID'] = query_machineinfo['cityID'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) self.assertEqual(query['troubleStatus'], actual_machineinfo['troubleStatus']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstNoGoods']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstOutOfstock']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondNoGoods']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondOutOfstock']) self.assertEqual(query['isEnable'], actual_machineinfo['isEnable']) self.assertEqual(query['cityID'], actual_machineinfo['cityID']) """根据机器编号、网络状态、故障状态、1号库存、2号库存、启用状态、城市、商圈查询""" query['areaID'] = query_machineinfo['areaID'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) self.assertEqual(query['troubleStatus'], actual_machineinfo['troubleStatus']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstNoGoods']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstOutOfstock']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondNoGoods']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondOutOfstock']) self.assertEqual(query['isEnable'], actual_machineinfo['isEnable']) self.assertEqual(query['cityID'], actual_machineinfo['cityID']) self.assertEqual(query['areaID'], actual_machineinfo['areaID']) """根据机器编号、网络状态、故障状态、1号库存、2号库存、启用状态、城市、商圈、楼宇查询""" query['buildingID'] = query_machineinfo['buildingID'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) self.assertEqual(query['troubleStatus'], actual_machineinfo['troubleStatus']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstNoGoods']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstOutOfstock']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondNoGoods']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondOutOfstock']) self.assertEqual(query['isEnable'], actual_machineinfo['isEnable']) self.assertEqual(query['cityID'], actual_machineinfo['cityID']) self.assertEqual(query['areaID'], actual_machineinfo['areaID']) self.assertEqual(query['buildingID'], actual_machineinfo['buildingID']) """根据机器编号、网络状态、故障状态、1号库存、2号库存、启用状态、城市、商圈、楼宇、卫生间查询""" query['sexType'] = query_machineinfo['sexType'] res = self.get_result(func_name, var_params=query) actual_machineinfo = res[0].json()['data']['list'][0] self.assertIn(actual_machineinfo['machineID'], expect_result) self.assertEqual(query['isOnline'], actual_machineinfo['isOnline']) self.assertEqual(query['troubleStatus'], actual_machineinfo['troubleStatus']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstNoGoods']) self.assertEqual(query['firstStockStatus'], actual_machineinfo['firstOutOfstock']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondNoGoods']) self.assertEqual(query['secondStockStatus'], actual_machineinfo['secondOutOfstock']) self.assertEqual(query['isEnable'], actual_machineinfo['isEnable']) self.assertEqual(query['cityID'], actual_machineinfo['cityID']) self.assertEqual(query['areaID'], actual_machineinfo['areaID']) self.assertEqual(query['buildingID'], actual_machineinfo['buildingID']) self.assertEqual(query['sexType'], actual_machineinfo['sexType'])
#coding:utf-8 """ 运行测试脚本 """ import pytest from run.common_test_set import UrineWebInterfaceTestCase import run.globalvar as gl if __name__ == '__main__': gl._init() gl.set_value('pass_case_list', []) gl.set_value('fail_case_list', []) # runner.add_case_dir(r'C:\Users\Doctorwork\PycharmProjects\APITestFrame\run') pytest.main([ '-v', '-s', 'run/geekbang', '--html=report/接口自动化测试报告.html', '--self-contained-html', '--cov=./run/' ]) # pytest.main(['-v', 'algorithm_correlation','--html=report/test2.html', '--self-contained-html', '--cov=./']) # runner.add_case_dir(r'C:\Users\Doctorwork\PycharmProjects\APITestFrame\run\a_login_system') # runner.add_case_dir(r'C:\Users\Doctorwork\PycharmProjects\APITestFrame\run\algorithm_correlation') # runner.run_test(report_title='健康终端管理台接口测试报告') UrineWebInterfaceTestCase().send_email()