def test_adv(self): # 遍历文件生成数组 fileUtil = File.ReadFile() testpath = r"D:\work" fileList = fileUtil.getFileList(testpath, []) # 上传文件到cos for e in fileList: tecentUtil.uploadImg(e[1], e[0]) # 生成测试数据 imgList = tecentUtil.getImgList(fileList) # 循环请求 for e in imgList: print(e) imgUrl = e[1] testCase = e[0] url = baseUrl + "/index.php?c=goods" cmd = "11552" data = { "json": [{ "cmd": cmd, "type": 0, "image_url": imgUrl, "user_id": user_id, "user_name": user_name, "token": token }] } # headers = constant.env["headers"] print( cmd + testCase + "url:" + url, ",request data:" + str(data).replace("\'", "\"").replace(r"\\", "\\")) j = httpUtil.postJson(url, data, headers) js = j[cmd] exc.writeXls(path, [ cmd, e[0], js["statusCode"], js["qtime"], js["errorMsg"], url, str(data).replace("\'", "\"").replace(r"\\", "\\") ]) if js["statusCode"] != 0: break # 上传图片至图谱获取返回结果 try: tpUrl = "http://test-api2.ppwang.com:8800/index.php?c=test&m=requestTupuCheakTest&type=0&imageUrl=" + e[ 1] res = requests.get(tpUrl) r = str((res.text)[:-5]) js = json.loads(r) js = json.loads(js["json"]) tpData = [] if js["56a8645b0c800bff40990cf1"]["statistic"] != None: tpData.append( ["广告识别", js["56a8645b0c800bff40990cf1"]["statistic"]]) if js["5acb135cc40c6772b10ec73a"]["statistic"] != None: tpData.append( ["暴恐识别", js["5acb135cc40c6772b10ec73a"]["statistic"]]) if js["54bcfc6c329af61034f7c2fc"]["statistic"] != None: tpData.append( ["色情识别", js["54bcfc6c329af61034f7c2fc"]["statistic"]]) exc.writeXls(path, [ "。", e[0], str(res.status_code), "。", "。", str(tpUrl), str(tpData) ]) exc.writeXls(path, [""]) time.sleep(1) except Exception as e: print(e)
import os from util import File testpath = r"D:\work\色情暴恐广告监测测试数据" fileUtil=File.ReadFile() fileList=fileUtil.renameFile(testpath)