def test_getCoursePlans_onlyTeacherId(self): '''只传入班主任Id''' self.params['params'] = { "classId":914, "teacherId":273, "courseId":780 } self.params['key']= TestProvide.generateKey(self.timeStamp,self.params['params']) #提交请求 print("Url: {} \n Parameter:{}".format(self.url,json.dumps(self.params,separators=(',',':'),ensure_ascii=False))) response = self.s.post(self.url,data=json.dumps(self.params,separators=(',',':'),ensure_ascii=False)) response.encoding= "utf-8" returnObj = json.loads(response.text) #验证返回值排课数据结构 ExpectKeys = ['planId','sectionDesc','sectionName','teacherId','teacherName','adminId','adminName','courseType','startTime','status','totalTime'] self.assertTrue(Confirm.VerifyDataStucture(ExpectKeys, returnObj['result']['data'][0].keys()), "返回排课对象属性字段值不对") OnePlanInfo = { 'adminName': '李胜红', 'courseType': 1, 'adminId': 273, 'sectionDesc': '1', 'planId': 2558, 'startTime': '2016-08-31 19:08:00', 'sectionName': '第1课时', 'status': 1, 'teacherId': 281, 'totalTime': 0, 'teacherName': '王喜山' } self.assertTrue(Confirm.VerifyDictEqual(OnePlanInfo,returnObj['result']['data'][0]),"排课信息不匹配 预期:{},返回值:{}".format(OnePlanInfo,returnObj['result']['data'][0]))
def test_getLivingPlan(self): teacherId = self.s.cookies.get('uid_test') month = 2016 year = 9 self.params['params'] = { "month": month, "teacherId": teacherId, "year": year } self.params['key'] = TestProvide.generateKey(self.timeStamp, self.params['params']) #提交请求 print("Url: {} \n Parameter:{}".format( self.url, json.dumps(self.params, separators=(',', ':'), ensure_ascii=False))) response = self.s.post(self.url, data=json.dumps(self.params, separators=(',', ':'), ensure_ascii=False)) response.encoding = "utf-8" returnObj = json.loads(response.text) ExpectKeys = [ 'sectionDescipt', 'start_time', 'status', 'class_id', 'thumb', 'type', 'class_name', 'section_name', 'teacher_name', 'course_id', 'userTotal', 'num', 'title', 'plan_id', 'course_type' ] for key in returnObj['result']: if returnObj['result'][key]['flag'] == 1: CompareObj = returnObj['result'][key]['data'][0] self.assertTrue( Confirm.VerifyDataStucture(ExpectKeys, CompareObj)) break count = 0 format = [ "course_name", "class_name", "section_name", "section_desc", "course_type", "plan_id", "start_time", "totaltime", "teacher_id", "teacher_real_name" ] query = { "start_time": "2016-09-01,2016-10-01", "teacher_id": 281, "status": "1,2,3" } ob = {"start_time": "asc"} planList = Seek.seekPlan(format, query, ob) planList = planList['data'] print(planList) for i in range(len(planList)): dateObj = datetime.strptime(planList[i]['start_time'], "%Y-%m-%d %H:%M:%S") key = str(dateObj.day) for plan in returnObj['result'][key]['data']: if plan['title'] == planList[i]['course_name'] and plan['class_name']==planList[i]['class_name'] and plan['plan_id']==planList[i]['plan_id'] \ and plan['section_desc']==planList[i]['sectionDescipt']: count += 1 self.assertEqual(len(planList), count, "排课信息不符")
def test_GetTeacherPlan(self): self.params['params']= { "courseId":1007 } self.params['key']= TestProvide.generateKey(self.timeStamp,self.params['params']) #提交请求 print(self.url) print(json.dumps(self.params,separators=(',',':'))) response = self.s.post(self.url,data=json.dumps(self.params,separators=(',',':'),ensure_ascii=False)) response.encoding= "utf-8" returnObj = json.loads(response.text) self.assertEqual(returnObj['code'],0) self.assertEqual(returnObj['message'],"success") ClassInfo = { 'classId': '1226', 'planNum': 4, 'uploadVideo': 0, 'data': [ { 'planId': 3568, 'status': '1', 'sectionDesc': '001', 'sectionName': '第1课时' }, { 'planId': 3569, 'status': '1', 'sectionDesc': '002', 'sectionName': '第2课时' }, { 'planId': 4378, 'status': '1', 'sectionDesc': '003', 'sectionName': '第3课时' }, { 'planId': 4379, 'status': '1', 'sectionDesc': '004', 'sectionName': '第4课时' } ], 'name': '1班' } self.assertTrue(Confirm.objIsInList(ClassInfo, returnObj['result']))
def test_getStudentList(self): """获取学生列表---通过班主任获取""" self.params['params'] = { "page":1, "length":20, "classId": Configuration.class_id, "courseId": Configuration.course_id, "teacherId":273, } self.params['key']= TestProvide.generateKey(self.timeStamp,self.params['params']) print("Url:{}\r\n Parameters:{}".format(self.url,json.dumps(self.params,separators=(',',':'),ensure_ascii=False))) response = self.s.post(self.url,data=json.dumps(self.params)) response.encoding= "utf-8" returnObj = json.loads(response.text) firstObj=returnObj['result']['data'][0] keys = ['startTime','address','sex','userName','mobile','userId'] Result=Confirm.VerifyDataStucture(keys,firstObj.keys()) self.assertTrue(Result, "学生属性值返回错误")
def test_GetTeacherCourse_all(self): """班主任下的课程--默认排序 """ self.params['params'] = { "keywords": "", "length": 20, "page": 1, "sort": 1000, "status": 0, "teacherId": self.teacherId, "type": 0 } self.params['key'] = TestProvide.generateKey(self.timeStamp, self.params['params']) #提交请求 print("Url: {} \n Parameter:{}".format( self.url, json.dumps(self.params, separators=(',', ':'), ensure_ascii=False))) response = self.s.post(self.url, data=json.dumps(self.params)) response.encoding = "utf-8" returnObj = json.loads(response.text) self.assertEqual(returnObj['code'], 0) self.assertEqual(returnObj['message'], "success") ActualFirstCourseOfList = returnObj['result']['list']['data'][0] CourseProperty = [ 'courseId', 'courseName', 'courseImg', 'classList', 'subname', 'courseType', 'userTotal' ] text = "数据结构不匹配 Expect keys:{};response keys:{}".format( CourseProperty, ActualFirstCourseOfList.keys()) self.assertTrue( Confirm.VerifyDataStucture(CourseProperty, ActualFirstCourseOfList.keys()), text) conn = self.create_SqlConnect() cursor = conn.cursor() sql = "SELECT COUNT(c.`pk_course`) AS num,c.`type` FROM t_course_teacher AS t JOIN t_course AS c ON t.`fk_course`=c.`pk_course` WHERE t.`fk_user_teacher`={} GROUP BY c.`type`".format( self.teacherId) cursor.execute(sql) rows = cursor.fetchall() livingNum, recordNum, underNum = 0, 0, 0 for row in rows: if row['type'] == 1: livingNum = row['num'] elif row['type'] == 2: recordNum = row['num'] else: underNum = row['num'] total = livingNum + recordNum + underNum #验证课程数量 self.assertEqual(total, returnObj['result']['nums']['total']) self.assertEqual(livingNum, returnObj['result']['nums']['livingNum']) self.assertEqual(recordNum, returnObj['result']['nums']['recordNum']) self.assertEqual(underNum, returnObj['result']['nums']['underNum']) #验证课程名称 Flag = True CourseSql = "SELECT c.`pk_course`,c.`title` FROM `t_course_teacher` AS t JOIN t_course AS c ON t.`fk_course`=c.`pk_course` WHERE t.fk_user_teacher={}".format( self.teacherId) cursor.execute(CourseSql) rows = cursor.fetchall() num = 0 for courseObj in returnObj['result']['list']['data']: for row in rows: if courseObj['courseId'] == row['pk_course'] and courseObj[ 'courseName'] == row['title']: num = num + 1 break cursor.close() conn.close() self.assertTrue(len(rows), num)