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'])
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'])
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'])
def test_api(self, data): method = data['method'] url = self.url + '/api' + data['url'] send_data = data['send_data'] assert_info = data['assert_info'] 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) self.assertEqual(r['code'], assert_info['code']) self.assertEqual(r['msg'], assert_info['msg'])
def test_api(self, data): method = data['method'] url = self.url + '/api' + data['url'] send_data = data['send_data'] assert_info = data['assert_info'] 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)) self.assertEqual(r['code'], assert_info['code']) self.assertEqual(r['msg'], assert_info['msg'])
def setUp(self): self.url = ConfigInit.url self.headers = {} self.send_requests = SendRequest(self.url, self.headers) logger.info( '############################### START ###############################' )
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
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'])
def setUp(self): self.url = ConfigInit.url self.headers = { 'JK-TOKEN': self.token, 'JK-USER-ID': str(self.user_id) } self.send_requests = SendRequest(self.url, self.headers) logger.info( '############################### START ###############################' )
def login_func(cls, account='18175516432', pw='hb123456'): """封装登录函数""" send_data = {"account": account, "password": pw, "login_type": 1} url = ConfigInit.login_url + '/id_v2_5/user/login' headers = {'Content-Type': 'application/json'} r = SendRequest().send_json_post(url=url, dict=send_data, header=headers) token = r['data']['token'] user_id = r['data']['basic']['id'] return token, user_id
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'])
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'])
def login_func(cls, account='*****@*****.**', pw='q5310543'): """封装登陆函数""" send_data = { "account": account, "password": pw, "platform_code": "PLATFORM", "app_id": "a1287a3837f640e0" } url = ConfigInit.login_url + '/login' logger.info(url) headers = {'Content-Type': 'application/json'} logger.info(send_data) logger.info(headers) r = SendRequest().send_json_post(url=url, dict=send_data, header=headers) logger.info(r) token = r['data']['accessToken'] return token
def login_func(cls, account='13800138907', password='******'): """封装登录函数""" send_data = {'mobile': account, 'password': password} url = ConfigInit.url + 'member/login' logger.info(url) headers = { 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36' } logger.info(send_data) logger.info(headers) r = SendRequest().send_json_post(url=url, dict=send_data, header=headers) logger.info(r) # print(r) token = r['data']['token'] return token