Exemple #1
0
    def run(self):
        # 读json文件,取测试数据
        api_file = Tool.read_json("interface")
        test_data_file = Tool.read_json("test_data")
        expect_data_file = Tool.read_json("expect_data")

        # 获取接口的具体信息,循环读取某一接口
        api_list = api_file["api_list"]
        for api in api_list:
            url = api["url"]
            method = api["method"]
            need_login = api["need_login"]
            test_data = api["test_data"]
            expect_data_addr = api["expect_data"]
            expect_data = expect_data_file[expect_data_addr]
            print("期望结果", expect_data)
            params = test_data_file[test_data]

            if method == "get":
                result = self.net.get(url, params)
                result_dict = json.loads(result.content)
                print("实际结果", result_dict)
                print("开始比较实际结果和期望值")
                flag = self.check.comparison_result( expect_data, result_dict)
                self.write.write_report(url, params, expect_data, result_dict, flag)
Exemple #2
0
    def write_report(self, url, params, expect, actual, flag):
        open_file = Tool.read_excel("report")
        table = open_file.sheets()[0]
        n = table.nrows
        wb = copy(open_file)
        write_sheet = wb.get_sheet(0)

        params = json.dumps(params, ensure_ascii=False)  # 默认不将中文编码
        # print("写报告测试参数", params)
        expect = json.dumps(expect, ensure_ascii=False)
        expect = Tool.json_converted_str(expect)
        # print("写报告期望结果", expect)
        actual = json.dumps(actual, ensure_ascii=False)
        actual = Tool.json_converted_str(actual)
        # print("写报告实际结果", actual)

        style = xlwt.easyxf('align: wrap on')  # 数据写入excel自动换行
        write_sheet.col(2).width = (30 * 367)
        write_sheet.col(3).width = (30 * 367)

        write_sheet.write(n, 0, url)
        write_sheet.write(n, 1, params)
        write_sheet.write(n, 2, expect, style)
        write_sheet.write(n, 3, actual, style)

        # result_sheet.write(0, 1, txt1.decode('utf-8'))
        if flag == 1:
            write_sheet.write(n, 4, u"测试通过")
            print("测试通过")
        else:
            write_sheet.write(n, 4, u"测试失败")
            print("测试失败")
        wb.save(r"../test_report/report.xls")
        print("报告书写完成")
Exemple #3
0
 def cancel(self, iid, tradeId):
     data = {}
     data['id'] = Tool.getTradeId(self.modelName)
     data['from'] = self.srvChannel
     data['iid'] = iid
     data['tradeId'] = tradeId
     jsonData = JSON.encode(data)
     print jsonData
     self.sender.publish(self.TUNNEL_CANCEL, jsonData)
Exemple #4
0
 def ioc(self, iid, price, volume, isOpen, isBuy, isToday):
     tradeId = Tool.getTradeId(self.modelName)
     self.tradeCallbackTick[tradeId] = 0
     self.tradeInfo[tradeId] = {
         'tradeId': tradeId,
         'price': price,
         'volume': volume,
         'type': 'ioc',
         'isBuy': isBuy
     }
     self.tradeIds.append(tradeId)
     return tradeId
Exemple #5
0
 def fok(self, iid, price, volume, isOpen, isBuy, isToday):
     tradeId = Tool.getTradeId(self.modelName)
     r = random.randint(1, 10) if self.isRandom else 10
     self.tradeCallbackTick[tradeId] = 0
     self.tradeInfo[tradeId] = {
         'tradeId': tradeId,
         'price': price,
         'volume': volume,
         'type': 'fok',
         'r': r
     }
     self.tradeIds.append(tradeId)
     return tradeId
Exemple #6
0
 def __trade(self, tunnel, iid, price, volume, isOpen, isBuy, isToday):
     data = {}
     data['id'] = Tool.getTradeId(self.srvChannel)
     data['from'] = self.srvChannel
     data['iid'] = iid
     data['price'] = price
     data['total'] = volume
     data['isOpen'] = int(isOpen)
     data['isBuy'] = int(isBuy)
     data['isToday'] = int(isToday)
     jsonData = JSON.encode(data)
     print jsonData
     self.sender.publish(tunnel, jsonData)
     return data['id']