def test_completion_form(self, gaolu_login, gaolu_login_luban, gaolu_login_report, env_conf): with allure.step("查看标段"): # section_dict = return_section_dict(gaolu_login, env_conf['用例配置']['主页']['section']) section_K = return_section_dict(gaolu_login) # 获取Kxx 下所有元素 section_home_arr = return_section_array( gaolu_login, section_K, env_conf['用例配置']['主页']['section']) # 获取3级节点的详细信息 pid_1 = get_section_home_id(section_home_arr, env_conf['用例配置']['主页']['项目节点']) # 获4级节点的详细信息 pid_2 = get_data(section_home_arr, pid_1, env_conf['用例配置']['主页']['文件节点']) # 获5级节点的详细信息 data_temp = get_data(section_home_arr, pid_2['id'], env_conf['用例配置']['主页']['subItem']) # 组装为{"name":"id"} section_dict = assemble_dict(data_temp) with allure.step("获取资料模板条目列表"): resp_temp = Data_template().pageDataTemplateItemUsingGET( gaolu_login_luban, page_size=10000, page_index=1) for data in resp_temp.get('source_response')['data']['result']: if data['name'] == env_conf['用例配置']['主页']['父表单']: template_id1 = data['formTemplateId'] template_db_id1 = data['templateCode'] with allure.step('获取roleName'): resp = UserInfo().getUserInfoUsingGET(gaolu_login) fullName = resp.get('source_response')['data']['fullName'] with allure.step('获取发起人用户信息: {0}'.format(fullName)): get_userName = Roleandrole().findUsersUsingGET(gaolu_login_luban) userinfo_datas = get_userName.get('source_response')['data'] userIdList = None for data in userinfo_datas: if data['truename'] == fullName: userIdList = data['id'] # 检验评定添加父表单 with allure.step('获取原始主页数据'): summary_org = get_summary_value(gaolu_login, env_conf['用例配置']['主页']['section']) summary_bySection_org = get_summary_bySection_value( gaolu_login, env_conf['用例配置']['主页']['section']) summary_byUnit_org = get_summary_byUnit_value( gaolu_login, env_conf['用例配置']['主页']['section'], env_conf['用例配置']['主页']['项目节点']) new_task_org = get_new_tasks_value(gaolu_login) # todo = get_todo_value(gaolu_login, userIdList) task_org = get_trace_value(gaolu_login, userIdList) with allure.step('添加父表单: {0}'.format(env_conf['用例配置']['主页']['父表单'])): add_parent_sheet_body = { "templateId": template_id1, "projectNodeId": section_dict[env_conf['用例配置']['主页']['subItem']], "templateDbId": int(template_db_id1), "classifier": "test_construction" } resp_add_parent_sheet = FormGroup().addFormGroupsPOST( gaolu_login, add_parent_sheet_body) waitForStatus(resp_add_parent_sheet, 200, 200, 15) href_formGroup = resp_add_parent_sheet.get( 'response_header')['Location'] formGroup_id = href_formGroup.split('/')[-1] with allure.step("断言添加父表单: {0} 成功".format( env_conf['用例配置']['主页']['父表单'])): add_sheet_result = { "classifier": "test_construction", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['主页']['subItem']] } group_resp = FormGroup().formGroupsGET(gaolu_login, add_sheet_result) id_templateName_dict = {} edit_hrefs = {} ids = {} templateId_ids = {} for data in group_resp.get( 'source_response')['data']['_embedded']['formGroups']: id_templateName_dict[str(data['id'])] = data['templateName'] edit_hrefs[str( data['id'])] = data['instance']['_links']['edit']['href'] ids[str(data['id'])] = data['instance']['id'] templateId_ids[str(data['id'])] = data['templateId'] Assertions.assert_equal_value(id_templateName_dict[formGroup_id], env_conf['用例配置']['主页']['父表单']) with allure.step('获取现在主页表单数据'): summary_new1 = get_summary_value(gaolu_login, env_conf['用例配置']['主页']['section']) with allure.step('断言未发起数量变化'): except_value = int(summary_org['未发起']) actual_value = int(summary_new1['未发起']) if except_value - 200 <= actual_value <= except_value + 200: assert True else: assert False, f'实际值为:{actual_value},预期值为:{except_value}' with allure.step("获取表单内容"): pattern = re.compile(r'[?]id=[A-Za-z0-9]{1,}') result = pattern.findall(edit_hrefs[formGroup_id]) edit_id = result[0].split('=')[1] ServiceTemplate().rbTemplateGET(gaolu_login_report, templateId_ids[formGroup_id]) ServiceTemplate().rbInstanceGET(gaolu_login_report, edit_id) with open('data/测试表6.2.2-2 干砌挡土墙分项工程质量检验评定表(JL).json', 'r', encoding='utf8') as fp: json_data = json.load(fp) body = { "id": edit_id, "name": id_templateName_dict[formGroup_id], "templateId": templateId_ids[formGroup_id], "data": json_data } with allure.step("获取提交表单id"): submit_resp = ServiceTemplate().rbInstancePUT( gaolu_login_report, edit_id, body) waitForStatus(submit_resp, 200, 200, 15) base_utils.file_is_exist(env_conf['用例配置']['主页']['文件路径']) resp = Content().contentGET(gaolu_login, ids[formGroup_id]) with allure.step("提交表单内容"): res = Content().contentPOST( gaolu_login, resp.get('source_response')['data']['id'], env_conf['用例配置']['主页']['文件路径'], 'application/pdf') waitForStatus(res, 200, 200, 15) with allure.step("发起审批"): time = datetime.datetime.now().strftime('%Y-%m-%d') body = {"deadline": time, "assignee": userIdList} start_approve = ApprovalProcess().starApprovePOST( gaolu_login, body, ids[formGroup_id]) waitForStatus(start_approve, 200, 200, 15) with allure.step("断言发起审批成功"): status = check_status( gaolu_login, formGroup_id, section_dict[env_conf['用例配置']['主页']['subItem']]) Assertions.assert_equal_value(status, 'PROCESSING') with allure.step('获取-表单(总)数据统计-数据'): summary_new2 = get_summary_value(gaolu_login, env_conf['用例配置']['主页']['section']) with allure.step('断言-表单(总)数据统计-审批中-数量变化'): except_value = int(summary_org['审批中']) actual_value = int(summary_new2['审批中']) if except_value - 200 <= actual_value <= except_value + 200: assert True else: assert False, f'实际值为:{actual_value},预期值为:{except_value}' with allure.step('获取-项目概况-数据'): summary_byUnit_new1 = get_summary_byUnit_value( gaolu_login, env_conf['用例配置']['主页']['section'], env_conf['用例配置']['主页']['项目节点']) with allure.step('断言-项目概况-评定中-数量变化'): except_value = int(summary_byUnit_org['评定中']) actual_value = int(summary_byUnit_new1['评定中']) if except_value - 200 <= actual_value <= except_value + 200: assert True else: assert False, f'实际值为:{actual_value},预期值为:{except_value}' with allure.step('获取-我的代发-数据'): except_value = new_task_org actual_value = get_new_tasks_value(gaolu_login) if except_value - 200 <= actual_value <= except_value + 200: assert True else: assert False, f'实际值为:{actual_value},预期值为:{except_value}' with allure.step("审批一"): body = { "deadline": time, "comment": "test", "assignee": userIdList } pass_approve = ApprovalProcess().passApprovePOST( gaolu_login, body, ids[formGroup_id]) waitForStatus(pass_approve, 200, 200, 15) with allure.step("审批二"): body = { "deadline": time, "comment": "test", "assignee": userIdList } pass_approve = ApprovalProcess().passApprovePOST( gaolu_login, body, ids[formGroup_id]) waitForStatus(pass_approve, 200, 200, 15) with allure.step("审批完成"): status = check_status( gaolu_login, formGroup_id, section_dict[env_conf['用例配置']['主页']['subItem']]) Assertions.assert_equal_value(status, 'COMPLETED') with allure.step('获取-表单(总)数据统计-数据'): summary_new3 = get_summary_value(gaolu_login, env_conf['用例配置']['主页']['section']) summary_bySection_new = get_summary_bySection_value( gaolu_login, env_conf['用例配置']['主页']['section']) with allure.step('断言-表单(总)数据统计-已完成-数量变化'): except_value = int(summary_org['已完成']) actual_value = int(summary_new3['已完成']) if except_value - 200 <= actual_value <= except_value + 200: assert True else: assert False, f'实际值为:{actual_value},预期值为:{except_value}' with allure.step('断言-项目数据统计-已评定-数量变化'): except_value = int(summary_bySection_org['已评定']) actual_value = int(summary_bySection_new['已评定']) if except_value - 20 <= actual_value <= except_value + 20: assert True else: assert False, f'实际值为:{actual_value},预期值为:{except_value}' with allure.step('获取-项目概况-数据'): summary_byUnit_new2 = get_summary_byUnit_value( gaolu_login, env_conf['用例配置']['主页']['section'], env_conf['用例配置']['主页']['项目节点']) with allure.step('断言-项目概况-已评定-数量变化'): except_value = int(summary_byUnit_org['已评定']) actual_value = int(summary_byUnit_new2['已评定']) if except_value - 200 <= actual_value <= except_value + 200: assert True else: assert False, f'实际值为:{actual_value},预期值为:{except_value}' with allure.step('获取-我的已办-数据'): except_value = task_org actual_value = get_trace_value(gaolu_login, userIdList) if except_value - 200 <= actual_value <= except_value + 200: assert True else: assert False, f'实际值为:{actual_value},预期值为:{except_value}' with allure.step('删除父表单'): delete_sheet1 = FormGroup().deleteFormGroupsDELETE( gaolu_login, formGroup_id) waitForStatus(delete_sheet1, 200, 200, 15)
def test_new_sheet(self, gaolu_login, gaolu_login_luban, env_conf): # 新增表单 with allure.step("查看标段"): # section_dict = return_section_dict(gaolu_login, env_conf['用例配置']['增加表单']['section']) section_K = return_section_dict(gaolu_login) # 获取Kxx 下所有元素 section_home_arr = return_section_array( gaolu_login, section_K, env_conf['用例配置']['增加表单']['section']) # 获取3级节点的详细信息 pid_1 = get_section_home_id(section_home_arr, env_conf['用例配置']['增加表单']['项目节点']) # 获4级节点的详细信息 pid_2 = get_data(section_home_arr, pid_1, env_conf['用例配置']['增加表单']['文件节点']) # 获5级节点的详细信息 data_temp = get_data(section_home_arr, pid_2['id'], env_conf['用例配置']['增加表单']['subItem']) # 组装为{"name":"id"} section_dict = assemble_dict(data_temp) with allure.step("获取资料模板条目列表"): resp_temp = Data_template().pageDataTemplateItemUsingGET( gaolu_login_luban, page_size=10000, page_index=1) for data in resp_temp.get('source_response')['data']['result']: if data['name'] == env_conf['用例配置']['增加表单']['父表单']: template_id1 = data['formTemplateId'] template_db_id1 = data['templateCode'] elif data['name'] == env_conf['用例配置']['增加表单']['普通表单']: template_id2 = data['formTemplateId'] template_db_id2 = data['templateCode'] with allure.step('添加普通表单'): add_sheet_body = { "templateId": template_id2, "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']], "templateDbId": int(template_db_id2), "classifier": "report" } resp_add_normal_sheet = FormGroup().addFormGroupsPOST( gaolu_login, add_sheet_body) waitForStatus(resp_add_normal_sheet, 200, 200, 15) href_formGroup = resp_add_normal_sheet.get( 'response_header')['Location'] formGroup_normal_id = href_formGroup.split('/')[-1] with allure.step("断言添加普通表单: {0} 成功".format( env_conf['用例配置']['增加表单']['普通表单'])): add_sheet_result = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']] } normal_group_resp = FormGroup().formGroupsGET( gaolu_login, add_sheet_result) id_normal_templateName_dict = {} for data in normal_group_resp.get( 'source_response')['data']['_embedded']['formGroups']: id_normal_templateName_dict[str( data['id'])] = data['templateName'] Assertions.assert_equal_value( id_normal_templateName_dict[formGroup_normal_id], env_conf['用例配置']['增加表单']['普通表单']) # 检验评定添加父表单 with allure.step('添加父表单'): add_parent_sheet_body = { "templateId": template_id1, "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']], "templateDbId": int(template_db_id1), "classifier": "report" } resp_add_parent_sheet = FormGroup().addFormGroupsPOST( gaolu_login, add_parent_sheet_body) waitForStatus(resp_add_parent_sheet, 200, 200, 15) href_formGroup = resp_add_parent_sheet.get( 'response_header')['Location'] formGroup_id = href_formGroup.split('/')[-1] with allure.step("断言添加父表单: {0} 成功".format( env_conf['用例配置']['增加表单']['父表单'])): add_sheet_result = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']] } group_resp = FormGroup().formGroupsGET(gaolu_login, add_sheet_result) id_templateName_dict = {} for data in group_resp.get( 'source_response')['data']['_embedded']['formGroups']: id_templateName_dict[str(data['id'])] = data['templateName'] Assertions.assert_equal_value(id_templateName_dict[formGroup_id], env_conf['用例配置']['增加表单']['父表单']) with allure.step('添加子表单'): body = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']] } formGroup_resp_dict = {} formGroup_resp = FormGroup().formGroupsGET(gaolu_login, body) for data in formGroup_resp.get( 'source_response')['data']['_embedded']['formGroups']: formGroup_resp_dict[str( data['id'])] = data['_links']['self']['href'] sheet_name = "测试表单" + base_utils.generate_random_str() sheet_body = { "name": sheet_name, "toFormInstance": "", "formGroup": formGroup_resp_dict[formGroup_id] } resp_child = FormInstances().formInstancesPOST( gaolu_login, sheet_body) waitForStatus(resp_child, 200, 200, 15) print('添加子表单: {0} 成功'.format(sheet_name)) # 表单上移 with allure.step("上移表单"): up_down_body = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']] } up_down_resp = FormGroup().formGroupsGET(gaolu_login, up_down_body) name_id_dict = {} for data in up_down_resp.get( 'source_response')['data']['_embedded']['formGroups']: name_id_dict[data['templateName']] = data['id'] id_weight_dict = {} for data in up_down_resp.get( 'source_response')['data']['_embedded']['formGroups']: id_weight_dict[str(data['id'])] = data['weight'] weight_body_down = { "weight": id_weight_dict[str( name_id_dict[env_conf['用例配置']['增加表单']['普通表单']])] } down_form_resp = FormGroup().upDownFormPatch( gaolu_login, name_id_dict[env_conf['用例配置']['增加表单']['父表单']], weight_body_down) waitForStatus(down_form_resp, 200, 200, 15) weight_body_up = { "weight": id_weight_dict[str( name_id_dict[env_conf['用例配置']['增加表单']['父表单']])] } up_form_resp = FormGroup().upDownFormPatch( gaolu_login, name_id_dict[env_conf['用例配置']['增加表单']['普通表单']], weight_body_up) waitForStatus(up_form_resp, 200, 200, 15) with allure.step("断言上移表单成功"): up_down_result_body = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']] } up_down_resp = FormGroup().formGroupsGET(gaolu_login, up_down_result_body) result_weight_dict = {} for data in up_down_resp.get( 'source_response')['data']['_embedded']['formGroups']: result_weight_dict[str(data['id'])] = data['weight'] Assertions.assert_equal_value( result_weight_dict[str( name_id_dict[env_conf['用例配置']['增加表单']['普通表单']])], id_weight_dict[str( name_id_dict[env_conf['用例配置']['增加表单']['父表单']])]) with allure.step("获取资料模板条目列表"): resp_temp = Data_template().pageDataTemplateItemUsingGET( gaolu_login_luban, page_size=10000, page_index=1) for data in resp_temp.get('source_response')['data']['result']: if data['name'] == env_conf['用例配置']['增加表单']['应用模板表单']: template_id3 = data['formTemplateId'] template_db_id3 = data['templateCode'] with allure.step("应用模板"): add_use_sheet_body = { "templateId": template_id3, "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']], "templateDbId": int(template_db_id3), "classifier": "report" } resp_apply_template = FormGroup().addFormGroupsPOST( gaolu_login, add_use_sheet_body) waitForStatus(resp_apply_template, 200, 200, 15) href_template = resp_apply_template.get( 'response_header')['Location'] template_id = href_template.split('/')[-1] with allure.step("断言应用模板: {0} 成功".format( env_conf['用例配置']['增加表单']['应用模板表单'])): add_sheet_result = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']] } up_down_resp = FormGroup().formGroupsGET(gaolu_login, add_sheet_result) name_id_dict = {} for data in up_down_resp.get( 'source_response')['data']['_embedded']['formGroups']: name_id_dict[data['templateName']] = data['id'] Assertions.assert_in_key(name_id_dict, env_conf['用例配置']['增加表单']['应用模板表单']) with allure.step("查询可上传的模板"): up_body = {"classifier": "report"} resp_temp = FormGroup().searchUpTemplatesGET(gaolu_login, up_body) up_dict = {} for data in resp_temp.get( 'source_response')['data']['_embedded']['stashNodes']: up_dict[data['name']] = data['id'] with allure.step('上传模板'): up_sheet_result = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['增加表单']['subItem']] } up_resp = FormGroup().formGroupsGET(gaolu_login, up_sheet_result) body_data = [] body_params = {"classifier": "report"} for data in up_resp.get( 'source_response')['data']['_embedded']['formGroups']: body_data.append({ "templateDbId": data['templateDbId'], "templateId": data['templateId'], "templateName": data['templateName'] }) resp = FormGroup().upTemplatesPUT(gaolu_login, up_dict[new_template_node3], body_data, body_params) waitForStatus(resp, 200, 200, 15) # 删除表单 with allure.step('删除子表单'): node = env_conf['用例配置']['增加表单']['subItem'] body = return_InstanceBody(gaolu_login, section_dict, node, formGroup_id) res = FormInstances().formInstanceSearchGET(gaolu_login, body) delete_id = None for data in res.get( 'source_response')['data']['_embedded']['formInstances']: if data['name'] == sheet_name: delete_id = data['id'] delete_sheet3 = Sort().formInstancesDELETE(gaolu_login, delete_id) waitForStatus(delete_sheet3, 200, 200, 15) with allure.step('删除父表单'): delete_sheet1 = FormGroup().deleteFormGroupsDELETE( gaolu_login, formGroup_id) waitForStatus(delete_sheet1, 200, 200, 15) with allure.step('删除普通表单'): delete_sheet2 = FormGroup().deleteFormGroupsDELETE( gaolu_login, formGroup_normal_id) waitForStatus(delete_sheet2, 200, 200, 15) with allure.step('删除应用模板表单'): delete_sheet3 = FormGroup().deleteFormGroupsDELETE( gaolu_login, template_id) waitForStatus(delete_sheet3, 200, 200, 15)
def test_approve_batch_form(self, gaolu_login, gaolu_login_luban, gaolu_login_report, env_conf): with allure.step("查看标段"): section_K = return_section_dict(gaolu_login) # 获取Kxx 下所有元素 section_home_arr = return_section_array( gaolu_login, section_K, env_conf['用例配置']['表单审批']['批量表单']['section']) # 获取3级节点的详细信息 pid_1 = get_section_home_id( section_home_arr, env_conf['用例配置']['表单审批']['批量表单']['项目节点']) # 获4级节点的详细信息 pid_2 = get_data(section_home_arr, pid_1, env_conf['用例配置']['表单审批']['批量表单']['文件节点']) # 获5级节点的详细信息 data_temp = get_data(section_home_arr, pid_2['id'], env_conf['用例配置']['表单审批']['批量表单']['subItem']) # 组装为{"name":"id"} section_dict = assemble_dict(data_temp) with allure.step("获取资料模板条目列表"): resp_temp = Data_template().pageDataTemplateItemUsingGET( gaolu_login_luban, page_size=10000, page_index=1) for data in resp_temp.get('source_response')['data']['result']: if data['name'] == env_conf['用例配置']['表单审批']['批量表单']['父表单']: template_id1 = data['formTemplateId'] template_db_id1 = data['templateCode'] with allure.step('获取roleName'): resp = UserInfo().getUserInfoUsingGET(gaolu_login) fullName = resp.get('source_response')['data']['fullName'] with allure.step('获取发起人用户信息: {0}'.format(fullName)): get_userName = Roleandrole().findUsersUsingGET(gaolu_login_luban) userinfo_datas = get_userName.get('source_response')['data'] userIdList = None for data in userinfo_datas: if data['truename'] == fullName: userIdList = data['id'] # 检验评定添加父表单 with allure.step('添加父表单: {0}'.format( env_conf['用例配置']['表单审批']['批量表单']['父表单'])): add_parent_sheet_body = { "templateId": template_id1, "projectNodeId": section_dict[env_conf['用例配置']['表单审批']['批量表单']['subItem']], "templateDbId": int(template_db_id1), "classifier": "report" } resp_add_parent_sheet = FormGroup().addFormGroupsPOST( gaolu_login, add_parent_sheet_body) waitForStatus(resp_add_parent_sheet, 200, 200, 15) href_formGroup = resp_add_parent_sheet.get( 'response_header')['Location'] formGroup_id = href_formGroup.split('/')[-1] with allure.step("断言添加父表单: {0} 成功".format( env_conf['用例配置']['表单审批']['批量表单']['父表单'])): add_sheet_result = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['表单审批']['批量表单']['subItem']] } group_resp = FormGroup().formGroupsGET(gaolu_login, add_sheet_result) id_templateName_dict = {} for data in group_resp.get( 'source_response')['data']['_embedded']['formGroups']: id_templateName_dict[str(data['id'])] = data['templateName'] Assertions.assert_equal_value( id_templateName_dict[formGroup_id], env_conf['用例配置']['表单审批']['批量表单']['父表单']) with allure.step('批量添加子表单'): body = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['表单审批']['批量表单']['subItem']] } formGroup_resp_dict = {} formGroup_resp = FormGroup().formGroupsGET(gaolu_login, body) for data in formGroup_resp.get( 'source_response')['data']['_embedded']['formGroups']: formGroup_resp_dict[str( data['id'])] = data['_links']['self']['href'] sheet_name1 = "测试表单" + base_utils.generate_random_str() sheet_name2 = "测试表单" + base_utils.generate_random_str() sheet_body1 = { "name": sheet_name1, "toFormInstance": "", "formGroup": formGroup_resp_dict[formGroup_id] } sheet_body2 = { "name": sheet_name2, "toFormInstance": "", "formGroup": formGroup_resp_dict[formGroup_id] } resp_child1 = FormInstances().formInstancesPOST( gaolu_login, sheet_body1) waitForStatus(resp_child1, 200, 200, 15) print('添加子表单: {0} 成功'.format(sheet_name1)) resp_child2 = FormInstances().formInstancesPOST( gaolu_login, sheet_body2) waitForStatus(resp_child2, 200, 200, 15) print('添加子表单: {0} 成功'.format(sheet_name2)) with allure.step('获取子表单templateId'): node = env_conf['用例配置']['表单审批']['批量表单']['subItem'] body = return_InstanceBody(gaolu_login, section_dict, node, formGroup_id) res = FormInstances().formInstanceSearchGET(gaolu_login, body) templateId_ids = {} ids = {} edit_hrefs = {} for data in res.get( 'source_response')['data']['_embedded']['formInstances']: templateId_ids[data['name']] = data['templateId'] ids[data['name']] = data['id'] edit_hrefs[data['name']] = data['_links']['edit']['href'] with allure.step("获取表单内容"): pattern = re.compile(r'[?]id=[A-Za-z0-9]{1,}') result1 = pattern.findall(edit_hrefs[sheet_name1]) result2 = pattern.findall(edit_hrefs[sheet_name2]) edit_id1 = result1[0].split('=')[1] edit_id2 = result2[0].split('=')[1] ServiceTemplate().rbTemplateGET(gaolu_login_report, templateId_ids[sheet_name1]) ServiceTemplate().rbTemplateGET(gaolu_login_report, templateId_ids[sheet_name2]) content_resp1 = ServiceTemplate().rbInstanceGET( gaolu_login_report, edit_id1) content_resp2 = ServiceTemplate().rbInstanceGET( gaolu_login_report, edit_id2) body1 = content_resp1.get('source_response')['data'] body2 = content_resp2.get('source_response')['data'] with allure.step("获取提交表单id1"): submit_resp1 = ServiceTemplate().rbInstancePUT( gaolu_login_report, edit_id1, body1) waitForStatus(submit_resp1, 200, 200, 15) base_utils.file_is_exist(env_conf['用例配置']['表单审批']['批量表单']['文件路径']) os.rename(env_conf['用例配置']['表单审批']['批量表单']['文件路径'], "data/" + sheet_name1 + ".pdf") resp1 = Content().contentGET(gaolu_login, ids[sheet_name1]) with allure.step("提交表单1内容"): res1 = Content().contentPOST( gaolu_login, resp1.get('source_response')['data']['id'], "data/" + sheet_name1 + ".pdf", 'application/pdf') waitForStatus(res1, 200, 200, 15) os.rename("data/" + sheet_name1 + ".pdf", env_conf['用例配置']['表单审批']['批量表单']['文件路径']) with allure.step("获取提交表单id2"): submit_resp2 = ServiceTemplate().rbInstancePUT( gaolu_login_report, edit_id2, body2) waitForStatus(submit_resp2, 200, 200, 15) base_utils.file_is_exist(env_conf['用例配置']['表单审批']['批量表单']['文件路径']) os.rename(env_conf['用例配置']['表单审批']['批量表单']['文件路径'], "data/" + sheet_name2 + ".pdf") resp2 = Content().contentGET(gaolu_login, ids[sheet_name2]) with allure.step("提交表单2内容"): res2 = Content().contentPOST( gaolu_login, resp2.get('source_response')['data']['id'], "data/" + sheet_name2 + ".pdf", 'application/pdf') waitForStatus(res2, 200, 200, 15) os.rename("data/" + sheet_name2 + ".pdf", env_conf['用例配置']['表单审批']['批量表单']['文件路径']) with allure.step("创建委托实例"): node = env_conf['用例配置']['表单审批']['批量表单']['subItem'] body = return_InstanceBody(gaolu_login, section_dict, node, formGroup_id) res = FormInstances().formInstanceSearchGET(gaolu_login, body) datas = res.get( 'source_response')['data']['_embedded']['formInstances'] id_newDelegate = {} for data in datas: id_newDelegate[ data['name']] = data['_links']['newDelegate']['href'] pprint.pprint(id_newDelegate) formInstances = [ id_newDelegate[sheet_name1], id_newDelegate[sheet_name2] ] newDelegate_body = {"formInstances": formInstances} resp_create = DelegatesForm().createFormDelegatesPOST( gaolu_login, newDelegate_body) href_Delegate = resp_create.get('response_header')['Location'] Delegate_id = href_Delegate.split('/')[-1] with allure.step("发起审批"): time = datetime.datetime.now().strftime('%Y-%m-%d') body = {"deadline": time, "assignee": userIdList} start_approve = ApprovalProcess().starApprovePOST( gaolu_login, body, ids[sheet_name1]) waitForStatus(start_approve, 200, 200, 15) ApprovalProcess().starApprovePOST(gaolu_login, Delegate_id) with allure.step("断言发起审批成功"): node = env_conf['用例配置']['表单审批']['批量表单']['subItem'] result_body = return_InstanceBody(gaolu_login, section_dict, node, formGroup_id) res = FormInstances().formInstanceSearchGET( gaolu_login, result_body) for data in res.get( 'source_response')['data']['_embedded']['formInstances']: if data['name'] == sheet_name1: status1 = data['status'] elif data['name'] == sheet_name2: status2 = data['status'] Assertions.assert_equal_value(status1, 'PROCESSING') Assertions.assert_equal_value(status2, 'PROCESSING') with allure.step("审批"): body = { "deadline": time, "comment": "test", "assignee": userIdList } pass_approve = ApprovalProcess().passApprovePOST( gaolu_login, body, ids[sheet_name1]) waitForStatus(pass_approve, 200, 200, 15) with allure.step("查询可退回步骤ID"): return_step = ApprovalProcess().returnApproveGET( gaolu_login, ids[sheet_name1]) data_arr = return_step.get('source_response')['data'] for data in data_arr: if data['name'] == '发起人': step1 = data['id'] else: step2 = data['id'] with allure.step("退回一步"): body = {"stepId": step2, "deadline": time, "comment": "pre_step"} return_step2 = ApprovalProcess().returnApprovePOST( gaolu_login, body, ids[sheet_name1]) waitForStatus(return_step2, 200, 200, 15) with allure.step("断言退回一步成功"): node = env_conf['用例配置']['表单审批']['批量表单']['subItem'] result_body = return_InstanceBody(gaolu_login, section_dict, node, formGroup_id) res = FormInstances().formInstanceSearchGET( gaolu_login, result_body) for data in res.get( 'source_response')['data']['_embedded']['formInstances']: if data['name'] == sheet_name1: status1 = data['status'] status2 = data['status'] Assertions.assert_equal_value(status1, 'RETURN') Assertions.assert_equal_value(status2, 'RETURN') with allure.step("退回到未发起"): body = {"stepId": step1, "deadline": time, "comment": "pre"} return_step1 = ApprovalProcess().returnApprovePOST( gaolu_login, body, ids[sheet_name1]) waitForStatus(return_step1, 200, 200, 15) with allure.step("断言退回到未发起成功"): node = env_conf['用例配置']['表单审批']['批量表单']['subItem'] result_body = return_InstanceBody(gaolu_login, section_dict, node, formGroup_id) res = FormInstances().formInstanceSearchGET( gaolu_login, result_body) for data in res.get( 'source_response')['data']['_embedded']['formInstances']: if data['name'] == sheet_name1: status1 = data['status'] elif data['name'] == sheet_name2: status2 = data['status'] Assertions.assert_equal_value(status1, 'UNSTART') Assertions.assert_equal_value(status2, 'UNSTART') with allure.step("删除子表单"): delete_sheet1 = Sort().formInstancesDELETE(gaolu_login, ids[sheet_name1]) waitForStatus(delete_sheet1, 200, 200, 15) delete_sheet2 = Sort().formInstancesDELETE(gaolu_login, ids[sheet_name2]) waitForStatus(delete_sheet2, 200, 200, 15) with allure.step('删除父表单'): delete_group_sheet = FormGroup().deleteFormGroupsDELETE( gaolu_login, formGroup_id) waitForStatus(delete_group_sheet, 200, 200, 15)
def test_attach_up_download_delete(self, gaolu_login, gaolu_login_luban, gaolu_login_report, env_conf): with allure.step("查看标段"): section_K = return_section_dict(gaolu_login) # 获取Kxx 下所有元素 section_home_arr = return_section_array( gaolu_login, section_K, env_conf['用例配置']['表单审批']['表单附件']['section']) # 获取3级节点的详细信息 pid_1 = get_section_home_id( section_home_arr, env_conf['用例配置']['表单审批']['表单附件']['项目节点']) # 获4级节点的详细信息 pid_2 = get_data(section_home_arr, pid_1, env_conf['用例配置']['表单审批']['表单附件']['文件节点']) # 获5级节点的详细信息 data_temp = get_data(section_home_arr, pid_2['id'], env_conf['用例配置']['表单审批']['表单附件']['subItem']) # 组装为{"name":"id"} section_dict = assemble_dict(data_temp) with allure.step("获取资料模板条目列表"): resp_temp = Data_template().pageDataTemplateItemUsingGET( gaolu_login_luban, page_size=10000, page_index=1) for data in resp_temp.get('source_response')['data']['result']: if data['name'] == env_conf['用例配置']['表单审批']['表单附件']['父表单']: template_id1 = data['formTemplateId'] template_db_id1 = data['templateCode'] with allure.step('获取roleName'): resp = UserInfo().getUserInfoUsingGET(gaolu_login) fullName = resp.get('source_response')['data']['fullName'] with allure.step('获取发起人用户信息: {0}'.format(fullName)): get_userName = Roleandrole().findUsersUsingGET(gaolu_login_luban) userinfo_datas = get_userName.get('source_response')['data'] userIdList = None for data in userinfo_datas: if data['truename'] == fullName: userIdList = data['id'] # 检验评定添加父表单 with allure.step('添加父表单: {0}'.format( env_conf['用例配置']['表单审批']['表单附件']['父表单'])): add_parent_sheet_body = { "templateId": template_id1, "projectNodeId": section_dict[env_conf['用例配置']['表单审批']['表单附件']['subItem']], "templateDbId": int(template_db_id1), "classifier": "report" } resp_add_parent_sheet = FormGroup().addFormGroupsPOST( gaolu_login, add_parent_sheet_body) waitForStatus(resp_add_parent_sheet, 200, 200, 15) href_formGroup = resp_add_parent_sheet.get( 'response_header')['Location'] formGroup_id = href_formGroup.split('/')[-1] with allure.step("断言添加父表单: {0} 成功".format( env_conf['用例配置']['表单审批']['表单附件']['父表单'])): add_sheet_result = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['表单审批']['表单附件']['subItem']] } group_resp = FormGroup().formGroupsGET(gaolu_login, add_sheet_result) id_templateName_dict = {} for data in group_resp.get( 'source_response')['data']['_embedded']['formGroups']: id_templateName_dict[str(data['id'])] = data['templateName'] Assertions.assert_equal_value( id_templateName_dict[formGroup_id], env_conf['用例配置']['表单审批']['表单附件']['父表单']) with allure.step('添加子表单'): body = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['表单审批']['表单附件']['subItem']] } formGroup_resp_dict = {} formGroup_resp = FormGroup().formGroupsGET(gaolu_login, body) for data in formGroup_resp.get( 'source_response')['data']['_embedded']['formGroups']: formGroup_resp_dict[str( data['id'])] = data['_links']['self']['href'] sheet_name = "测试表单" + base_utils.generate_random_str() sheet_body = { "name": sheet_name, "toFormInstance": "", "formGroup": formGroup_resp_dict[formGroup_id] } resp_child = FormInstances().formInstancesPOST( gaolu_login, sheet_body) waitForStatus(resp_child, 200, 200, 15) print('添加子表单: {0} 成功'.format(sheet_name)) with allure.step('获取子表单templateId'): node = env_conf['用例配置']['表单审批']['表单附件']['subItem'] body = return_InstanceBody(gaolu_login, section_dict, node, formGroup_id) res = FormInstances().formInstanceSearchGET(gaolu_login, body) templateId_ids = {} ids = {} edit_hrefs = {} for data in res.get( 'source_response')['data']['_embedded']['formInstances']: if data['name'] == sheet_name: templateId_ids[data['name']] = data['templateId'] ids[data['name']] = data['id'] edit_hrefs[data['name']] = data['_links']['edit']['href'] with allure.step("获取表单内容"): pattern = re.compile(r'[?]id=[A-Za-z0-9]{1,}') result = pattern.findall(edit_hrefs[sheet_name]) edit_id = result[0].split('=')[1] ServiceTemplate().rbTemplateGET(gaolu_login_report, templateId_ids[sheet_name]) content_resp = ServiceTemplate().rbInstanceGET( gaolu_login_report, edit_id) body = content_resp.get('source_response')['data'] with allure.step("获取提交表单id"): submit_resp = ServiceTemplate().rbInstancePUT( gaolu_login_report, edit_id, body) waitForStatus(submit_resp, 200, 200, 15) base_utils.file_is_exist(env_conf['用例配置']['表单审批']['表单附件']['文件路径']) os.rename(env_conf['用例配置']['表单审批']['表单附件']['文件路径'], "data/" + sheet_name + ".pdf") resp = Content().contentGET(gaolu_login, ids[sheet_name]) with allure.step("提交表单内容"): res = Content().contentPOST( gaolu_login, resp.get('source_response')['data']['id'], "data/" + sheet_name + ".pdf", 'application/pdf') os.rename("data/" + sheet_name + ".pdf", env_conf['用例配置']['表单审批']['表单附件']['文件路径']) waitForStatus(res, 200, 200, 15) with allure.step("上传附件png"): body = {"source": "upload"} res_up = Content().documentsPOST(gaolu_login, body) waitForStatus(res_up, 200, 200, 15) href_formGroup = res_up.get('response_header')['Location'] get_id = href_formGroup.split('/')[-1] res_id = Content().documentsGET(gaolu_login, get_id) href = res_id.get( 'source_response')['data']['_links']['content']['href'] up_id = href.split('/')[-1] res = Content().contentPOST( gaolu_login, up_id, env_conf['用例配置']['表单审批']['表单附件']['图片附件'], 'image/png') waitForStatus(res, 200, 200, 15) document_hef = res_id.get( 'source_response')['data']['_links']['document']['href'] res_bind = FormInstances().attachmentsPUT(gaolu_login, document_hef, ids[sheet_name], 'text') waitForStatus(res_bind, 200, 200, 15) with allure.step('下载附件png'): down_resp = Content().downcontentGET(gaolu_login, up_id) with open('data/down_png.png', 'wb') as code: code.write(down_resp.get('Response_content')) with allure.step('删除附件png'): delete_bind = FormInstances().attachmentsPUT( gaolu_login, '', ids[sheet_name], 'text') waitForStatus(delete_bind, 200, 200, 15) with allure.step("删除子表单"): delete_sheet = Sort().formInstancesDELETE(gaolu_login, ids[sheet_name]) waitForStatus(delete_sheet, 200, 200, 15) with allure.step('删除父表单'): delete_group_sheet = FormGroup().deleteFormGroupsDELETE( gaolu_login, formGroup_id) waitForStatus(delete_group_sheet, 200, 200, 15)
def test_advance_form(self, gaolu_login, gaolu_login_luban, gaolu_login_report, env_conf): with allure.step("查看标段"): section_K = return_section_dict(gaolu_login) # 获取Kxx 下所有元素 section_home_arr = return_section_array( gaolu_login, section_K, env_conf['用例配置']['高级表单']['section']) # 获取3级节点的详细信息 pid_1 = get_section_home_id(section_home_arr, env_conf['用例配置']['高级表单']['项目节点']) # 获4级节点的详细信息 pid_2 = get_data(section_home_arr, pid_1, env_conf['用例配置']['高级表单']['文件节点']) # 获5级节点的详细信息 data_temp = get_data(section_home_arr, pid_2['id'], env_conf['用例配置']['高级表单']['subItem']) # 组装为{"name":"id"} section_dict = assemble_dict(data_temp) with allure.step("获取资料模板条目列表"): resp_temp = Data_template().pageDataTemplateItemUsingGET( gaolu_login_luban, page_size=10000, page_index=1) for data in resp_temp.get('source_response')['data']['result']: if data['name'] == env_conf['用例配置']['高级表单']['父表单']: template_id1 = data['formTemplateId'] template_db_id1 = data['templateCode'] # 检验评定添加父表单 with allure.step('添加父表单: {0}'.format(env_conf['用例配置']['高级表单']['父表单'])): add_parent_sheet_body = { "templateId": template_id1, "projectNodeId": section_dict[env_conf['用例配置']['高级表单']['subItem']], "templateDbId": int(template_db_id1), "classifier": "report" } resp_add_parent_sheet = FormGroup().addFormGroupsPOST( gaolu_login, add_parent_sheet_body) waitForStatus(resp_add_parent_sheet, 200, 200, 15) href_formGroup = resp_add_parent_sheet.get( 'response_header')['Location'] formGroup_id = href_formGroup.split('/')[-1] with allure.step("断言添加父表单: {0} 成功".format( env_conf['用例配置']['高级表单']['父表单'])): add_sheet_result = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['高级表单']['subItem']] } group_resp = FormGroup().formGroupsGET(gaolu_login, add_sheet_result) id_templateName_dict = {} for data in group_resp.get( 'source_response')['data']['_embedded']['formGroups']: id_templateName_dict[str(data['id'])] = data['templateName'] Assertions.assert_equal_value(id_templateName_dict[formGroup_id], env_conf['用例配置']['高级表单']['父表单']) with allure.step('添加子表单'): body = { "classifier": "report", "projection": "excerpt", "projectNodeId": section_dict[env_conf['用例配置']['高级表单']['subItem']] } formGroup_resp_dict = {} formGroup_resp = FormGroup().formGroupsGET(gaolu_login, body) for data in formGroup_resp.get( 'source_response')['data']['_embedded']['formGroups']: formGroup_resp_dict[str( data['id'])] = data['_links']['self']['href'] sheet_name = "测试表单" + base_utils.generate_random_str() sheet_body = { "name": sheet_name, "toFormInstance": "", "formGroup": formGroup_resp_dict[formGroup_id] } resp_child = FormInstances().formInstancesPOST( gaolu_login, sheet_body) waitForStatus(resp_child, 200, 200, 15) print('添加子表单: {0} 成功'.format(sheet_name)) with allure.step('获取子表单templateId'): node = env_conf['用例配置']['高级表单']['subItem'] body = return_InstanceBody(gaolu_login, section_dict, node, formGroup_id) res = FormInstances().formInstanceSearchGET(gaolu_login, body) templateId_ids = {} ids = {} edit_hrefs = {} for data in res.get( 'source_response')['data']['_embedded']['formInstances']: templateId_ids[data['name']] = data['templateId'] ids[data['name']] = data['id'] edit_hrefs[data['name']] = data['_links']['edit']['href'] with allure.step("获取表单内容"): pattern = re.compile(r'[?]id=[A-Za-z0-9]{1,}') result = pattern.findall(edit_hrefs[sheet_name]) edit_id = result[0].split('=')[1] ServiceTemplate().rbTemplateGET(gaolu_login_report, templateId_ids[sheet_name]) content_resp = ServiceTemplate().rbInstanceGET( gaolu_login_report, edit_id) body = content_resp.get('source_response')['data'] with allure.step("获取提交表单id"): submit_resp = ServiceTemplate().rbInstancePUT( gaolu_login_report, edit_id, body) waitForStatus(submit_resp, 200, 200, 15) base_utils.file_is_exist(env_conf['用例配置']['高级表单']['文件路径']) os.rename(env_conf['用例配置']['高级表单']['文件路径'], "data/" + sheet_name + ".pdf") resp = Content().contentGET(gaolu_login, ids[sheet_name]) with allure.step("提交表单内容"): res = Content().contentPOST( gaolu_login, resp.get('source_response')['data']['id'], "data/" + sheet_name + ".pdf", 'application/pdf') os.rename("data/" + sheet_name + ".pdf", env_conf['用例配置']['高级表单']['文件路径']) waitForStatus(res, 200, 200, 15) with allure.step("删除子表单"): delete_sheet3 = Sort().formInstancesDELETE(gaolu_login, ids[sheet_name]) waitForStatus(delete_sheet3, 200, 200, 15) with allure.step('删除父表单'): delete_sheet1 = FormGroup().deleteFormGroupsDELETE( gaolu_login, formGroup_id) waitForStatus(delete_sheet1, 200, 200, 15)