def test_get_section_by_department(self): # empty db should have nothing sections = api.get_courses('section') self.assertFalse(list(sections)) # Create 5 sections where every attribute is the same as the ID self.create_test_sections() # Create 5 more sections # Sections will be made in a way that each of the 10 sections will share a department with another section sectionAdd = [] for i in range(5): num = str(i + 6) departmentNum = str(i + 1) sectionAdd.append(Section(ta=num, lecture=None, name=num, title=num, department=departmentNum, location=num, days=num, time=num, max_spots=num, space=num)) db.session.add_all(sectionAdd) db.session.commit() # Try to get all Sections based on department # Check will be made by making sure there are 2 sections in a department, and by checking the name of the department # to make sure they match expected values for i in range(5): sections = api.get_courses('section', department=str(i + 1)) sectionList = list(sections) # Make sure there are 2 sections in department self.assertEqual(len(sectionList), 2) # Make sure the 2 sections are the one expected self.assertEqual(sectionList[0].name, str(i + 1)) self.assertEqual(sectionList[1].name, str(i + 6))
def test_get_all_lectures(self): #empty db should be nothing lectures = api.get_courses('lecture') self.assertFalse(list(lectures)) #now there should be 10 classes self.create_test_lectures() lectures = api.get_courses('lecture') self.assertEqual(len(list(lectures)), 10)
def test_get_all_sections(self): # Empty db should have nothing sections = api.get_courses('section') self.assertFalse(list(sections)) # Create 5 sections where every attribute is the same as the ID self.create_test_sections() # 5 Sections should have been made, get_all_sections() should get them all sections = api.get_courses('section') self.assertEqual(len(list(sections)), 5)
def get_all_labs(): wants_json = request_wants_json page_number = request.args.get("page") try: labs = api.get_courses("lab", pagination=page_number is not None, page=page_number, json=wants_json) except api.DbNotFoundError: abort(404) return jsonify({"labs": labs})
def get_all_lectures(): page_number = request.args.get('page') wants_json = request_wants_json() try: lectures = api.get_courses(class_type='lecture', pagination=page_number is not None, page=page_number, json=wants_json) except api.DbNotFoundError: abort(404) return jsonify({'lectures': lectures}) if wants_json else render_template('lecture.html', lectures=lectures)
def get_lecture_by_department(department): page_number = request.args.get('page') wants_json = request_wants_json() try: lectures = api.get_courses(class_type='lecture', pagination=page_number is not None, page=page_number, json=wants_json, department=department) except api.DbNotFoundError: abort(404) return jsonify({'lectures': lectures})
def get_lab_by_department(department): wants_json = request_wants_json() page_number = request.args.get("page") try: labs = api.get_courses( "lab", pagination=page_number is not None, page=page_number, json=wants_json, department=department ) except api.DbNotFoundError: abort(404) return jsonify({"labs": labs})
def get_all_sections(): page_number = request.args.get('page') wants_json = request_wants_json() try: sections = api.get_courses('section', pagination=page_number is not None, page=page_number, json=wants_json) except api.DbNotFoundError: abort(404) return jsonify({'sections': sections})
def test_get_section_by_id(self): # empty db should have nothing sections = api.get_courses('section') self.assertFalse(list(sections)) # Create 5 sections where every attribute is the same as the ID self.create_test_sections() # Try to get all Sections based on ID # Check will be made by comparing Section name to Section ID, which in this test are the same for i in range(5): section = api.get_course_by_id('section', i + 1) self.assertEqual(section.name, str(i + 1))