示例#1
0
    def test_get_verba_by_schedule(self):
        regid = "9136CCB8F66711D5BE060004AC494FFE"
        term = Term()
        term.year = 2012
        term.quarter = "summer"
        schedule = _get_schedule(regid, term)

        expected_link = ("http://uw-seattle.verbacompare.com/m?"
                         "section_id=AB12345&quarter=summer")
        returned_link = get_verba_link_by_schedule(schedule)
        self.assertEquals(returned_link, expected_link)

        returned_link = get_verba_link_by_schedule(None)
        self.assertEquals(returned_link, None)
示例#2
0
    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)
示例#3
0
文件: textbook.py 项目: vegitron/myuw
    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)
示例#4
0
    def test_get_verba_by_schedule(self):
        regid = "9136CCB8F66711D5BE060004AC494FFE"
        term = Term()
        term.year = 2013
        term.quarter = "spring"
        schedule = _get_schedule(regid, term)

        returned_link = get_verba_link_by_schedule(schedule)

        expected_link = ("http://uw-seattle.verbacompare.com/m?"
                         "section_id=AB12345&quarter=spring")
        self.assertEquals(returned_link, expected_link)

        regid = "9136CCB8F66711D5BE060004AC494FFE"
        term = Term()
        term.year = 2014
        term.quarter = "winter"
        schedule = _get_schedule(regid, term)
        self.assertRaises(DataFailureException, get_verba_link_by_schedule,
                          schedule)
示例#5
0
    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))
示例#6
0
    def test_get_verba_by_schedule(self):
        regid = "9136CCB8F66711D5BE060004AC494FFE"
        term = Term()
        term.year = 2013
        term.quarter = "spring"
        schedule = _get_schedule(regid, term)

        returned_link = get_verba_link_by_schedule(schedule)

        expected_link = ("http://uw-seattle.verbacompare.com/m?"
                         "section_id=AB12345&quarter=spring")
        self.assertEquals(returned_link, expected_link)

        regid = "9136CCB8F66711D5BE060004AC494FFE"
        term = Term()
        term.year = 2014
        term.quarter = "winter"
        schedule = _get_schedule(regid, term)
        self.assertRaises(DataFailureException,
                          get_verba_link_by_schedule,
                          schedule)