def retrieve(self, request, *args, **kwargs): testcase = self.get_object() testcase_include = json.loads(testcase.include, encoding='utf-8') testcase_request = json.loads(testcase.request, encoding='utf-8') testcase_request_datas = testcase_request.get('test').get('request') # validate testcase_validate = testcase_request.get('test').get('validate') # 处理params参数 testcase_request_params = testcase_request_datas.get('params') testcase_request_params_list = handle_datas.handle_data4(testcase_request_params) # 处理用例的header列表 testcases_headers = testcase_request_datas.get('headers') testcase_request_headers_list = handle_datas.handle_data4(testcases_headers) # 处理用例variables变量列表 testcase_variables = testcase_request.get('test').get('variables') testcase_variables_list = handle_datas.handle_data2(testcase_variables) # 处理form表单数据 testcase_form_datas = testcase_request_datas.get('data') testcase_form_datas_list = handle_datas.handle_data6(testcase_form_datas) # 处理json格式数据 testcase_request_json = json.dumps(testcase_request_datas.get('json'), ensure_ascii=False) # 处理extract数据 testcase_extract = testcase_request.get('test').get('extract') testcase_extract_list = handle_datas.handle_data3(testcase_extract) # 处理parameters数据(处理参数化数据) # 在平台使用时,运用嵌套列表的列表 testcase_parameters = testcase_request.get('test').get('parameters') testcase_parameters_list = handle_datas.handle_data3(testcase_parameters) # 处理setupHooks数据 testcase_setup_hooks = testcase_request.get('test').get('setup_hooks') testcase_setup_hooks_list = handle_datas.handle_data5(testcase_setup_hooks) # 处理teardownHooks数据 testcase_teardown_hooks = testcase_request.get('test').get('teardown_hooks') testcase_teardown_hooks_list = handle_datas.handle_data5(testcase_teardown_hooks) web_selected_configure_id = testcase_include.get('config') web_selected_interface_id = testcase.interface_id web_selected_project_id = Interfaces.objects.get(id=web_selected_interface_id).project_id web_selected_testcase_id = testcase_include.get('testcases') datas = { "author": testcase.author, "testcase_name": testcase.name, "selected_interface_id": web_selected_interface_id, "selected_project_id": web_selected_project_id, "selected_configure_id": web_selected_configure_id, "selected_testcase_id": web_selected_testcase_id, "method": testcase_request_datas.get("method"), "url": testcase_request_datas.get("url"), "param": testcase_request_params_list, "header": testcase_request_headers_list, "variable": testcase_form_datas_list, "jsonVariable": testcase_request_json, "extract": testcase_extract_list, "validate": testcase_validate, "globalVar": testcase_variables_list, "parameterized": testcase_parameters_list, "setupHooks": testcase_setup_hooks_list, "teardownHooks": testcase_teardown_hooks_list, } return Response(datas)
def retrieve(self, request, *args, **kwargs): testcase_obj = self.get_object() #用例前置信息 testcase_include = json.loads(testcase_obj.include, encoding='utf-8') #用例请求信息 testcase_request = json.loads(testcase_obj.request, encoding='utf-8') testcase_request_datas = testcase_request.get('test').get('request') #处理用例的validate列表 testcase_validate = testcase_request.get('test').get('validate') testcase_validate_list = handle_datas.handle_data3(testcase_validate) #处理用例的param数据 testcase_param = testcase_request_datas.get('param') testcase_param_list = handle_datas.handle_data1(testcase_param) #处理用例的header数据 testcase_headers = testcase_request_datas.get('headers') testcase_headers_list = handle_datas.handle_data1(testcase_headers) #处理用例variables变量数据 testcase_variables = testcase_request.get('test').get('variables') testcase_variables_list = handle_datas.handle_data2(testcase_variables) #处理from表单数据 testcase_from_datas = testcase_request_datas.get('data') testcase_from_datas_list = handle_datas.handle_data4(testcase_from_datas) #处理json数据 testcase_json_datas = json.dumps(testcase_request_datas.get('json'), ensure_ascii=False) #处理extract数据 testcase_extract_datas = testcase_request.get('test').get('extract') testcase_extract_datas_list = handle_datas.handle_data5(testcase_extract_datas) #处理parameters数据 testcase_parameters_datas = testcase_request.get('test').get('parameters') testcase_parameters_datas_list = handle_datas.handle_data5(testcase_parameters_datas) #处理setupHooks数据 testcase_setup_hooks_datas = testcase_request.get('test').get('setup_hooks') testcase_setup_hooks_datas_list = handle_datas.handle_data6(testcase_setup_hooks_datas) #处理teardownHooks数据 testcase_teardown_hooks_datas = testcase_request.get('test').get('teardown_hooks') testcase_teardown_hooks_datas_list = handle_datas.handle_data6(testcase_teardown_hooks_datas) selected_configure_id = testcase_include.get('config') selected_interface_id = testcase_obj.interface_id selected_project_id = Interfaces.objects.get(id=selected_interface_id).project_id selected_testcase_id = testcase_include.get('testcases') datas = { 'author': testcase_obj.author, 'testcase_name': testcase_obj.name, 'selected_configure_id': selected_configure_id, 'selected_interface_id': selected_interface_id, 'selected_project_id': selected_project_id, 'selected_testcase_id': selected_testcase_id, 'method': testcase_request_datas.get('method'), 'url': testcase_request_datas.get('url'), 'param': testcase_param_list, 'header': testcase_headers_list, 'variable': testcase_from_datas_list, # form表单数据 'jsonVariable': testcase_json_datas, 'extract': testcase_extract_datas_list, 'validate': testcase_validate_list, 'globalVar': testcase_variables_list, 'parameterized': testcase_parameters_datas_list, 'setupHooks': testcase_setup_hooks_datas_list, 'teardownHooks': testcase_teardown_hooks_datas_list, } return Response(datas)
def retrieve(self, request, *args, **kwargs): """获取用例详情信息""" # Testcase对象 testcase_obj = self.get_object() # 用例前置信息 # testcase_include = eval(testcase_obj.include) # 用json.loads将数据库tb_testcases中include字段的json 格式的字符串转化为python中的字典。 testcase_include = json.loads(testcase_obj.include, encoding='utf-8') # 用例请求信息 # testcase_request = eval(testcase_obj.request) testcase_request = json.loads(testcase_obj.request, encoding='utf-8') # testcase_request取出后,只是一个大字典,先获取最外层key:test,再获取里层key:request testcase_request_datas = testcase_request.get('test').get('request') # 处理用例的validate列表 # 将[{'check': 'status_code', 'expected':200, 'comparator': 'equals'}] # 转化为[{key: 'status_code', value: 200, comparator: 'equals', param_type: 'string'}] testcase_validate = testcase_request.get('test').get('validate') testcase_validate_list = handle_datas.handle_data1(testcase_validate) # 处理用例的param数据 testcase_params = testcase_request_datas.get('params') testcase_params_list = handle_datas.handle_data4(testcase_params) # 处理用例的header列表 testcase_headers = testcase_request_datas.get('headers') testcase_headers_list = handle_datas.handle_data4(testcase_headers) # 处理用例variables变量列表 testcase_variables = testcase_request.get('test').get('variables') testcase_variables_list = handle_datas.handle_data2(testcase_variables) # 处理form表单数据 testcase_form_datas = testcase_request_datas.get('data') testcase_form_datas_list = handle_datas.handle_data6( testcase_form_datas) # 处理json数据 # testcase_json_datas = str(testcase_request_datas.get('json')) testcase_json_datas = json.dumps(testcase_request_datas.get('json'), ensure_ascii=False) # 处理extract数据 testcase_extract_datas = testcase_request.get('test').get('extract') testcase_extract_datas_list = handle_datas.handle_data3( testcase_extract_datas) # 处理parameters数据 testcase_parameters_datas = testcase_request.get('test').get( 'parameters') testcase_parameters_datas_list = handle_datas.handle_data3( testcase_parameters_datas) # 处理setupHooks数据 testcase_setup_hooks_datas = testcase_request.get('test').get( 'setup_hooks') testcase_setup_hooks_datas_list = handle_datas.handle_data5( testcase_setup_hooks_datas) # 处理teardownHooks数据 testcase_teardown_hooks_datas = testcase_request.get('test').get( 'teardown_hooks') testcase_teardown_hooks_datas_list = handle_datas.handle_data5( testcase_teardown_hooks_datas) selected_configure_id = testcase_include.get('config') selected_interface_id = testcase_obj.interface_id selected_project_id = Interfaces.objects.get( id=selected_interface_id).project_id selected_testcase_id = testcase_include.get('testcases') datas = { "author": testcase_obj.author, "testcase_name": testcase_obj.name, "selected_configure_id": selected_configure_id, "selected_interface_id": selected_interface_id, "selected_project_id": selected_project_id, "selected_testcase_id": selected_testcase_id, "method": testcase_request_datas.get('method'), "url": testcase_request_datas.get('url'), "param": testcase_params_list, "header": testcase_headers_list, "variable": testcase_form_datas_list, # form表单请求数据 "jsonVariable": testcase_json_datas, "extract": testcase_extract_datas_list, "validate": testcase_validate_list, "globalVar": testcase_variables_list, # 变量 "parameterized": testcase_parameters_datas_list, "setupHooks": testcase_setup_hooks_datas_list, "teardownHooks": testcase_teardown_hooks_datas_list, } return Response(datas)
def retrieve(self, request, *args, **kwargs): """获取用例详情信息""" testcase_obj = self.get_object() # 用例前置信息 testcase_include = json.loads(testcase_obj.include, encoding='utf-8') # 用例请求信息 testcase_request = json.loads(testcase_obj.request, encoding='utf-8') testcase_request_datas = testcase_request.get('test').get('request') # 处理用例的validate列表 # 将[{'check': 'status_code', 'expected':200, 'comparator': 'equals'}] # 转化为[{key: 'status_code', value: 200, comparator: 'equals', param_type: 'string'}] testcase_validate = testcase_request.get('test').get('validate') testcase_validate_list = handle_datas.handle_data1(testcase_validate) # 处理用例的param数据 testcase_params = testcase_request_datas.get('params') testcase_params_list = handle_datas.handle_data4(testcase_params) # 处理用例的header列表 testcase_headers = testcase_request_datas.get('headers') testcase_headers_list = handle_datas.handle_data4(testcase_headers) # 处理用例variables变量列表 testcase_variables = testcase_request.get('test').get('variables') testcase_variables_list = handle_datas.handle_data2(testcase_variables) # 处理form表单数据 testcase_form_datas = testcase_request_datas.get('data') testcase_form_datas_list = handle_datas.handle_data6(testcase_form_datas) # 处理用例的files类请求 testcase_files_datas = testcase_request_datas.get("files") testcase_files_datas_list = handle_datas.handle_data6(testcase_files_datas) # 处理json数据 # testcase_json_datas = str(testcase_request_datas.get('json')) testcase_json_datas = json.dumps(testcase_request_datas.get('json'), ensure_ascii=False) # 处理extract数据 testcase_extract_datas = testcase_request.get('test').get('extract') testcase_extract_datas_list = handle_datas.handle_data3(testcase_extract_datas) # 处理parameters数据 testcase_parameters_datas = testcase_request.get('test').get('parameters') testcase_parameters_datas_list = handle_datas.handle_data3(testcase_parameters_datas) # 处理setupHooks数据 testcase_setup_hooks_datas = testcase_request.get('test').get('setup_hooks') testcase_setup_hooks_datas_list = handle_datas.handle_data5(testcase_setup_hooks_datas) # 处理teardownHooks数据 testcase_teardown_hooks_datas = testcase_request.get('test').get('teardown_hooks') testcase_teardown_hooks_datas_list = handle_datas.handle_data5(testcase_teardown_hooks_datas) selected_configure_id = testcase_include.get('config') selected_interface_id = testcase_obj.interface_id selected_project_id = Interfaces.objects.get(id=selected_interface_id).project_id selected_testcase_id = testcase_include.get('testcases') # 获取改用例下的前置用例id selected_testcase_id_name_list = [] for testcase_id in selected_testcase_id: # 遍历前置用例,组装返回前置用例id和name selected_testcase_id_name = {} selected_testcase_id_name["id"] =testcase_id selected_testcase_id_name["name"] = Testcases.objects.get(id=testcase_id).name selected_testcase_id_name_list.append(selected_testcase_id_name) datas = { "author": testcase_obj.author, "testcase_name": testcase_obj.name, "selected_configure_id": selected_configure_id, "selected_interface_id": selected_interface_id, "selected_project_id": selected_project_id, "selected_testcase_id": selected_testcase_id, "selected_testcase_id_name_list" :selected_testcase_id_name_list, "method": testcase_request_datas.get('method'), "url": testcase_request_datas.get('url'), "param": testcase_params_list, "header": testcase_headers_list, "variable": testcase_form_datas_list, # form表单请求数据 "jsonVariable": testcase_json_datas, "filesVariable" :testcase_files_datas_list, "extract": testcase_extract_datas_list, "validate": testcase_validate_list, "globalVar": testcase_variables_list, # 变量 "parameterized": testcase_parameters_datas_list, "setupHooks": testcase_setup_hooks_datas_list, "teardownHooks": testcase_teardown_hooks_datas_list, } return Response(datas)
def retrieve(self, request, *args, **kwargs): """获取用例详情信息""" testcase_obj = self.get_object() # 用例前置信息 testcase_include = json.loads(testcase_obj.include, encoding='utf-8') # 用例请求信息 testcase_request = json.loads(testcase_obj.request, encoding='utf-8') testcase_request_datas = testcase_request.get('test').get('request') if testcase_request.get('test').get('skip'): is_skip = [{ "key": "skip", "value": testcase_request.get('test').get('skip') }] elif testcase_request.get('test').get('skipIf'): is_skip = [{ "key": "skipIf", "value": testcase_request.get('test').get('skipIf') }] elif testcase_request.get('test').get('skipUnless'): is_skip = [{ "key": "skipUnless", "value": testcase_request.get('test').get('skipUnless') }] else: is_skip = [{"key": "", "value": ""}] # 处理用例的validate列表 # 将[{'check': 'status_code', 'expected':200, 'comparator': 'equals'}] # 转化为[{key: 'status_code', value: 200, comparator: 'equals', param_type: 'string'}] testcase_validate = testcase_request.get('test').get('validate') testcase_validate_list = handle_datas.handle_data1(testcase_validate) # 处理用例的param数据 testcase_params = testcase_request_datas.get('params') testcase_params_list = handle_datas.handle_data4(testcase_params) # 处理用例的header列表 testcase_headers = testcase_request_datas.get('headers') testcase_headers_list = handle_datas.handle_data4(testcase_headers) # 处理用例variables变量列表 testcase_variables = testcase_request.get('test').get('variables') testcase_variables_list = handle_datas.handle_data2(testcase_variables) # 处理form表单数据 testcase_form_datas = testcase_request_datas.get('data') testcase_form_datas_list = handle_datas.handle_data6( testcase_form_datas) # 处理json数据 # testcase_json_datas = str(testcase_request_datas.get('json')) testcase_json_datas = json.dumps(testcase_request_datas.get('json'), ensure_ascii=False) # 处理extract数据 testcase_extract_datas = testcase_request.get('test').get('extract') testcase_extract_datas_list = handle_datas.handle_data3( testcase_extract_datas) # 处理parameters数据 testcase_parameters_datas = testcase_request.get('test').get( 'parameters') testcase_parameters_datas_list = handle_datas.handle_data3( testcase_parameters_datas) # 处理setupHooks数据 testcase_setup_hooks_datas = testcase_request.get('test').get( 'setup_hooks') testcase_setup_hooks_datas_list = handle_datas.handle_data5( testcase_setup_hooks_datas) # 处理teardownHooks数据 testcase_teardown_hooks_datas = testcase_request.get('test').get( 'teardown_hooks') testcase_teardown_hooks_datas_list = handle_datas.handle_data5( testcase_teardown_hooks_datas) files = json.loads(testcase_obj.files, encoding='utf-8') selected_configure_id = testcase_include.get('config') selected_module_id = testcase_obj.module_id selected_project_id = Modules.objects.get( id=selected_module_id).project_id selected_testcase_id = testcase_include.get('testcases') selected_testcase = [] if selected_testcase_id: for i in selected_testcase_id: selected_testcase.append({ "id": i, "name": Testcases.objects.get(id=i).name }) selected_testcase_after_id = testcase_include.get('testcases_after') selected_testcase_after = [] if selected_testcase_after_id: for i in selected_testcase_after_id: selected_testcase_after.append({ "id": i, "name": Testcases.objects.get(id=i).name }) datas = { "author": testcase_obj.author, "testcase_name": testcase_obj.name, "selected_configure_id": selected_configure_id, "selected_module_id": selected_module_id, "selected_project_id": selected_project_id, "selected_testcase": selected_testcase, # "selected_testcase_after": selected_testcase_after, "method": testcase_request_datas.get('method'), "url": testcase_request_datas.get('url'), "param": testcase_params_list, "header": testcase_headers_list, "variable": testcase_form_datas_list, # form表单请求数据 "jsonVariable": testcase_json_datas, "extract": testcase_extract_datas_list, "validate": testcase_validate_list, "globalVar": testcase_variables_list, # 变量 "parameterized": testcase_parameters_datas_list, "setupHooks": testcase_setup_hooks_datas_list, "teardownHooks": testcase_teardown_hooks_datas_list, "is_skip": is_skip, "files": files } return Response(datas)
def retrieve(self, request, *args, **kwargs): """获取用例详情信息""" # Testcase对象 # 根据pk获取单个数据 testcase_obj = self.get_object() # 用例前置信息 # 将json格式的字符串转化为Python中的数据类型 testcase_include = json.loads(testcase_obj.include, encoding='utf-8') # 用例请求信息 testcase_request = json.loads(testcase_obj.request, encoding='utf-8') testcase_request_datas = testcase_request.get('test').get('request') # 处理用例的validate列表 testcase_validate = testcase_request.get('test').get('validate') testcase_validate_list = handle_datas.handle_data1(testcase_validate) # 处理用例的param数据 testcase_params = testcase_request_datas.get('params') testcase_params_list = handle_datas.handle_data4(testcase_params) # 处理用例的header列表 testcase_headers = testcase_request_datas.get('headers') testcase_headers_list = handle_datas.handle_data4(testcase_headers) # 处理用例variables变量列表 testcase_variables = testcase_request.get('test').get('variables') testcase_variables_list = handle_datas.handle_data2(testcase_variables) # 处理form表单数据 testcase_form_datas = testcase_request_datas.get('data') testcase_form_datas_list = handle_datas.handle_data6( testcase_form_datas) # 处理json数据 # 将字典转化为json格式的字符串 testcase_json_datas = json.dumps(testcase_request_datas.get('json'), ensure_ascii=False) # 处理extract数据 testcase_extract_datas = testcase_request.get('test').get('extract') testcase_extract_datas_list = handle_datas.handle_data3( testcase_extract_datas) # 处理parameters数据 testcase_parameters_datas = testcase_request.get('test').get( 'parameters') testcase_parameters_datas_list = handle_datas.handle_data3( testcase_parameters_datas) # 处理setupHooks数据 testcase_setup_hooks_datas = testcase_request.get('test').get( 'setup_hooks') testcase_setup_hooks_datas_list = handle_datas.handle_data5( testcase_setup_hooks_datas) # 处理teardownHooks数据 testcase_teardown_hooks_datas = testcase_request.get('test').get( 'teardown_hooks') testcase_teardown_hooks_datas_list = handle_datas.handle_data5( testcase_teardown_hooks_datas) selected_configure_id = testcase_include.get('config') selected_interface_id = testcase_obj.interface_id selected_project_id = Interfaces.objects.get( id=selected_interface_id).project_id selected_testcase_id = testcase_include.get('testcases') datas = { "author": testcase_obj.author, "testcase_name": testcase_obj.name, "selected_configure_id": selected_configure_id, "selected_interface_id": selected_interface_id, "selected_project_id": selected_project_id, "selected_testcase_id": selected_testcase_id, "method": testcase_request_datas.get('method'), "url": testcase_request_datas.get('url'), "param": testcase_params_list, "header": testcase_headers_list, "variable": testcase_form_datas_list, # form表单请求数据 "jsonVariable": testcase_json_datas, "extract": testcase_extract_datas_list, "validate": testcase_validate_list, "globalVar": testcase_variables_list, # 变量 "parameterized": testcase_parameters_datas_list, "setupHooks": testcase_setup_hooks_datas_list, "teardownHooks": testcase_teardown_hooks_datas_list, } return Response(datas)