def test_get_by_schedule(self): regid = "9136CCB8F66711D5BE060004AC494FFE" term = Term() term.year = 2012 term.quarter = "summer" schedule = _get_schedule(regid, term) books = get_textbook_by_schedule(schedule) self.assertEquals(len(books), 5) self.assertEquals(books["13833"][0].title, "Quantum Chemistry (6th Edition)") self.assertEquals(get_textbook_by_schedule(None), None)
def respond(self, request, year, quarter, summer_term): timer = Timer() try: if not is_student(): log_msg(logger, timer, "Not a student, abort!") return data_not_found() term = get_specific_term(year=year, quarter=quarter) schedule = get_schedule_by_term(request, term) if summer_term is not None and len(summer_term) > 0: summer_term = summer_term.replace(",", "") filter_schedule_sections_by_summer_term(schedule, summer_term) if len(schedule.sections) == 0: log_data_not_found_response(logger, timer) return data_not_found() book_data = get_textbook_by_schedule(schedule) by_sln = index_by_sln(book_data) try: verba_link = get_verba_link_by_schedule(schedule) by_sln["verba_link"] = verba_link except DataFailureException as ex: if ex.status != 404: raise log_success_response(logger, timer) return HttpResponse(json.dumps(by_sln)) except Exception: return handle_exception(logger, timer, traceback)
def test_get_by_schedule(self): regid = "9136CCB8F66711D5BE060004AC494FFE" term = Term() term.year = 2012 term.quarter = "summer" schedule = _get_schedule(regid, term) books = get_textbook_by_schedule(schedule) self.assertEquals(len(books), 1) self.assertEquals(books["13833"][0].title, "2 P/S Tutorials In Introductory Physics")
def respond(self, year, quarter, summer_term): timer = Timer() logger = logging.getLogger(__name__) term = get_quarter(year=year, quarter=quarter) schedule = get_schedule_by_term(term) if summer_term is not None: summer_term = summer_term.replace(",", "") filter_schedule_sections_by_summer_term(schedule, summer_term) book_data = get_textbook_by_schedule(schedule) if book_data is None: log_data_not_found_response(logger, timer) return data_not_found() verba_link = get_verba_link_by_schedule(schedule) by_sln = index_by_sln(book_data) by_sln["verba_link"] = verba_link log_success_response(logger, timer) return HttpResponse(json.dumps(by_sln))