Ejemplo n.º 1
0
 def test_003_delete_curriculum(self, data):
     method = data['method']
     url = self.url + data['url']
     # logger.info(url)
     rely_num = data['rely_num']  # 依赖接口所在行数
     res_data = get_specific_num(num=rely_num[0] - 1)  # 找到对应行数,取出依赖接口返回值
     # logger.info(res_data)
     curriculum_id = res_data['data']['id']  # 取出依赖Id
     send_data = data['send_data']
     send_data = self.replace_dict(send_data, '#curriculum_id',
                                   curriculum_id)
     # logger.info(send_data)
     assert_info = data['assert_info']
     rownum = data['rownum']
     # logger.info(self.headers)
     if method == 'post':
         r = SendRequest().send_json_post(url=url,
                                          dict=send_data,
                                          header=self.headers)
     if method == 'get':
         r = SendRequest().send_get_request(url=url, header=self.headers)
     # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
     write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
     self.assertEqual(r['code'], assert_info['code'])
     self.assertEqual(r['msg'], assert_info['msg'])
Ejemplo n.º 2
0
 def test_007_save_functions(self, data):
     method = data['method']
     url = data['url']
     send_data = data['send_data']
     rely_num = data['rely_num']  # 依赖接口所在行数
     product_list_data = get_specific_num(num=rely_num[0] -
                                          1)  # 找到对应行数,取出依赖接口返回值
     # logger.info(res_data)
     product_id = product_list_data['data'][0]['id']  # 取出依赖Id
     categoryids = get_specific_num(num=rely_num[1] - 1)
     normal = [categoryids['data'][0]['id']]
     lis = [product_id, normal]
     keys = ['#id', '#normal']
     for i in range(len(lis)):
         send_data = self.replace_dict(send_data, keys[i], lis[i])
     url = self.url + url
     assert_info = data['assert_info']
     rownum = data['rownum']
     # logger.info(self.headers)
     if method == 'post':
         r = SendRequest().send_json_post(url=url,
                                          dict=send_data,
                                          header=self.headers)
     if method == 'get':
         r = SendRequest().send_get_request(url=url, header=self.headers)
     # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
     write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
     self.assertEqual(r['code'], assert_info['code'])
     self.assertEqual(r['msg'], assert_info['msg'])
Ejemplo n.º 3
0
 def test_001_add_curriculum(self, data):
     method = data['method']
     url = self.url + data['url']
     # logger.info(url)
     label = fake.word()  # 生成随机课程名称
     name = "脚本修改" + fake.word() + str(random.randint(
         1, 1000)) + "课程"  # 生成随机Name  # 生成随机课程标签
     objector = fake.word()  # 生成随机目标学员
     income = fake.sentence(nb_words=6, variable_nb_words=True)  # 生成随机学习目标
     intro = fake.sentence(nb_words=6, variable_nb_words=True)  # 生成随机课程综述
     lis = [label, name, objector, income, intro]
     keys = ['#label', '#name', '#objector', '#income', '#intro']
     send_data = data["send_data"]
     for i in range(5):
         send_data = self.replace_dict(send_data, keys[i], lis[i])  # 替换请求值
     # logger.info(send_data)
     assert_info = data['assert_info']
     rownum = data['rownum']  # 获取当前接口所在行数
     # logger.info(self.headers)
     if method == 'post':
         r = SendRequest().send_json_post(url=url,
                                          dict=send_data,
                                          header=self.headers)
     if method == 'get':
         r = SendRequest().send_get_request(url=url, header=self.headers)
     # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
     write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
     self.assertEqual(r['code'], assert_info['code'])
     self.assertEqual(r['msg'], assert_info['msg'])
Ejemplo n.º 4
0
    def send_request_all(self, data, random_parameters=None):
        """
        :param data: 从data文件中读取到的对应接口数据
        :param random_parameters: 除了从依赖接口获取依赖参数替换外,需要随机生成参数替换时,从这里传
        :return: null
        """
        if 'http' in data['url']:
            url = data['url']
        else:
            url = self.url + data['url']
        rownum = data['rownum']
        method = data['method']
        send_data = data['send_data']
        keys = data['update_data']  # 获取请求参数需要替换的参数标示列表
        content_type = data['Content-Type']
        if content_type is None or content_type == '':
            content_type = 'application/json'
        self.headers['Content-Type'] = content_type
        if not random_parameters is None:
            send_data = self.update_data2(send_data,
                                          random_parameters)  # 替换发送的数据
        if "rely_num" not in data:
            r = self.send_request(method,
                                  url=url,
                                  data=send_data,
                                  header=self.headers)
        else:
            rely_num = data['rely_num']  # 依赖接口名称
            rely_parameter = data['rely_parameter']  # 依赖接口参数
            values = finddata(
                case_name=rely_num,
                rely_parameter=rely_parameter)  # 通过依赖接口名称和对应的依赖参数,提取依赖值
            if method == 'post':
                k_v_list = self.construct_dict(
                    keys, values)  # 组成替换参数字典{"参数标示":"提取到的值"}
                send_data = self.update_data2(send_data, [k_v_list])  # 替换发送的数据
                r = self.send_request(method,
                                      url=url,
                                      data=send_data,
                                      header=self.headers)
            else:
                url = self.replace_str(url, keys[0], values)
                r = self.send_request(method,
                                      url=url,
                                      data=send_data,
                                      header=self.headers)
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值

        return r
Ejemplo n.º 5
0
 def test_login(self, data):
     method = data['method']
     url = self.url + data['url']
     send_data = data['send_data']
     assert_info = data['assert_info']
     rownum = data['rownum']
     # logger.info(url)
     # logger.info(send_data)
     # logger.info(self.headers)
     if method == 'post':
         r = SendRequest().send_json_post(url=url, dict=send_data, header=self.headers)
     if method == 'get':
         r = SendRequest().send_get_request(url=url,header=self.headers)
     # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
     write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 接口返回值写入表格
     self.assertEqual(r['status'], assert_info['status'])            # 断言status==status
     # self.assertEqual(r['info'], assert_info['info'])                # 断言info==info
Ejemplo n.º 6
0
 def test_002_get_product_list(self, data):
     method = data['method']
     url = data['url']
     url = self.url + url
     assert_info = data['assert_info']
     send_data = data['send_data']
     rownum = data['rownum']
     # logger.info(self.headers)
     if method == 'post':
         r = SendRequest().send_json_post(url=url,
                                          dict=send_data,
                                          header=self.headers)
     if method == 'get':
         r = SendRequest().send_get_request(url=url, header=self.headers)
     # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
     write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
     self.assertEqual(r['code'], assert_info['code'])
     self.assertEqual(r['msg'], assert_info['msg'])
Ejemplo n.º 7
0
 def test_005_upload(self, data):
     self.headers = None
     url = data['url']
     rely_num = data['rely_num']  # 依赖接口名称
     rely_parameter = data['rely_parameter']  # 依赖接口参数
     keys = data['update_data']
     values = finddata(case_name=rely_num, rely_parameter=rely_parameter)
     k_v_list = self.send_requests.construct_dict(keys, values)
     send_data = data['send_data']
     send_data = self.send_requests.update_data2(send_data, [k_v_list])
     rownum = data['rownum']
     r = self.send_requests.send_file_data(
         url=url,
         dict=send_data,
         file_name={"file": ("img", open(r"D:/6.png", "rb"), "img/png")})
     write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
     self.assertTrue('hash' in json.dumps(r, indent=2, ensure_ascii=False))
     self.assertTrue('key' in json.dumps(r, indent=2, ensure_ascii=False))
Ejemplo n.º 8
0
 def test_001_add_project(self, data):
     method = data['method']
     url = data['url']
     url = self.url + url
     code = fake_en.word() + str(random.randint(1, 1000))
     name = fake.word() + str(random.randint(1, 1000)) + '- 产品'
     send_data = data["send_data"]
     send_data = self.replace_dict(send_data, '#code', code)
     send_data = self.replace_dict(send_data, '#name', name)
     assert_info = data['assert_info']
     rownum = data['rownum']
     # logger.info(self.headers)
     if method == 'post':
         r = SendRequest().send_json_post(url=url,
                                          dict=send_data,
                                          header=self.headers)
     if method == 'get':
         r = SendRequest().send_get_request(url=url, header=self.headers)
     # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
     write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
     self.assertEqual(r['code'], assert_info['code'])
     self.assertEqual(r['msg'], assert_info['msg'])
Ejemplo n.º 9
0
 def test_006_get_categoryids(self, data):
     method = data['method']
     url = data['url']
     send_data = data['send_data']
     rely_num = data['rely_num']  # 依赖接口所在行数
     res_data = get_specific_num(num=rely_num[0] - 1)  # 找到对应行数,取出依赖接口返回值
     # logger.info(res_data)
     category_ids = res_data['data'][0]['id']  # 取出依赖Id
     url = self.url + url + category_ids  # 组成Url
     assert_info = data['assert_info']
     rownum = data['rownum']
     # logger.info(self.headers)
     if method == 'post':
         r = SendRequest().send_json_post(url=url,
                                          dict=send_data,
                                          header=self.headers)
     if method == 'get':
         r = SendRequest().send_get_request(url=url, header=self.headers)
     # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
     write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
     self.assertEqual(r['code'], assert_info['code'])
     self.assertEqual(r['msg'], assert_info['msg'])