def test_selectcoursename2(self): a = Course(course_name="这是一个测试", course_type="ss", course_url="4399", platform_name="") b = Course(course_name="这是一个测试", course_type="sss", course_url="4399d", platform_name="rt") s = [a, b] db.insert_courses_table(s) self.assertEqual(db.select_course_name("这是")[0].course_name,a.course_name) self.assertEqual(db.select_course_name(a.course_name)[1].course_name, a.course_name)
def test_selectcoursename3(self): a = Course(course_name="这是一个测试", course_type="ss", course_url="4399", platform_name="") b = Course(course_name="这是一个测试", course_type="sss", course_url="4399d", platform_name="rt") c=Course(course_name="这是s测试", course_type="325s", course_url="439d", platform_name="t") s = [a, b] db.insert_courses_table(s) self.assertEqual(db.select_course_name(c.course_name),[])
def search(): if request.method == 'POST': if request.form['type'] == '全平台': keyword = request.form['keyword'] courses = db.select_course_name(keyword) else: keyword = request.form['keyword'] platform = request.form['type'] courses = db.select_platform_course_name(platform, keyword) #分页显示 parer_obj = Pagination(request.args.get("page", 1), len(courses), request.path, request.args, per_page_count=20) #print(request.path) #print(request.args) index_list = courses[parer_obj.start:parer_obj.end] html = parer_obj.page_html() return render_template('index.html', index_list=index_list, html=html, coursetypes=coursetypes) else: # 分页显示 courses = db.select_all_course() parer_obj = Pagination(request.args.get("page", 1), len(courses), request.path, request.args, per_page_count=20) #print(request.path) #print(request.args) index_list = courses[parer_obj.start:parer_obj.end] html = parer_obj.page_html() return render_template('index.html', index_list=index_list, html=html, coursetypes=coursetypes)
def test_selectcoursename5(self): a = Course(course_name="这是一个测试", course_type="ss", course_url="4399", platform_name="") self.assertEqual(db.select_course_name(a), None)
def test_course(self): a = Course(course_name="这是一个测试", course_type="ss", course_url="4399", platform_name="") b = Course(course_name="这是一个测试", course_type="sss", course_url="4399d", platform_name="rt") s = [a, b] db.insert_courses_table(s) #c=COurse(course_name=) self.assertTrue( db.insert_course_table( Course(course_name="s", course_type="ss", course_url="757", platform_name="1);DROP ALL TABLE--"))) self.assertEqual(db.select_all_course()[0].course_name, a.course_name) db.delete_all_course_table() a = Course(course_name="TABLE", course_type="ss", course_url="4399", platform_name="1);DROP ALL TABLE--") b = Course(course_name="ALL", course_type="sss", course_url="4399d", platform_name="1);DROP ALL TABLE--") s = [a, b] self.assertTrue(db.insert_courses_table(s)) self.assertEqual(db.select_all_course()[0].course_name, a.course_name) self.assertTrue(db.delete_course_table(b)) self.assertEqual(db.select_all_course()[0].course_name, a.course_name) db.drop_course_table() db.init_course_table() a = Course(course_name="TABLE", course_type="ss", course_url="4399", platform_name="1);DROP TABLE if exists COURSE;--") b = Course(course_name="ALL", course_type="sss", course_url="4399d", platform_name="1);DROP TABLE if exists COURSE;--") s = [a, b] db.insert_courses_table(s) self.assertFalse(db.delete_course_table2("1);DROP ALL TABLE--")) self.assertEqual(db.select_all_course()[0].course_name, a.course_name) self.assertTrue( db.update_course_table( 1, Course(course_name="TABLE", course_type="ss", course_url="4399", platform_name="1);DROP TABLE if exists COURSE;--"))) self.assertEqual( db.select_course_name("5);DROP TABLE if exists COURSE;--"), []) self.assertEqual( db.select_course_type("5);DROP TABLE if exists COURSE;--"), []) self.assertEqual( db.select_platform_name("5);DROP TABLE if exists COURSE;--"), []) self.assertEqual( db.select_course_type_accuracy( "5);DROP TABLE if exists COURSE;--"), []) self.assertEqual( db.select_platform_course_name( "s", "5);DROP TABLE if exists COURSE;--"), [])