def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.point_id_tup = self.teacher_parm.get_point_id() self.all_point_resource_id_list = self.teacher_parm.get_all_point_resource_id( 1) self.teacher_class_id_list = self.teacher_parm.get_class_list( get_all=True) self.student_class_id_list = self.student_parm.get_class_list( get_all=True) self.series_id_list = self.teacher_parm.get_series_list(2) self.teacher_id, self.school_id = self.teacher_parm.get_user_school_id( ) self.student_id, _ = self.student_parm.get_user_school_id() self.teacher_homework_id_list = self.teacher_parm.get_homework_id_list( teacher=True) self.student_homework_id_list = self.student_parm.get_homework_id_list( ) self.teacher_problem_id_list = self.teacher_parm.teacher_get_homework_problem_id_list( ) self.student_problem_id_list = self.student_parm.student_get_problem_id_list( )
class TestGetOfflineFile(unittest.TestCase): def setUp(self): self.parameter = ParameterForOthers(identity='teacher') self.ip = self.parameter.ip self.headers = self.parameter.headers def test_01(self): series_list = self.parameter.get_series_list() for s in series_list: os.makedirs(f'E://offline_series{s}', exist_ok=True) all_point_resource_id_list = self.parameter.get_all_point_resource_id(s) for r in all_point_resource_id_list: url = f'{self.ip}/teachcenter/coursemanage/offline/{r["id"]}/{r["resource_id"]}' response = requests.get(url=url, headers=self.headers) time.sleep(1.5) data_ret = response.json() msg = data_ret['msg'] try: self.assertEqual(msg, '操作成功') except AssertionError: print(f'{r}资源报错:{msg}') else: data_url = data_ret['data'] download = requests.get(url=data_url, headers=self.headers) with open(f'E://offline_series{s}/{r["resource_id"]}.zip', 'wb') as zip_file: zip_file.write(download.content)
def setUp(self) -> None: self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.category_id_list = self.student_parm.get_category_list()
def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers
def setUp(self) -> None: self.manager_param = ParameterForOthers(identity='manager') self.teacher_param = ParameterForOthers(identity='teacher') self.student_param = ParameterForOthers(identity='student') self.ip = self.teacher_param.ip self.manager_id, self.school_id = self.manager_param.get_user_school_id() self.class_id_list = self.manager_param.get_manage_class_list(self.school_id) self.student_id_list = self.manager_param.get_class_student_id(self.class_id_list[1], self.school_id) self.file_path = f'{get_absolute_path("interface")}\\K12edu\\files\\'
class TestCategorySucai(unittest.TestCase): """试炼场素材分类和素材添加修改删除""" def setUp(self) -> None: self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.category_id_list = self.student_parm.get_category_list() def test_01_add_category(self): url = f'{self.ip[:-8]}/ddc-port/play/addSucaiCategory' data = { 'categoryName': '接口添加分类待删' } response = requests.post(url=url, headers=self.student_headers, json=data) assert_res(response.text, '操作成功') def test_02_add_image(self): image_name = '1-43.jpg' url = f'{self.ip[:-8]}/ddc-port/play/userSaveImageFile' data = { 'categoryId': self.category_id_list[0], 'fileName': image_name, 'url': f'{self.student_parm.get_sucai_url()}{image_name}' } response = requests.post(url=url, headers=self.student_headers, json=data) assert_res(response.text, '操作成功') def test_03_change_category(self): url = f'{self.ip[:-8]}/ddc-port/play/changeSucaiCategory/{self.category_id_list[0]}?categoryName=接口修改分类待删' response = requests.put(url=url, headers=self.student_headers) assert_res(response.text, '操作成功') def test_04_change_image_name(self): image_id = self.student_parm.get_image_id_list(self.category_id_list[1])[0] url = f'{self.ip[:-8]}/ddc-port/play/changeImageFileName/{image_id}?imageTitle=接口修改素材名称待删.jpg' response = requests.put(url=url, headers=self.student_headers) assert_res(response.text, '操作成功') def test_05_del_image(self): image_id = self.student_parm.get_image_id_list(self.category_id_list[0])[0] url = f'{self.ip[:-8]}/ddc-port/play/deleteImageFile?imageId={image_id}' response = requests.delete(url=url, headers=self.student_headers) assert_res(response.text, '操作成功') def test_06_del_category(self): url = f'{self.ip[:-8]}/ddc-port/play/deleteSucaiCategory?categoryId={self.category_id_list[0]}' response = requests.delete(url=url, headers=self.student_headers) assert_res(response.text, '操作成功')
def setUp(self) -> None: self.manager_param = ParameterForOthers(identity='manager') self.teacher_param = ParameterForOthers(identity='teacher') self.student_param = ParameterForOthers(identity='student') self.ip = self.manager_param.ip self.manager_headers = self.manager_param.headers self.teacher_id_list = self.manager_param.get_manage_teacher_list() self.manager_id, self.school_id = self.manager_param.get_user_school_id( ) self.class_id = self.manager_param.get_class_list(get_all=True) self.teacher_mobile_num = '1520840000' self.file_path = f'{get_absolute_path("interface")}\\K12edu\\files\\'
def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.series_id_list = self.teacher_parm.get_series_list(2) self.teacher_class_id_list = self.teacher_parm.get_class_list(get_all=True) self.student_class_id_list = self.student_parm.get_class_list(get_all=True) self.student_id, _ = self.student_parm.get_user_school_id()
def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.course_id_list = self.teacher_parm.get_user_course_list() self.point_id_tup = self.teacher_parm.get_point_id() self.all_point_resource_id_list = self.teacher_parm.get_all_point_resource_id(1) self.class_id_list = self.teacher_parm.get_class_list(get_all=True) self.series_id_list = self.teacher_parm.get_series_list()
def test_post_homework_loop(self): """ 老师遍历发布设置发布作业 :return: """ for a in range(3): for d in range(2): for t in range(2): param = { 'hw_name': f'答案{a}难度{d}定时{t}', 'series_id': self.series_id_list[1], 'point_id_list': [self.point_id_tup[0]], 'show_answer': a, 'show_difficulty': d, 'timing': t } add_result = add_homework(self.teacher_parm, **param) if add_result and t == 0: c = 0 for student_username in self.teacher_parm.teacher_get_hw_student_num( ): student_param = ParameterForOthers( 'student', student_username) do_homework_simple(student_param, cut_num=c) c -= 1
def test_post_simple_series_problem(self): """ 教师发布单个系列全部题目 :return: """ series_id = 1 all_point_resource_id_list = self.teacher_parm.get_all_point_resource_id( series_id) all_point_id_list = [ id_dic['id'] for id_dic in all_point_resource_id_list ] for point_id in all_point_id_list: param = { 'hw_name': f'S{series_id}的{point_id}', 'series_id': series_id, 'point_id_list': [point_id], 'show_answer': 1, 'show_difficulty': 1, 'timing': 0 } add_result = add_homework(self.teacher_parm, **param) if add_result: c = 0 for student_username in self.teacher_parm.teacher_get_hw_student_num( ): student_param = ParameterForOthers('student', student_username) do_homework_simple(student_param, cut_num=c) c -= 1
class DoHomework(unittest.TestCase): def setUp(self) -> None: self.parameter = ParameterForOthers(identity='student') self.ip = self.parameter.ip self.headers = self.parameter.headers point_id_list = self.parameter.get_point_id() self.point_id = point_id_list[0] def test_do_homework_01(self): do_homework_simple(self.parameter, cut_num=None) def test_do_homework_02(self): do_homework_simple(self.parameter, cut_num=None) def test_03_do_homework_loop(self): do_homework_simple(self.parameter, cut_num=None, homework_num=3)
def test_post_homework(self): """ 老师发布单个作业 :return: """ param = { 'hw_name': '接口发布作业', 'series_id': self.series_id_list[1], 'point_id_list': [self.point_id_tup[0]], 'show_answer': 1, 'show_difficulty': 1, 'timing': 0 } add_result = add_homework(self.teacher_parm, **param) if add_result: c = 0 for student_username in self.teacher_parm.teacher_get_hw_student_num( ): student_param = ParameterForOthers('student', student_username) do_homework_simple(student_param, cut_num=c) c -= 1
class TeacherManageController(unittest.TestCase): def setUp(self) -> None: self.manager_param = ParameterForOthers(identity='manager') self.teacher_param = ParameterForOthers(identity='teacher') self.student_param = ParameterForOthers(identity='student') self.ip = self.manager_param.ip self.manager_headers = self.manager_param.headers self.teacher_id_list = self.manager_param.get_manage_teacher_list() self.manager_id, self.school_id = self.manager_param.get_user_school_id( ) self.class_id = self.manager_param.get_class_list(get_all=True) self.teacher_mobile_num = '1520840000' self.file_path = f'{get_absolute_path("interface")}\\K12edu\\files\\' def test_01_add_teacher(self): """ 管理员添加老师 :return: """ url = f'{self.ip}/teachcenter/teachermanage/add' data = { "classIds": self.class_id[:1], "gender": 1, "mobile": f"{self.teacher_mobile_num}0", "position": "test", "schoolId": self.school_id, "tchName": "接口添加老师" } res = requests.post(url=url, headers=self.manager_headers, json=data) assert_res(res.text) def test_02_change_teacher(self): """ 管理员修改老师 :return: """ url = f'{self.ip}/teachcenter/teachermanage/edit' for m in [3, 0]: data = { "classIds": self.class_id[:2], "gender": 2, "mobile": f"{self.teacher_mobile_num}{m}", "position": "change_test", "schoolId": self.school_id, "tchId": self.teacher_id_list[0], "tchName": "接口修改老师" } res = requests.post(url=url, headers=self.manager_headers, json=data) assert_res(res.text) def test_03_get_teacher_list(self): """ 获取老师管理列表 :return: """ url = f'{self.ip}/teachcenter/teachermanage/list' for t in range(1, 4): for k in ['', '接口']: data = { "currPage": 1, "keyword": k, "pageSize": 40, "schoolId": self.school_id, "tchType": t } res = requests.post(url=url, headers=self.manager_headers, json=data) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print( f'接口/teachcenter/teachermanage/list报错,返回{data_ret["msg"]}' ) except KeyError: print(f'接口/teachcenter/teachermanage/list返回{data_ret}') else: pprint([{i['tchId']: i['tchName']} for i in data_list]) def test_04_delete_teacher(self): """ 管理员删除教师 :return: """ url = f'{self.ip}/teachcenter/teachermanage/remove' data = {"schoolId": self.school_id, "tchIds": self.teacher_id_list[:1]} res = requests.post(url=url, headers=self.manager_headers, json=data) assert_res(res.text) def test_05_teacher_select_list(self): """ 教师管理-查询下拉-列表 :return: """ url = f'{self.ip}/teachcenter/teachermanage/selectList' params = f'schoolId={self.school_id}' res = requests.get(url=url, headers=self.manager_headers, params=params) assert_res(res.text) def test_06_export(self): """ 教师管理-批量导出 :return: """ url = f'{self.ip}/teachcenter/teachermanage/export' params = f'exportType=1&tchType=1&schoolId={self.school_id}' res = requests.get(url=url, headers=self.manager_headers, params=params) file_name = 'teacher_export.xls' file_write(f'{self.file_path}export\\', file_name, res.content) def test_07_export_temp(self): """ 教师管理-模板导出 :return: """ url = f'{self.ip}/teachcenter/teachermanage/exportTemp' res = requests.get(url=url, headers=self.manager_headers) file_name = 'teacher_temp.xls' file_write(f'{self.file_path}export\\', file_name, res.content) def test_08_file_import(self): """ 教师管理-批量导入 :return: """ from requests_toolbelt.multipart.encoder import MultipartEncoder url = f'{self.ip}/teachcenter/teachermanage/fileImport' file_name = 'teacher.xls' with open(f'{self.file_path}upload\\{file_name}', 'rb') as f: m = MultipartEncoder( {'file': (file_name, f, 'application/vnd.ms-excel')}) self.manager_headers['Content-Type'] = m.content_type params = f'schoolId={self.school_id}' res = requests.post(url=url, headers=self.manager_headers, data=m, params=params) assert_res(res.text, '批量导入用户失败') data_ret = res.json() try: print(data_ret['data']['errMsg']) except TypeError: print( f'接口/teachcenter/teachermanage/fileImport报错,返回{data_ret["msg"]}' ) except KeyError: print(f'接口/teachcenter/teachermanage/fileImport返回{data_ret}')
def setUp(self) -> None: self.parameter = ParameterForOthers(identity='student') self.ip = self.parameter.ip self.headers = self.parameter.headers
def setUp(self): self.parameter = ParameterForOthers(identity='teacher') self.url = f'{self.parameter.ip}/pc/resource/addResource' self.headers = self.parameter.headers
def setUp(self): self.parameter = ParameterForOthers(identity='teacher') self.ip = self.parameter.ip self.headers = self.parameter.headers
def setUp(self) -> None: self.parameter = ParameterForOthers(identity='student') self.ip = self.parameter.ip self.headers = self.parameter.headers point_id_list = self.parameter.get_point_id() self.point_id = point_id_list[0]
class HomeworkController(unittest.TestCase): """作业页面""" def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.point_id_tup = self.teacher_parm.get_point_id() self.all_point_resource_id_list = self.teacher_parm.get_all_point_resource_id( 1) self.teacher_class_id_list = self.teacher_parm.get_class_list( get_all=True) self.student_class_id_list = self.student_parm.get_class_list( get_all=True) self.series_id_list = self.teacher_parm.get_series_list(2) self.teacher_id, self.school_id = self.teacher_parm.get_user_school_id( ) self.student_id, _ = self.student_parm.get_user_school_id() self.teacher_homework_id_list = self.teacher_parm.get_homework_id_list( teacher=True) self.student_homework_id_list = self.student_parm.get_homework_id_list( ) self.teacher_problem_id_list = self.teacher_parm.teacher_get_homework_problem_id_list( ) self.student_problem_id_list = self.student_parm.student_get_problem_id_list( ) @pytest.mark.run(order=1) def test_post_homework(self): """ 老师发布单个作业 :return: """ param = { 'hw_name': '接口发布作业', 'series_id': self.series_id_list[1], 'point_id_list': [self.point_id_tup[0]], 'show_answer': 1, 'show_difficulty': 1, 'timing': 0 } add_result = add_homework(self.teacher_parm, **param) if add_result: c = 0 for student_username in self.teacher_parm.teacher_get_hw_student_num( ): student_param = ParameterForOthers('student', student_username) do_homework_simple(student_param, cut_num=c) c -= 1 @pytest.mark.run(order=2) def test_post_homework_loop(self): """ 老师遍历发布设置发布作业 :return: """ for a in range(3): for d in range(2): for t in range(2): param = { 'hw_name': f'答案{a}难度{d}定时{t}', 'series_id': self.series_id_list[1], 'point_id_list': [self.point_id_tup[0]], 'show_answer': a, 'show_difficulty': d, 'timing': t } add_result = add_homework(self.teacher_parm, **param) if add_result and t == 0: c = 0 for student_username in self.teacher_parm.teacher_get_hw_student_num( ): student_param = ParameterForOthers( 'student', student_username) do_homework_simple(student_param, cut_num=c) c -= 1 @pytest.mark.run(order=3) def test_post_simple_series_problem(self): """ 教师发布单个系列全部题目 :return: """ series_id = 1 all_point_resource_id_list = self.teacher_parm.get_all_point_resource_id( series_id) all_point_id_list = [ id_dic['id'] for id_dic in all_point_resource_id_list ] for point_id in all_point_id_list: param = { 'hw_name': f'S{series_id}的{point_id}', 'series_id': series_id, 'point_id_list': [point_id], 'show_answer': 1, 'show_difficulty': 1, 'timing': 0 } add_result = add_homework(self.teacher_parm, **param) if add_result: c = 0 for student_username in self.teacher_parm.teacher_get_hw_student_num( ): student_param = ParameterForOthers('student', student_username) do_homework_simple(student_param, cut_num=c) c -= 1 @pytest.mark.run(order=4) def test_post_all_problem(self): """ 老师发布全部题目,发之前要确定这个班有权限 :return: """ for series_id in self.series_id_list: all_point_resource_id_list = self.teacher_parm.get_all_point_resource_id( series_id) all_point_id_list = [ id_dic['id'] for id_dic in all_point_resource_id_list ] for point_id in all_point_id_list: param = { 'hw_name': f'S{series_id}的{point_id}', 'series_id': series_id, 'point_id_list': all_point_id_list, 'show_answer': 1, 'show_difficulty': 1, 'timing': 0 } add_homework(self.teacher_parm, **param) do_homework_simple(self.student_parm, cut_num=None) @pytest.mark.run(order=5) def test_teacher_homework_list(self): """ 老师作业列表 :return: """ url = f'{self.ip}/homework/tchHwList' for class_id in list(chain(self.teacher_class_id_list, [''])): for homework_name in ['', '接口']: for status in ['', 1, 2, 3]: # 待定 data = { 'schoolId': self.school_id, 'classId': class_id, 'homeworkName': homework_name, 'pageSize': 30, 'status': status, 'currPage': 1 } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口"/homework/tchHwList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwList"返回{data_ret}') else: print([{ i['homeworkId']: i['homeworkName'] } for i in data_list]) @pytest.mark.run(order=6) def test_teacher_homework_class_list(self): """ 老师发布作业班级选择 :return: """ url = f'{self.ip}/homework/tchHwClassList' data = {"schoolId": self.school_id, "seriesId": self.series_id_list[1]} res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: print(data_ret['data']) except TypeError: print(f'接口"/homework/tchHwClassList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwClassList"返回{data_ret}') @pytest.mark.run(order=7) def test_teacher_homework_analysis_list(self): """ 教师端题目分析统计列表 :return: """ url = f'{self.ip}/homework/tchHwAnalysisList' data = { "currPage": 1, "hwId": self.teacher_homework_id_list[0], "pageSize": 30 } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口"/homework/tchHwAnalysisList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwAnalysisList"返回{data_ret}') else: print([{ i['problemId']: [i['problemName'], i['correctRate']] } for i in data_list]) @pytest.mark.run(order=8) def test_teacher_homework_analysis_problem_list(self): """ 教师端-题目分析-题目列表 :return: """ url = f'{self.ip}/homework/tchHwAnsProblemList' data = {"hwId": self.teacher_homework_id_list[0]} res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: print([{ i['problemId']: [i['problemName'], i['correctRate']] } for i in data_ret['data']]) except TypeError: print(f'接口"/homework/tchHwAnsProblemList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwAnsProblemList"返回{data_ret}') @pytest.mark.run(order=9) def test_teacher_homework_class_list(self): """ 教师端作业发布班级选择 :return: """ url = f'{self.ip}/homework/tchHwClassList' data = { "schoolId": self.school_id, "seriesId": self.series_id_list[1], "seriesType": 0 } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: print([{i['id']: i['name']} for i in data_ret['data']]) except TypeError: print(f'接口"/homework/tchHwClassList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwClassList"返回{data_ret}') @pytest.mark.run(order=10) def test_teacher_homework_current_student_list(self): """ 教师端当前作业学生下拉列表 :return: """ self.teacher_problem_id_list = self.teacher_parm.teacher_get_homework_problem_id_list( ) url = f'{self.ip}/homework/tchHwCurrentStuList' for subject_id, subject_type in self.teacher_problem_id_list: data = { "hwId": self.teacher_homework_id_list[0], "subjectId": subject_id, "subjectType": subject_type } res = requests.post(url=url, headers=self.teacher_parm.headers, json=data) assert_res(res.text) data_ret = res.json() try: print([(i['studentId'], i['studentName'], i['status']) for i in data_ret['data']]) except TypeError: print( f'接口"/homework/tchHwCurrentStuList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwCurrentStuList"返回{data_ret}') @pytest.mark.run(order=11) def test_teacher_homework_list(self): """ 教师作业信息查询 :return: """ url = f'{self.ip}/homework/tchHwList/{self.teacher_homework_id_list[0]}' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) data_ret = res.json() try: print({data_ret['data']['hwName']: data_ret['data']['status']}) except TypeError: print(f'接口"/homework/tchHwList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwList"返回{data_ret}') @pytest.mark.run(order=12) def test_teacher_homework_problem_info(self): """ 教师端题目查看 :return: """ url = f'{self.ip}/homework/tchHwProblemInfo' for subject_id, subject_type in self.teacher_problem_id_list: data = { "hwId": self.teacher_homework_id_list[0], "studentId": self.student_id, "subjectId": subject_id, "subjectType": subject_type } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: print({ data_ret['data']['problemId']: data_ret['data']['problemName'] }) except TypeError: print(f'接口"/homework/tchHwProblemInfo"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwProblemInfo"返回{data_ret}') @pytest.mark.run(order=13) def test_teacher_homework_problem_list(self): """ 教师端-学生列表-题目列表查询 :return: """ url = f'{self.ip}/homework/tchHwProblemList' data = { "hwId": self.teacher_homework_id_list[0], "stuId": self.student_id } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: print([{ i['problemName']: i['problemStatus'] } for i in data_ret['data']]) except TypeError: print(f'接口"/homework/tchHwProblemList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwProblemList"返回{data_ret}') @pytest.mark.run(order=14) def test_teacher_homework_problem_oj(self): """ 教师端-测评-预览测评/指定学生 :return: """ url = f'{self.ip}/homework/tchHwProblemOj' for subject_id, subject_type in self.teacher_problem_id_list: data = oj_data(subject_id, subject_type, self.teacher_homework_id_list[0]) res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) @pytest.mark.run(order=15) def test_teacher_homework_series_list(self): """ 教师端-作业发布-系列下拉选取 :return: """ url = f'{self.ip}/homework/tchHwSeriesList' data = { "classIds": self.teacher_class_id_list, "schoolId": self.school_id } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: print([{i['name']: i['id']} for i in data_ret['data']]) except TypeError: print(f'接口"/homework/tchHwSeriesList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwSeriesList"返回{data_ret}') @pytest.mark.run(order=16) def test_teacher_homework_student_list(self): """ 教师端-学生成绩列表 :return: """ url = f'{self.ip}/homework/tchHwStuList' data = { "currPage": 1, "hwId": self.teacher_homework_id_list[0], "pageSize": 30 } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口"/homework/tchHwStuList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/tchHwStuList"返回{data_ret}') else: print([{ i['studentName']: [ i['result'], i['correctCount'], i['finishedCount'], i['level'] ] } for i in data_list]) @pytest.mark.run(order=17) def test_teacher_homework_student_resend(self): """ 教师端-学生作业重交 :return: """ url = f'{self.ip}/homework/tchHwStuResend' data = { "studentEvalId": self.teacher_parm.teacher_get_student_eval_id_list()[-1] } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) @pytest.mark.run(order=18) def test_teacher_homework_delete(self): """ 教师删除作业 :return: """ for i in range(12): url = f'{self.ip}/homework/tchHwDelete' data = { "classId": self.teacher_class_id_list[-1], "hwId": self.teacher_homework_id_list[i] } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) @pytest.mark.run(order=19) def test_student_homework_list(self): """ 学生端-作业列表-作业列表查询 :return: """ url = f'{self.ip}/homework/stuHwList' class_id_list = self.student_class_id_list class_id_list.append('') for class_id in class_id_list: for status in ['', 0, 1, 2]: for homework_name in ['', '接口']: data = { "classId": class_id, "currPage": 1, "homeworkName": homework_name, "pageSize": 100, "schoolId": self.school_id, "status": status } res = requests.post(url=url, headers=self.student_headers, json=data) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口"/homework/stuHwList"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/stuHwList"返回{data_ret}') else: print([{ i['homeworkId']: i['homeworkName'] } for i in data_list]) @pytest.mark.run(order=20) def test_student_homework_add_eval(self): """ 学生端-作业列表-开始做作业(exist为0时调用) :return: """ url = f'{self.ip}/homework/stuHwAddEval' data = {"hwId": self.student_homework_id_list[0]} res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: data_dic = data_ret['data'] print((data_dic['studentName'], data_dic['result'])) except TypeError: print(f'接口"/homework/stuHwAddEval"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/stuHwAddEval"返回{data_ret}') @pytest.mark.run(order=21) def test_student_homework_problem_info(self): """ 学生端-作业题目-详细查询 :return: """ url = f'{self.ip}/homework/stuHwProblemInfo' for p, t in self.student_problem_id_list: data = { "hwId": self.student_homework_id_list[0], "subjectId": p, "subjectType": t } res = requests.post(url=url, headers=self.student_headers, json=data) assert_res(res.text) data_ret = res.json() try: data_dic = data_ret['data'] print((data_dic['problemName'], data_dic['problemAnswer'], data_dic['userCode'])) except TypeError: print(f'接口"/homework/stuHwProblemInfo"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/stuHwProblemInfo"返回{data_ret}') @pytest.mark.run(order=22) def test_student_homework_student_info(self): """ 学生端-作业列表-学生信息栏查询 :return: """ url = f'{self.ip}/homework/stuHwStuInfo' data = {"hwId": self.student_homework_id_list[0]} res = requests.post(url=url, headers=self.student_headers, json=data) assert_res(res.text) data_ret = res.json() try: data_dic = data_ret['data'] print((data_dic['studentName'], data_dic['result'], data_dic['finishedCount'])) except TypeError: print(f'接口"/homework/stuHwStuInfo"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/homework/stuHwStuInfo"返回{data_ret}')
class CommonController(unittest.TestCase): """公共数据""" def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.class_list = self.teacher_parm.get_class_list() self.teacher_id, self.school_id = self.teacher_parm.get_user_school_id( ) self.student_id, _ = self.student_parm.get_user_school_id() @pytest.mark.run(order=1) def test_class(self): """ 班级信息 :return: """ url = f'{self.ip}/common/class/{self.class_list[0]}' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) data_ret = res.json() try: print({data_ret['data']['name']: data_ret['data']['teachNames']}) except TypeError: print(f'接口/common/class报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/common/class,返回{data_ret},与预期不符') @pytest.mark.run(order=2) def test_classes(self): """ 班级列表 :return: """ url = f'{self.ip}/common/classes' for i in ['teacher', 'student']: user_id = self.teacher_id if i == 'teacher' else self.student_id headers = self.teacher_headers if i == 'teacher' else self.student_headers data = f'userId={user_id}&schoolId={self.school_id}' res = requests.get(url=url, headers=headers, params=data) assert_res(res.text) data_ret = res.json() try: data_list = data_ret['data'] for data in data_list: print({data['name']: data['teachNames']}) except TypeError: print(f'接口/common/classes,返回{data_ret["msg"]}') except KeyError: print(f'接口/common/classes,返回{data_ret},与预期不符') @pytest.mark.run(order=3) def test_points(self): """ 知识点树 :return: """ series_id_list = self.teacher_parm.get_series_list() if series_id_list: for s in series_id_list: url = f'{self.ip}/common/points/{s}' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) data_ret = res.json() series_point_id_list = [] try: data_list = data_ret['data'] for d in data_list: child_id_list = [c['id'] for c in d['children']] series_point_id_list.append(child_id_list) print(list(chain(*series_point_id_list))) except TypeError: print(f'接口/common/points,返回{data_ret["msg"]}') except KeyError: print(f'接口/common/points,返回{data_ret},与预期不符') @pytest.mark.run(order=4) def test_roles(self): """ 角色列表 :return: """ url = f'{self.ip}/common/roles' manager_id, _ = self.manager_parm.get_user_school_id() school_id_list = self.manager_parm.get_school_id_list() for s in school_id_list: data = f'userId={manager_id}&schoolId={s}' res = requests.get(url=url, headers=self.manager_headers, params=data) assert_res(res.text) data_ret = res.json() try: print(data_ret['data']) except TypeError: print(f'接口/common/roles,返回{data_ret["msg"]}') except KeyError: print(f'接口/common/roles,返回{data_ret},与预期不符') @pytest.mark.run(order=5) def test_schools(self): """ 学校列表 :return: """ url = f'{self.ip}/common/schools' data = f'userId={self.student_id}' res = requests.get(url=url, headers=self.student_headers, params=data) assert_res(res.text) data_ret = res.json() try: print(data_ret['data']) except TypeError: print(f'接口/common/schools,返回{data_ret["msg"]}') except KeyError: print(f'接口/common/schools,返回{data_ret},与预期不符') @pytest.mark.run(order=6) def test_series(self): """ 系列课程 :return: """ url = f'{self.ip}/common/series' for m in range(1, 3): data = { "schoolId": self.school_id, "seriesType": 0, "moduleType": m } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: pprint([{d['id']: d['name']} for d in data_ret['data']]) except TypeError: print(f'接口/common/series,返回{data_ret["msg"]}') except KeyError: print(f'接口/common/series,返回{data_ret},与预期不符') @pytest.mark.run(order=7) def test_default_covers(self): """ 默认封面 :return: """ url = f'{self.ip}/common/default/covers' content_type = list(range(5)) content_type.append(-1) for i in content_type: res = requests.get(url=url, headers=self.teacher_headers, params=f'coverType={i}') assert_res(res.text) time.sleep(1) data_ret = res.json() try: pprint([{i['name']: i['coverUrl']} for i in data_ret['data']]) except TypeError: print(f'接口/common/default/covers,返回{data_ret["msg"]}') except KeyError: print(f'接口/common/default/covers,返回{data_ret},与预期不符') def resource(self): """
class TestUser(unittest.TestCase): def setUp(self): self.teacher_params = ParameterForOthers(identity='teacher') self.ip = self.teacher_params.ip self.teacher_headers = self.teacher_params.headers def test_login_01(self): """ 登录接口 :return: """ headers = { 'Content-Type': "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/73.0.3683.86 Safari/537.36" } url = f'{self.ip}/user/login' username = Data().teacher_data()['username'] password = Data().teacher_data()['password'] data = {"password": password, "username": username} response = requests.post(url=url, json=data, headers=headers) assert_res(response.text) def test_login_02(self): headers = { 'Content-Type': "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/73.0.3683.86 Safari/537.36" } url = f'{self.ip}/user/login' username = Data().teacher_data()['username'] data = {"password": '******', "username": username} response = requests.post(url=url, json=data, headers=headers) assert_res(response.text, '用户名/密码错误') def test_login_03(self): headers = { 'Content-Type': "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/73.0.3683.86 Safari/537.36" } url = f'{self.ip}/user/login' data = {"password": '******', "username": '******'} response = requests.post(url=url, json=data, headers=headers) assert_res(response.text, '账号不存在') def test_login_04(self, ): headers = { 'Content-Type': "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/73.0.3683.86 Safari/537.36" } url = f'{self.ip}/user/login' data = {"password": '******', "username": None} response = requests.post(url=url, json=data, headers=headers) assert_res(response.text, '参数校验失败') def test_login_05(self): headers = { 'Content-Type': "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/73.0.3683.86 Safari/537.36" } username = Data().teacher_data()['username'] url = f'{self.ip}/user/login' data = {"password": None, "username": username} response = requests.post(url=url, json=data, headers=headers) assert_res(response.text, '参数校验失败') def test_01_send_auth(self): """ 忘记密码-身份验证-发送验证码 :return: """ url = f'{self.ip}/user/forgetPassword/auth/send' for i in range(1, 3): username = '******' if i == 1 else '*****@*****.**' data = f'type={i}&username={username}' response = requests.get(url=url, headers=self.teacher_headers, params=data) assert_res(response.text) def test_02_modify_password(self): """ 账号设置-修改密码 :return: """ url = f'{self.ip}/user/username/modify/password' params = f"password={Data().teacher_data()['password']}&newPassword=1234567re&rePassword=1234567" response = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(response.text) def test_03_password_reset(self): """ 用户-重置密码 :return: """ user_id, _ = self.teacher_params.get_user_school_id() url = f'{self.ip}/user/password/reset/{user_id}' response = requests.get(url=url, headers=self.teacher_headers) assert_res(response.text) def test_04_subject_feedback(self): url = f'{self.ip}/user/subject/feedback' data = { "feedbackDetail": "string", "feedbackType": 1, "subjectId": 251, "subjectType": 1 } response = requests.post(url=url, json=data, headers=self.teacher_headers) assert_res(response.text, ) def test_05_logout(self): """ 注销 :return: """ url = f'{self.ip}/user/logout' response = requests.get(url=url, headers=self.teacher_headers) assert_res(response.text) def test_06_user_info(self): """ 用户信息 :return: """ url = f'{self.ip}/user/userinfo' response = requests.get(url=url, headers=self.teacher_headers) assert_res(response.text) def test_07_switch_school(self): """ 切换学校 :return: """ school_id_list = self.teacher_params.get_school_id_list() for i in [1, 0]: url = f'{self.ip}/user/switch/school/{school_id_list[i]}' response = requests.get(url=url, headers=self.teacher_headers) assert_res(response.text) def test_08_user_modify(self): """ 用户信息验证 :return: """ portrait_url, gender = self.teacher_params.get_user_portrait_url_gender( ) data = f'nickname={Data().teacher_data()["name"]}&gender={gender}&portraitUrl={portrait_url}' url = f'{self.ip}/user/modify?{data}' response = requests.post(url=url, headers=self.teacher_headers) assert_res(response.text)
class CourseController(unittest.TestCase): """课程页面""" def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.course_id_list = self.teacher_parm.get_user_course_list() self.point_id_tup = self.teacher_parm.get_point_id() self.all_point_resource_id_list = self.teacher_parm.get_all_point_resource_id(1) self.class_id_list = self.teacher_parm.get_class_list(get_all=True) self.series_id_list = self.teacher_parm.get_series_list() @pytest.mark.run(order=1) def test_teacher_issue(self): """ 老师单独发布一个课程并编辑删除 :return: """ add_course(self.teacher_parm, self.class_id_list[-1], self.series_id_list[0]) edit_course(self.teacher_parm, self.course_id_list[0], course_plan=True) finish_course(self.teacher_parm, self.course_id_list[0]) del_course(self.teacher_parm, self.course_id_list[0]) @pytest.mark.run(order=2) def test_teacher_issue(self): """ 老师发布所有系列课程 :return: """ for series_id in self.series_id_list: add_course(self.teacher_parm, self.class_id_list[-1], series_id) time.sleep(1) @pytest.mark.run(order=3) def test_teacher_switch_point(self): """ 老师切换知识点标识 :return: """ for f in [1, 0]: # 0-关闭 1-开启 url = f'{self.ip}/course/teacher/' \ f'{self.course_id_list[0]}/{self.class_id_list[-1]}/{self.point_id_tup[1]}/switch/{f}' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) time.sleep(1) @pytest.mark.run(order=4) def test_user_courses(self): """ 用户课程列表 :return: """ url = f'{self.ip}/course/user/courses' for class_id in self.class_id_list: for series_id in self.series_id_list: data = { "classId": class_id, "flag": 1, "pageNum": 1, "pageSize": 12, "seriesId": series_id } res = requests.post(url=url, headers=self.student_headers, json=data) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口"/course/user/courses"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/course/user/courses"返回{data_ret}') else: print([{i['id']: [i['seriesName'], i['issueName']]} for i in data_list]) @pytest.mark.run(order=5) def test_user_course_point_tag(self): """ 课程知识点标签信息 :return: """ url = f'{self.ip}/course/user/tag/course/points' for course_id in self.course_id_list: params = f'courseId={course_id}&classId={self.class_id_list[-1]}' res = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data'] print([{i['label']: [{s['label']: s['flag']} for s in i['children']]} for i in data_list]) except TypeError: print(f'接口"/course/user/tag/course/points"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/course/user/tag/course/points"返回{data_ret}') @pytest.mark.run(order=6) def test_teacher_practises(self): """ 老师查看学生练习 :return: """ all_point_id = [id_dic['id'] for id_dic in self.all_point_resource_id_list] for point_id in all_point_id: url = f'{self.ip}/course/teacher/' \ f'{self.course_id_list[0]}/{self.class_id_list[-1]}/{point_id}/practises' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_dic = data_ret['data'] print(f"{data_dic['practisedCount']}/{data_dic['practiseCount']},{data_dic['avgCorrectRate']}") practises_data = data_dic['practises'] pprint( [ {i['name']: i['correctRate'], 'subject': [{p['name']: p['result']} for p in i['subjects']]} for i in practises_data ] ) print('#################################################') except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/common/classes报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口"/practises"返回{data_ret}') @pytest.mark.run(order=7) def test_teacher_classes(self): """ 老师-可选班级 :return: """ url = f'{self.ip}/course/teacher/classes' for series_id in self.series_id_list: params = f'seriesId={series_id}' res = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: print([{i['id']: i['name']} for i in data_ret['data']]) except TypeError: print(f'接口"/course/teacher/classes"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/course/teacher/classes"返回{data_ret}') @pytest.mark.run(order=8) def test_user_course(self): """ 课程信息 :return: """ course_id_list = self.teacher_parm.get_user_course_list() for course_id in course_id_list: url = f'{self.ip}/course/user/course/{course_id}' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) data_ret = res.json() try: data_dic = data_ret['data'] print((data_dic['id'], data_dic['issuer'])) except TypeError: print(f'接口"/course/user/course"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/course/user/course"返回{data_ret}') @pytest.mark.run(order=9) def test_save_play_code(self): """ 课程-保存试炼场用户代码 :return: """ url = f'{self.ip}/course/user/save/playCode' data = { "classId": self.class_id_list[0], "courseId": self.course_id_list[0], "pointId": self.point_id_tup[0], "seriesId": self.series_id_list[0], "userCode": turtle_code() } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: save = data_ret['data'] except TypeError: print(f'接口"/course/user/save/playCode"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/course/user/save/playCode"返回{data_ret}') else: if save: url = f'{self.ip}/course/user/query/playCode' res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) data_ret = res.json() try: print(data_ret['data']) except TypeError: print(f'接口"/course/user/query/playCode"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/course/user/query/playCode"返回{data_ret}') @pytest.mark.run(order=10) def test_tag_course_current(self): """ 课程-已发布-当前授课标签信息 :return: """ url = f'{self.ip}/course/user/tag/course/current' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) data_ret = res.json() try: data_dic = data_ret['data'] print((data_dic['className'], data_dic['id'])) except TypeError: print(f'接口"/course/user/tag/course/current"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/course/user/tag/course/current"返回{data_ret}') @pytest.mark.run(order=11) def test_tag_course_point_current(self): """ 课程-已发布-当前授课知识点标签信息 :return: """ url = f'{self.ip}/course/user/tag/course/point/current' params = f'courseId={self.course_id_list[0]}&classId={self.class_id_list[-1]}' res = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(res.text) data_ret = res.json() try: data_dic = data_ret['data'] print((data_dic['label'], data_dic['resourceId'])) except TypeError: print(f'接口"/course/user/tag/course/point/current"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口"/course/user/tag/course/point/current"返回{data_ret}') @pytest.mark.run(order=12) def test_student_eval_save_record(self): """ 学生-课程练题评测&保存记录 :return: """ class_id = self.student_parm.get_class_list(get_all=True)[0] course_id = self.student_parm.get_user_course_list()[0] point_id_list = self.student_parm.get_all_point_resource_id(1) for id_dic in point_id_list: data = { 'class_id': class_id, 'course_id': course_id, 'point_id': id_dic['id'], 'subject_id_list': self.student_parm.get_practice_id_list(course_id, class_id, id_dic['id']) } print(student_do_practice(self.student_parm, **data))
class IndexController(unittest.TestCase): """公共数据""" def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers def test_01_student_dynamic(self): """ 学生同学动态 :return: """ for i in ['student', 'teacher']: url = f'{self.ip}/index/{i}/dynamic' data = 'pageNum=1&pageSize=10' header = self.student_headers if i == 'student' else self.teacher_headers res = requests.get(url=url, headers=header, params=data) assert_res(res.text) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口/index/{i}/dynamic报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/index/{i}/dynamic,返回{data_ret},与预期不符') else: print([i['nickname'] for i in data_list]) def test_02_student_homework(self): """ 学生最近作业 :return: """ for i in ['student', 'teacher']: url = f'{self.ip}/index/{i}/homework' header = self.student_headers if i == 'student' else self.teacher_headers data = 'pageNum=1&pageSize=10' res = requests.get(url=url, headers=header, params=data) assert_res(res.text) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口/index/{i}/homework报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/index/{i}/homework,返回{data_ret},与预期不符') else: print([{ i['homeworkName']: i['finishCount'] } for i in data_list]) def test_03_student_statistics(self): """ 学生统计 :return: """ for i in ['student', 'teacher']: url = f'{self.ip}/index/{i}/statistics' header = self.student_headers if i == 'student' else self.teacher_headers res = requests.get(url=url, headers=header) assert_res(res.text) print(res.text) def test_04_user_messages(self): """ 用户消息 :return: """ url = f'{self.ip}/index/user/messages' for s in range(2): data = {"pageNum": 1, "pageSize": 10, "status": s} res = requests.post(url=url, headers=self.student_headers, json=data) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口/index/user/messages,返回{data_ret["msg"]}') except KeyError: print(f'接口/index/user/messages,返回{data_ret},与预期不符') else: print([{i['id']: i['content']} for i in data_list]) def test_05_user_course(self): """ 用户最近课程 :return: """ series_id_list = self.teacher_parm.get_series_list() class_id_list = self.teacher_parm.get_class_list() url = f'{self.ip}/index/user/courses' for class_id in class_id_list: for series_id in series_id_list: for f in range(2): data = { "classId": class_id, "flag": f, "pageNum": 1, "pageSize": 10, "seriesId": series_id } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口/index/user/courses,返回{data_ret["msg"]}') except KeyError: print(f'接口/index/user/courses,返回{data_ret},与预期不符') else: print([{ i['seriesName']: [i['issueName'], i['planWeeks'], i['flag']] } for i in data_list]) def test_06_messages_opt(self): """ 用户消息操作 :return: """ msg_id_list = self.teacher_parm.get_msg_id_list() url = f'{self.ip}/index/user/messages/opt' for f in [1, 0, -1]: data = {"flag": f, "messageIds": [msg_id_list[0]]} res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) time.sleep(1)
class LearningController(unittest.TestCase): """学情分析""" def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers self.series_id_list = self.teacher_parm.get_series_list(2) self.teacher_class_id_list = self.teacher_parm.get_class_list(get_all=True) self.student_class_id_list = self.student_parm.get_class_list(get_all=True) self.student_id, _ = self.student_parm.get_user_school_id() def test_01_chart(self): """ 折线图(学生和老师) :return: """ for i in ['student', 'teacher']: url = f'{self.ip}/learning/{i}/chart' \ if 'student' == i else f'{self.ip}/learning/{i}/chart/{self.student_id}' header = self.student_headers if i == 'student' else self.teacher_headers class_id_list = self.student_class_id_list if i == 'student' else self.teacher_class_id_list for series_id in self.series_id_list: for class_id in class_id_list: for flag in ['', 1]: params = f'seriesId={series_id}&classId={class_id}&flag={flag}' \ if flag == 1 else f'seriesId={series_id}&classId={class_id}' res = requests.get(url=url, headers=header, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: print([{d['name']: d['grade']} for d in data_ret['data']]) except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/learning/{i}/chart报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口/learning/{i}/chart,返回{data_ret},与预期不符') def test_02_detail(self): """ 详情(学生和老师) :return: """ for i in ['student', 'teacher']: url = f'{self.ip}/learning/{i}/detail' \ if 'student' == i else f'{self.ip}/learning/{i}/detail/{self.student_id}' header = self.student_headers if i == 'student' else self.teacher_headers class_id_list = self.student_class_id_list if i == 'student' else self.teacher_class_id_list for series_id in self.series_id_list: for class_id in class_id_list: for flag in ['', 1]: params = f'seriesId={series_id}&classId={class_id}&flag={flag}' \ if flag == 1 else f'seriesId={series_id}&classId={class_id}' res = requests.get(url=url, headers=header, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: print([(d['name'], d['grade'], d['avgGrade']) for d in data_ret['data']]) except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/learning/{i}/detail报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口/learning/{i}/detail,返回{data_ret},与预期不符') def test_03_detail_page(self): """ 学生-自己详情 老师-学生详情-数据分页 :return: """ for i in ['student', 'teacher']: url = f'{self.ip}/learning/{i}/detail/page' \ if 'student' == i else f'{self.ip}/learning/{i}/detail/page/{self.student_id}' header = self.student_headers if i == 'student' else self.teacher_headers class_id_list = self.student_class_id_list if i == 'student' else self.teacher_class_id_list for series_id in self.series_id_list: for class_id in class_id_list: for flag in ['', 1]: params = f'seriesId={series_id}&classId={class_id}&flag={flag}&pageNum=1&pageSize=30' \ if flag == 1 else f'seriesId={series_id}&classId={class_id}&pageNum=1&pageSize=30' res = requests.get(url=url, headers=header, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/learning/{i}/detail/page报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口/learning/{i}/detail/page,返回{data_ret},与预期不符') else: print([(d['name'], d['grade'], d['avgGrade']) for d in data_list]) def test_04_evaluate(self): """ 学生-自己编程能力 老师-学生详情-编程能力 :return: """ out_list = [] for i in ['student', 'teacher']: url = f'{self.ip}/learning/{i}/evaluate' \ if 'student' == i else f'{self.ip}/learning/{i}/evaluate/{self.student_id}' header = self.student_headers if i == 'student' else self.teacher_headers res = requests.get(url=url, headers=header) assert_res(res.text) time.sleep(1) data_ret = res.json() try: out_list.append([{i['label']: i['score']} for i in data_ret['data']]) print(f'{i}:{[{i["label"]: i["score"]} for i in data_ret["data"]]}') except TypeError: print(f'接口"/learning/{i}/evaluate"报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/learning/{i}/evaluate,返回{data_ret},与预期不符') try: assert out_list[0] == out_list[1] except AssertionError: print('教师和学生数据不一致') def test_05_weak(self): """ 学生-自己薄弱统计 老师-学生详情-薄弱统计 :return: """ for i in ['student', 'teacher']: url = f'{self.ip}/learning/{i}/weak' \ if 'student' == i else f'{self.ip}/learning/{i}/weak/{self.student_id}' header = self.student_headers if i == 'student' else self.teacher_headers for series_id in self.series_id_list: params = f'seriesId={series_id}' res = requests.get(url=url, headers=header, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: print([{i['label']: i['grade']} for i in data_ret['data']]) except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/learning/{i}/weak报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口/learning/{i}/weak,返回{data_ret},与预期不符') def test_06_teacher_analysis(self): """ 老师-学情分析 :return: """ url = f'{self.ip}/learning/teacher/analysis' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) def test_07_teacher_classes(self): """ 老师-班级信息 :return: """ url = f'{self.ip}/learning/teacher/classes' res = requests.get(url=url, headers=self.teacher_headers) assert_res(res.text) def test_08_teacher_course(self): """ 老师-课程统计 老师-作业统计 :return: """ for i in ['course', 'homework']: url = f'{self.ip}/learning/teacher/{i}' for series_id in self.series_id_list: for class_id in self.teacher_class_id_list: for flag in ['', 1]: data = { "classId": class_id, "flag": flag, "seriesId": series_id } if flag == 1 else { "classId": class_id, "seriesId": series_id } res = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(res.text) time.sleep(1) data_ret = res.json() try: best = data_ret['data']['best'] worst = data_ret['data']['worst'] data_list = data_ret['data']['datas'] except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/learning/teacher/{i}报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口/learning/teacher/{i},返回{data_ret},与预期不符') else: print(f'{i}:{({"best": best["label"]}, {"worst": worst["label"]})}') print(f'{i}:{[{d["label"]: d["rate"]} for d in data_list]}') def test_09_teacher_student(self): """ 老师-学生学情 :return: """ url = f'{self.ip}/learning/teacher/student' for class_id in self.teacher_class_id_list: params = f'classId={class_id}' res = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: print([{i['name']: i['avgGrade']} for i in data_ret['data']]) except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/learning/teacher/student报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口/learning/teacher/student,返回{data_ret},与预期不符') def test_10_student_page(self): """ 老师-学生学情-分页 :return: """ url = f'{self.ip}/learning/teacher/student/page' for class_id in self.teacher_class_id_list: params = f'classId={class_id}&pageNum=1&pageSize=30' res = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/learning/teacher/student/page报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口/learning/teacher/student/page,返回{data_ret},与预期不符') else: print([{i['name']: i['avgGrade']} for i in data_list]) def test_11_user_homework_series(self): """ 用户-作业-系列集 :return: """ url = f'{self.ip}/learning/user/homework/series' for i in ['student', 'teacher']: header = self.student_headers if i == 'student' else self.teacher_headers class_id_list = self.student_class_id_list if i == 'student' else [1] for class_id in class_id_list: params = f'classId={class_id}' if i == 'student' else 'classId=' res = requests.get(url=url, headers=header, params=params) assert_res(res.text) time.sleep(1) data_ret = res.json() try: print(f'{i}:{[{i["id"]: i["name"]} for i in data_ret["data"]]}') except TypeError: msg = '接口正常,没有数据' \ if data_ret['msg'] == '操作成功' else \ f'接口/learning/homework/series报错,返回{data_ret["msg"]}' print(msg) except KeyError: print(f'接口/learning/homework/series,返回{data_ret},与预期不符')
class ClassManage(unittest.TestCase): def setUp(self) -> None: self.manager_param = ParameterForOthers(identity='manager') self.teacher_param = ParameterForOthers(identity='teacher') self.student_param = ParameterForOthers(identity='student') self.ip = self.teacher_param.ip self.manager_id, self.school_id = self.manager_param.get_user_school_id() self.class_id_list = self.manager_param.get_manage_class_list(self.school_id) self.student_id_list = self.manager_param.get_class_student_id(self.class_id_list[1], self.school_id) self.file_path = f'{get_absolute_path("interface")}\\K12edu\\files\\' @pytest.mark.run(order=1) def test_add_course(self): """ 管理员创建班级 :return: """ url = f'{self.ip}/teachcenter/classmanage/create' data = { 'className': '接口添加班级,待删除', 'schoolId': self.school_id, 'teachersId': [self.manager_id] } res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) data_ret = res.json() try: success = data_ret['data']['success'] if success: print('创建成功') self.class_id_list = self.manager_param.get_manage_class_list(self.school_id) if not success: print(f'创建失败,{data_ret["data"]["msg"]}') except KeyError: print(f"添加班级失败,{data_ret}") @pytest.mark.run(order=2) def test_add_form_student(self): """ 表单填写信息新建学生 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuAdd' data = { "classId": self.class_id_list[0], "gender": 1, "mobile": "", "schoolId": self.school_id, "stuName": "接口学生待删", "stuNo": "E00003" } res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) time.sleep(1) @pytest.mark.run(order=3) def test_add_course_student(self): """ 选取添加学生 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuBatchAdd' for i in range(2): data = { 'classId': self.class_id_list[0], 'stuIds': [str(self.student_id_list[i])] } res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) time.sleep(1) self.student_id_list = self.manager_param.get_class_student_id(self.class_id_list[0], self.school_id) @pytest.mark.run(order=4) def test_upd_student(self): """ 班级管理修改学生 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuEdit' for m in ['', '15208451946']: data = { "gender": 2, "mobile": m, "stuId": self.student_id_list[0], "stuName": "接口修改学生" } res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) data_ret = res.json() try: success = data_ret['data']['success'] if success: print('修改成功') if not success: assert '电话[15208451946]号码已被注册' == data_ret["data"]["msg"] except KeyError: print(f"添加班级失败,{data_ret}") @pytest.mark.run(order=5) def test_student_list(self): """ 班级管理-学生列表 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuList' for k in ['', '接口']: data = { "classId": self.class_id_list[0], "currPage": 1, "keyword": k, "pageSize": 30, "schoolId": self.school_id } res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口/teachcenter/classmanage/stuList报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/teachcenter/classmanage/stuList返回{data_ret}') else: print([(i['stuNo'], i['stuName'], i['mobile']) for i in data_list]) @pytest.mark.run(order=6) def test_student_info(self): """ 班级管理-学生列表-学生信息查询 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuInfo/{self.student_id_list[0]}' res = requests.get(url=url, headers=self.manager_param.headers) assert_res(res.text) pprint(res.json()) @pytest.mark.run(order=7) def test_del_students(self): """ 删除班级学生 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuRemove' data = { 'classId': self.class_id_list[0], 'stuId': [self.student_id_list[0]] } res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) time.sleep(1) @pytest.mark.run(order=8) def test_upd_course(self): """ 修改课程班 :return: """ url = f'{self.ip}/teachcenter/classmanage/edit' teacher_id, _ = self.teacher_param.get_user_school_id() data = { "classId": self.class_id_list[0], "className": "接口修改班级", "schoolId": self.school_id, "teachersId": [ self.manager_id, teacher_id ] } res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) time.sleep(1) @pytest.mark.run(order=9) def test_class_list(self): """ 班级管理-列表 :return: """ url = f'{self.ip}/teachcenter/classmanage/list' for t in range(1, 3): for k in ['', '接口']: data = { "classType": t, "currPage": 1, "keyword": k, "pageSize": 30, "schoolId": self.school_id } res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) time.sleep(1) data_ret = res.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口/teachcenter/classmanage/stuList报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/teachcenter/classmanage/stuList返回{data_ret}') else: pprint([(i['classId'], i['className'], i['stuCount']) for i in data_list]) @pytest.mark.run(order=10) def test_del_course(self): """ 删除对应班级 :return: """ url = f'{self.ip}/teachcenter/classmanage/remove' data = {'classId': [self.class_id_list[0]]} res = requests.post(url=url, headers=self.manager_param.headers, json=data) assert_res(res.text) time.sleep(1) @pytest.mark.run(order=11) def test_get_class_list(self): """ 班级管理-列表 :return: """ url = f'{self.ip}/teachcenter/classmanage/list/{self.school_id}' res = requests.get(url=url, headers=self.manager_param.headers) assert_res(res.text) data_ret = res.json() try: print([{i['id']: i['name']} for i in data_ret['data']]) except TypeError: print(f'接口/teachcenter/classmanage/list报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/teachcenter/classmanage/list返回{data_ret}') @pytest.mark.run(order=12) def test_select_list(self): """ 班级管理-查询下拉-列表 :return: """ url = f'{self.ip}/teachcenter/classmanage/selectList' params = f'schoolId={self.school_id}' res = requests.get(url=url, headers=self.manager_param.headers, params=params) assert_res(res.text) data_ret = res.json() try: print([i.values() for i in data_ret['data']]) except TypeError: print(f'接口/teachcenter/classmanage/selectList报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/teachcenter/classmanage/selectList返回{data_ret}') @pytest.mark.run(order=13) def test_student_class_list(self): """ 班级管理-添加学生-学生列表 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuClassList/{self.school_id}/{self.class_id_list[0]}' res = requests.get(url=url, headers=self.manager_param.headers) assert_res(res.text) data_ret = res.json() try: pprint([{i['name']: [{s['id']: s['name']} for s in i['students']]} for i in data_ret['data']]) except TypeError: print(f'接口/teachcenter/classmanage/stuClassList报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/teachcenter/classmanage/stuClassList返回{data_ret}') @pytest.mark.run(order=14) def test_student_import(self): """ 班级管理-学生列表-批量导入 :return: """ from requests_toolbelt.multipart.encoder import MultipartEncoder url = f'{self.ip}/teachcenter/classmanage/stuFileImport' file_name = 'student.xls' with open(f'{self.file_path}upload\\{file_name}', 'rb') as f: m = MultipartEncoder( { 'file': (file_name, f, 'application/vnd.ms-excel') } ) self.teacher_param.headers['Content-Type'] = m.content_type params = f'classId={self.class_id_list[0]}&schoolId={self.school_id}' res = requests.post(url=url, headers=self.teacher_param.headers, data=m, params=params) assert_res(res.text, '批量导入用户失败') data_ret = res.json() try: print(data_ret['data']['errMsg']) except TypeError: print(f'接口/teachcenter/classmanage/stuFileImport报错,返回{data_ret["msg"]}') except KeyError: print(f'接口/teachcenter/classmanage/stuFileImport返回{data_ret}') @pytest.mark.run(order=15) def test_student_export(self): """ 班级管理-学生列表-批量导出 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuExport' params = f'exportType=1&classId={self.class_id_list[0]}' res = requests.get(url=url, headers=self.teacher_param.headers, params=params) file_name = 'student_export.xls' file_write(f'{self.file_path}export\\', file_name, res.content) @pytest.mark.run(order=16) def test_student_temp_export(self): """ 班级管理-学生列表-模板导出 :return: """ url = f'{self.ip}/teachcenter/classmanage/stuTempExport' res = requests.get(url=url, headers=self.teacher_param.headers) file_name = 'student_temp.xls' file_write(f'{self.file_path}export\\', file_name, res.content)
def setUp(self): self.teacher_params = ParameterForOthers(identity='teacher') self.ip = self.teacher_params.ip self.teacher_headers = self.teacher_params.headers
class WorksController(unittest.TestCase): """作品展示学生端接口""" def setUp(self) -> None: self.manager_parm = ParameterForOthers(identity='manager') self.teacher_parm = ParameterForOthers(identity='teacher') self.student_parm = ParameterForOthers(identity='student') self.ip = self.teacher_parm.ip self.manager_headers = self.manager_parm.headers self.teacher_headers = self.teacher_parm.headers self.student_headers = self.student_parm.headers def test_01_post_work(self): """ 上传作品 :return: """ save_draft_for_works(self.teacher_parm) draft_id_list = self.teacher_parm.get_draft_id_list() code = turtle_code() url = f'{self.ip[:-8]}/ddc-port/play/postWork' for p in range(2): data = { "codeList": [ { "fileContent": code, "fileName": "main.py", "fileType": 1, "rwType": 1 } ], "cover": "https://edu-test-1255999742.file.myqcloud.com/portrait/20190527/" "4a60ada1fc0f478ca109f9fe49419328.jpg", "description": "发布接口测试", "draftId": draft_id_list[0], "publishCode": p, "title": f"接口发布作品源代码{p}" } response = requests.post(url=url, headers=self.teacher_headers, json=data) assert_res(response.text) def test_02_get_my_work_list(self): """ 获取我发布的作品 :return: """ url = f'{self.ip}/play/getMyWorksList' for s in range(2): for k in ['', '测试']: params = f'pageNum=1&pageSize=12&sort={s}&keyword={k}' response = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(response.text) data_ret = response.json() time.sleep(1) try: data_list = data_ret['data']['list'] except TypeError: print(f'接口"/pc/worksDisplay/getMyWorksList"报错,返回{data_ret["msg"]}') except KeyError: print(data_ret) else: work_list = [{i['id']: i['title']} for i in data_list] print(work_list) def test_05_get_work_detail_by_id(self): """ 通过作品ID获取作品详情 :return: """ work_id_list = self.teacher_parm.get_work_id_list() url = f'{self.ip[:-8]}/ddc-port/play/getWorkDetailById?worksId={work_id_list[0]}' response = requests.get(url=url, headers=self.teacher_headers) assert_res(response.text) data_ret = response.json() try: print({data_ret['data']['id']: data_ret['data']['title']}) except TypeError: print(f'接口"/play/getWorkDetailById"报错,返回{data_ret["msg"]}') except KeyError: print(data_ret) def test_06_get_works_hall(self): """ 获取作品大厅列表 :return: """ class_id_list = self.teacher_parm.get_class_list(get_all=True) class_id_list.append('') for class_id in class_id_list: for s in range(2): for k in ['', '测试']: url = f'{self.ip}/pc/play/getPlayWorksHall' params = f'pageNum=1&pageSize=12&sort={s}&keyword={k}&classId={class_id}' print(params) response = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(response.text) data_ret = response.json() time.sleep(1) try: data_list = data_ret['data']['list'] except TypeError: print(f'接口"/pc/play/getPlayWorksHall"报错,返回{data_ret["msg"]}') print('##############################################################') except KeyError: print(data_ret) print('##############################################################') else: print(f'班级{class_id}', [{i['id']: {i['title']: f"作者:{i['nickname']}"}} for i in data_list]) print('##############################################################') def test_08_user_praise(self): """ 通过作品ID对作品进行点赞 :return: """ url = f'{self.ip[:-8]}/ddc-port/play/userPraise' works_id_list = self.teacher_parm.get_work_id_list() for w in range(2): params = f'worksId={works_id_list[w]}' response = requests.get(url=url, headers=self.teacher_headers, params=params) assert_res(response.text, "今天已经点过赞了") time.sleep(1) def test_09_work_detail(self): """ 游客通过作品ID获取作品详情 :return: """ works_id_list = self.teacher_parm.get_work_id_list() url = f'{self.ip[:-8]}/ddc-port/play/workDetail' headers = { 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/68.0.3440.84 Safari/537.36' } params = f'worksId={works_id_list[0]}' response = requests.get(url=url, headers=headers, params=params) assert_res(response.text) data_ret = response.json() try: data_dic = data_ret['data'] print(f'作品id:{data_dic["id"]},' f'作品名称:{data_dic["title"]},' f'作者:{data_dic["nickname"]}') except TypeError: print(f'接口"/play/workDetail"报错,返回{data_ret["msg"]}') except KeyError: print(data_ret) def test_10_delete_works_by_id(self): """ 删除作品 :return: """ work_id_list = self.teacher_parm.get_work_id_list() for i in range(2): url = f'{self.ip[:-8]}/ddc-port/play/deleteWorksById?worksId={work_id_list[i]}' response = requests.delete(url=url, headers=self.teacher_headers) assert_res(response.text) def test_11_get_draft_list(self): """ 获取草稿列表(暂放此处) :return: """ url = f'{self.ip[:-8]}/ddc-port/play/getDraftList' params = 'pageNum=1&pageSize=15&keywords=' response = requests.get(url=url, headers=self.student_headers, params=params) assert_res(response.text) data_ret = response.json() try: data_list = data_ret['data']['list'] except TypeError: print(f'接口/play/getDraftList报错,返回{data_ret["msg"]}') except KeyError: print(data_ret) else: print([f'id:{i["id"]},title:{i["title"]}' for i in data_list])