def test_get_bod_class_start_quarter_after(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): quarter = get_specific_term(2013, 'winter') self.assertEqual(get_bod_class_start_quarter_after(quarter), datetime(2013, 4, 1, 0, 0, 0)) quarter = get_specific_term(2013, 'spring') self.assertEqual(get_bod_class_start_quarter_after(quarter), datetime(2013, 6, 24, 0, 0, 0)) quarter = get_specific_term(2013, 'summer') self.assertEqual(get_bod_class_start_quarter_after(quarter), datetime(2013, 9, 25, 0, 0, 0))
def test_get_bod_class_start_quarter_after(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): quarter = get_specific_term(2013, 'winter') self.assertEqual(get_bod_class_start_quarter_after(quarter), datetime(2013, 4, 1, 0, 0, 0)) quarter = get_specific_term(2013, 'spring') self.assertEqual(get_bod_class_start_quarter_after(quarter), datetime(2013, 6, 24, 0, 0, 0)) quarter = get_specific_term(2013, 'summer') self.assertEqual(get_bod_class_start_quarter_after(quarter), datetime(2013, 9, 25, 0, 0, 0))
def test_is_past(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): term = get_specific_term(2014, "winter") self.assertEqual(term.year, 2014) self.assertEqual(term.quarter, "winter") now_request = RequestFactory().get("/") now_request.session = {} self.assertFalse(is_past(term, now_request)) term = get_specific_term(2013, "winter") self.assertEqual(term.year, 2013) self.assertEqual(term.quarter, "winter") now_request = RequestFactory().get("/") now_request.session = {} self.assertTrue(is_past(term, now_request))
def test_is_past_1(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): term = get_specific_term(2014, "winter") self.assertEqual(term.year, 2014) self.assertEqual(term.quarter, "winter") now_request = RequestFactory().get("/") now_request.session = {} self.assertFalse(is_past(term, now_request)) term = get_specific_term(2013, "winter") self.assertEqual(term.year, 2013) self.assertEqual(term.quarter, "winter") now_request = RequestFactory().get("/") now_request.session = {} self.assertTrue(is_past(term, now_request))
def test_is_past(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): quarter = get_specific_term(2013, 'autumn') now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2014-01-01" self.assertTrue(is_past(quarter, now_request))
def test_in_show_grades_period(self): term = get_specific_term(2013, "winter") now_request = self.get_request_for_date('2013-03-27') self.assertTrue(in_show_grades_period(term, now_request)) # spring quarter starts now_request = self.get_request_for_date('2013-04-01') self.assertFalse(in_show_grades_period(term, now_request))
def test_must_displayed_separately(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): regid = "9136CCB8F66711D5BE060004AC494FFE" term = get_specific_term(2013, "summer") schedule = _get_schedule(regid, term) self.assertTrue(_must_displayed_separately(schedule))
def test_is_past_2(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): quarter = get_specific_term(2013, 'autumn') now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2014-01-01" self.assertTrue(is_past(quarter, now_request))
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 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_must_displayed_separately(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): regid = "9136CCB8F66711D5BE060004AC494FFE" term = get_specific_term(2013, "summer") schedule = _get_schedule(regid, term) self.assertTrue(_must_displayed_separately(schedule))
def GET(self, request, year, quarter, summer_term=None): """ GET returns 200 with course section schedule details of the given year, quarter. Return the course sections of full term and matched term if a specific summer-term is given @return class schedule data in json format status 404: no schedule found (not registered) status 543: data error """ timer = Timer() try: smr_term = "" if summer_term and len(summer_term) > 1: smr_term = summer_term.title() request_term = get_specific_term(year, quarter) if is_past(request_term, request): if not in_show_grades_period(request_term, request): log_msg(logger, timer, "Future term has pasted") return invalid_future_term() return self.make_http_resp(timer, request_term, request, smr_term) except Exception: return handle_exception(logger, timer, traceback)
def test_in_show_grades_period(self): term = get_specific_term(2013, "winter") now_request = self.get_request_for_date('2013-03-27') self.assertTrue(in_show_grades_period(term, now_request)) # spring quarter starts now_request = self.get_request_for_date('2013-04-01') self.assertFalse(in_show_grades_period(term, now_request))
def GET(self, request, year, quarter, summer_term=None): """ GET returns 200 with course section schedule details of the given year, quarter. Return the course sections of full term and matched term if a specific summer-term is given @return class schedule data in json format status 404: no schedule found (not registered) status 543: data error """ timer = Timer() try: smr_term = "" if summer_term and len(summer_term) > 1: smr_term = summer_term.title() request_term = get_specific_term(year, quarter) if is_past(request_term, request): if not in_show_grades_period(request_term, request): log_msg(logger, timer, "Future term has pasted") return invalid_future_term() return self.make_http_resp(timer, request_term, request, smr_term) except Exception: return handle_exception(logger, timer, traceback)
def test_get_registered_summer_terms(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): regid = "9136CCB8F66711D5BE060004AC494FFE" term = get_specific_term(2013, "summer") schedule = _get_schedule(regid, term) data = _get_registered_summer_terms(schedule.sections) self.assertTrue(data["B"]) self.assertTrue(data["A"])
def test_get_registered_summer_terms(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): regid = "9136CCB8F66711D5BE060004AC494FFE" term = get_specific_term(2013, "summer") schedule = _get_schedule(regid, term) data = _get_registered_summer_terms(schedule.sections) self.assertTrue(data["B"]) self.assertTrue(data["A"])
def _get_bterm_start(term): summer_term = get_specific_term(term["year"], "summer") bterm_start = summer_term.bterm_first_date return datetime(bterm_start.year, bterm_start.month, bterm_start.day, 0, 0, 0, tzinfo=timezone.now().tzinfo)
def test_in_show_grades_period(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): term = get_specific_term(2013, "winter") now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-03-27" self.assertTrue(in_show_grades_period(term, now_request)) now_request.session = {} # spring quarter starts now_request.session["myuw_override_date"] = "2013-04-01" self.assertFalse(in_show_grades_period(term, now_request))
def test_save_seen_registration_obj(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-12-10" regid = "9136CCB8F66711D5BE060004AC494FFE" term = get_specific_term(2014, "winter") winter2014_sche = _get_schedule(regid, term) self.assertIsNotNone(winter2014_sche) self.assertEqual(len(winter2014_sche.sections), 5) registered_future_quarters = _get_registered_future_quarters( now_request, winter2014_sche, None) user, created = User.objects.get_or_create( uwnetid='javerage', uwregid='9136CCB8F66711D5BE060004AC494FFE') model, created, now_datetime, summer_term =\ save_seen_registration_obj(user, now_request, registered_future_quarters[0]) self.assertTrue(created) self.assertEqual(model.user.uwnetid, "javerage") self.assertEqual(model.year, 2014) self.assertEqual(model.quarter, "Winter") self.assertEqual(model.summer_term, "F") qset = SeenRegistration.objects.filter( user=user, year=2014, quarter="Winter", summer_term="F", ) self.assertEqual(len(qset), 1) model1, created1, now_datetime1, summer_term1 =\ save_seen_registration_obj(user, now_request, registered_future_quarters[0]) self.assertFalse(created1) qset1 = SeenRegistration.objects.filter( user=user, year=2014, quarter="Winter", summer_term="F", ) self.assertEqual(len(qset1), 1) now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-5-10" regid = "9136CCB8F66711D5BE060004AC494FFE" term = get_specific_term(2013, "summer") summer2013_sche = _get_schedule(regid, term) self.assertIsNotNone(summer2013_sche) self.assertEqual(len(summer2013_sche.sections), 3) registered_future_quarters = _get_registered_future_quarters( now_request, summer2013_sche, None) self.assertEqual(len(registered_future_quarters), 2) quarter = registered_future_quarters[0] model, created, now_datetime, summer_term =\ save_seen_registration_obj(user, now_request, quarter) self.assertTrue(created) self.assertEqual(model.user.uwnetid, "javerage") self.assertEqual(model.year, 2013) self.assertEqual(model.quarter, "Summer") self.assertEqual(model.summer_term, "A") qset = SeenRegistration.objects.filter( user=user, year=2013, quarter="Summer", summer_term="A", ) self.assertEqual(len(qset), 1) model1, created1, now_datetime1, summer_term1 =\ save_seen_registration_obj(user, now_request, quarter) self.assertFalse(created1) qset1 = SeenRegistration.objects.filter( user=user, year=2013, quarter="Summer", summer_term="A", ) self.assertEqual(len(qset1), 1) quarter = registered_future_quarters[1] model, created, now_datetime, summer_term =\ save_seen_registration_obj(user, now_request, quarter) self.assertTrue(created) self.assertEqual(model.user.uwnetid, "javerage") self.assertEqual(model.year, 2013) self.assertEqual(model.quarter, "Summer") self.assertEqual(model.summer_term, "B") qset = SeenRegistration.objects.filter( user=user, year=2013, quarter="Summer", summer_term="B", ) self.assertEqual(len(qset), 1) model1, created1, now_datetime1, summer_term1 =\ save_seen_registration_obj(user, now_request, quarter) self.assertFalse(created1) qset1 = SeenRegistration.objects.filter( user=user, year=2013, quarter="Summer", summer_term="B", ) self.assertEqual(len(qset1), 1)
def test_get_registered_future_quarters(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): now_request = RequestFactory().get("/") now_request.session = {} regid = "9136CCB8F66711D5BE060004AC494FFE" term1 = get_specific_term(2013, "summer") schedule1 = _get_schedule(regid, term1) self.assertEqual(len(schedule1.sections), 3) term2 = get_specific_term(2013, "autumn") schedule2 = _get_schedule(regid, term2) self.assertEqual(len(schedule2.sections), 2) terms = _get_registered_future_quarters(now_request, schedule1, schedule2) self.assertTrue(len(terms) == 3) self.assertTrue(terms[0]['year'] == 2013) self.assertEqual(terms[0]['quarter'], "Summer") self.assertEqual(terms[0]['summer_term'], "a-term") self.assertTrue(terms[1]['year'] == 2013) self.assertEqual(terms[1]['quarter'], "Summer") self.assertEqual(terms[1]['summer_term'], "b-term") self.assertTrue(terms[2]['year'] == 2013) self.assertEqual(terms[2]['quarter'], "Autumn") self.assertEqual(terms[2]['summer_term'], "") terms = _get_registered_future_quarters(now_request, None, None) self.assertEqual(len(terms), 0) # MUWM-3010 # Baseline pre-summer now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-04-01" terms = _get_registered_future_quarters(now_request, schedule1, schedule2) self.assertTrue(len(terms) == 3) self.assertTrue(terms[0]['year'] == 2013) self.assertEqual(terms[0]['quarter'], "Summer") self.assertEqual(terms[0]['summer_term'], "a-term") self.assertTrue(terms[1]['year'] == 2013) self.assertEqual(terms[1]['quarter'], "Summer") self.assertEqual(terms[1]['summer_term'], "b-term") self.assertTrue(terms[2]['year'] == 2013) self.assertEqual(terms[2]['quarter'], "Autumn") self.assertEqual(terms[2]['summer_term'], "") # Summer has started - so no a-term now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-06-30" terms = _get_registered_future_quarters(now_request, schedule1, schedule2) self.assertTrue(len(terms) == 2) self.assertTrue(terms[0]['year'] == 2013) self.assertEqual(terms[0]['quarter'], "Summer") self.assertEqual(terms[0]['summer_term'], "b-term") self.assertTrue(terms[1]['year'] == 2013) self.assertEqual(terms[1]['quarter'], "Autumn") self.assertEqual(terms[1]['summer_term'], "") # Summer b-term has started - so no a-term or b-term now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-07-30" terms = _get_registered_future_quarters(now_request, schedule1, schedule2) self.assertTrue(len(terms) == 1) self.assertTrue(terms[0]['year'] == 2013) self.assertEqual(terms[0]['quarter'], "Autumn") self.assertEqual(terms[0]['summer_term'], "") now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-12-10" term = get_specific_term(2014, "winter") winter2014_sche = _get_schedule(regid, term) self.assertIsNotNone(winter2014_sche) self.assertEqual(len(winter2014_sche.sections), 5) registered_future_quarters =\ _get_registered_future_quarters(now_request, winter2014_sche, None) self.assertEqual(len(registered_future_quarters), 1) term1 = registered_future_quarters[0] self.assertEqual(term1["quarter"], "Winter") self.assertEqual(term1["year"], 2014) self.assertEqual(term1["section_count"], 5)
def test_save_seen_registration_obj(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-12-10" regid = "9136CCB8F66711D5BE060004AC494FFE" term = get_specific_term(2014, "winter") winter2014_sche = _get_schedule(regid, term) self.assertIsNotNone(winter2014_sche) self.assertEqual(len(winter2014_sche.sections), 5) registered_future_quarters = _get_registered_future_quarters( now_request, winter2014_sche, None) user, created = User.objects.get_or_create( uwnetid='javerage', uwregid='9136CCB8F66711D5BE060004AC494FFE') model, created, now_datetime, summer_term =\ save_seen_registration_obj(user, now_request, registered_future_quarters[0]) self.assertTrue(created) self.assertEqual(model.user.uwnetid, "javerage") self.assertEqual(model.year, 2014) self.assertEqual(model.quarter, "Winter") self.assertEqual(model.summer_term, "F") qset = SeenRegistration.objects.filter(user=user, year=2014, quarter="Winter", summer_term="F", ) self.assertEqual(len(qset), 1) model1, created1, now_datetime1, summer_term1 =\ save_seen_registration_obj(user, now_request, registered_future_quarters[0]) self.assertFalse(created1) qset1 = SeenRegistration.objects.filter(user=user, year=2014, quarter="Winter", summer_term="F", ) self.assertEqual(len(qset1), 1) now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-5-10" regid = "9136CCB8F66711D5BE060004AC494FFE" term = get_specific_term(2013, "summer") summer2013_sche = _get_schedule(regid, term) self.assertIsNotNone(summer2013_sche) self.assertEqual(len(summer2013_sche.sections), 3) registered_future_quarters = _get_registered_future_quarters( now_request, summer2013_sche, None) self.assertEqual(len(registered_future_quarters), 2) quarter = registered_future_quarters[0] model, created, now_datetime, summer_term =\ save_seen_registration_obj(user, now_request, quarter) self.assertTrue(created) self.assertEqual(model.user.uwnetid, "javerage") self.assertEqual(model.year, 2013) self.assertEqual(model.quarter, "Summer") self.assertEqual(model.summer_term, "A") qset = SeenRegistration.objects.filter(user=user, year=2013, quarter="Summer", summer_term="A", ) self.assertEqual(len(qset), 1) model1, created1, now_datetime1, summer_term1 =\ save_seen_registration_obj(user, now_request, quarter) self.assertFalse(created1) qset1 = SeenRegistration.objects.filter(user=user, year=2013, quarter="Summer", summer_term="A", ) self.assertEqual(len(qset1), 1) quarter = registered_future_quarters[1] model, created, now_datetime, summer_term =\ save_seen_registration_obj(user, now_request, quarter) self.assertTrue(created) self.assertEqual(model.user.uwnetid, "javerage") self.assertEqual(model.year, 2013) self.assertEqual(model.quarter, "Summer") self.assertEqual(model.summer_term, "B") qset = SeenRegistration.objects.filter(user=user, year=2013, quarter="Summer", summer_term="B", ) self.assertEqual(len(qset), 1) model1, created1, now_datetime1, summer_term1 =\ save_seen_registration_obj(user, now_request, quarter) self.assertFalse(created1) qset1 = SeenRegistration.objects.filter(user=user, year=2013, quarter="Summer", summer_term="B", ) self.assertEqual(len(qset1), 1)
def test_get_registered_future_quarters(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): now_request = RequestFactory().get("/") now_request.session = {} regid = "9136CCB8F66711D5BE060004AC494FFE" term1 = get_specific_term(2013, "summer") schedule1 = _get_schedule(regid, term1) self.assertEqual(len(schedule1.sections), 3) term2 = get_specific_term(2013, "autumn") schedule2 = _get_schedule(regid, term2) self.assertEqual(len(schedule2.sections), 2) terms = _get_registered_future_quarters(now_request, schedule1, schedule2) self.assertTrue(len(terms) == 3) self.assertTrue(terms[0]['year'] == 2013) self.assertEqual(terms[0]['quarter'], "Summer") self.assertEqual(terms[0]['summer_term'], "a-term") self.assertTrue(terms[1]['year'] == 2013) self.assertEqual(terms[1]['quarter'], "Summer") self.assertEqual(terms[1]['summer_term'], "b-term") self.assertTrue(terms[2]['year'] == 2013) self.assertEqual(terms[2]['quarter'], "Autumn") self.assertEqual(terms[2]['summer_term'], "") terms = _get_registered_future_quarters(now_request, None, None) self.assertEqual(len(terms), 0) # MUWM-3010 # Baseline pre-summer now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-04-01" terms = _get_registered_future_quarters(now_request, schedule1, schedule2) self.assertTrue(len(terms) == 3) self.assertTrue(terms[0]['year'] == 2013) self.assertEqual(terms[0]['quarter'], "Summer") self.assertEqual(terms[0]['summer_term'], "a-term") self.assertTrue(terms[1]['year'] == 2013) self.assertEqual(terms[1]['quarter'], "Summer") self.assertEqual(terms[1]['summer_term'], "b-term") self.assertTrue(terms[2]['year'] == 2013) self.assertEqual(terms[2]['quarter'], "Autumn") self.assertEqual(terms[2]['summer_term'], "") # Summer has started - so no a-term now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-06-30" terms = _get_registered_future_quarters(now_request, schedule1, schedule2) self.assertTrue(len(terms) == 2) self.assertTrue(terms[0]['year'] == 2013) self.assertEqual(terms[0]['quarter'], "Summer") self.assertEqual(terms[0]['summer_term'], "b-term") self.assertTrue(terms[1]['year'] == 2013) self.assertEqual(terms[1]['quarter'], "Autumn") self.assertEqual(terms[1]['summer_term'], "") # Summer b-term has started - so no a-term or b-term now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-07-30" terms = _get_registered_future_quarters(now_request, schedule1, schedule2) self.assertTrue(len(terms) == 1) self.assertTrue(terms[0]['year'] == 2013) self.assertEqual(terms[0]['quarter'], "Autumn") self.assertEqual(terms[0]['summer_term'], "") now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-12-10" term = get_specific_term(2014, "winter") winter2014_sche = _get_schedule(regid, term) self.assertIsNotNone(winter2014_sche) self.assertEqual(len(winter2014_sche.sections), 5) registered_future_quarters =\ _get_registered_future_quarters(now_request, winter2014_sche, None) self.assertEqual(len(registered_future_quarters), 1) term1 = registered_future_quarters[0] self.assertEqual(term1["quarter"], "Winter") self.assertEqual(term1["year"], 2014) self.assertEqual(term1["section_count"], 5)