def test_get_offset(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS, RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS): term = Term() term.year = 2013 term.quarter = "autumn" term.first_day_quarter = datetime.date(2013, 9, 11) date_prev = datetime.date(2013, 9, 10) date_equal = datetime.date(2013, 9, 11) date_post = datetime.date(2013, 9, 12) offset_prev = _get_offset(date_prev, term) self.assertEqual(offset_prev, -1) offset_equal = _get_offset(date_equal, term) self.assertEqual(offset_equal, 0) offset_post = _get_offset(date_post, term) self.assertEqual(offset_post, 1)
def _json_to_term_model(term_data): """ Returns a term model created from the passed json data. param: term_data loaded json data """ strptime = datetime.strptime day_format = "%Y-%m-%d" datetime_format = "%Y-%m-%dT%H:%M:%S" term = TermModel() term.year = term_data["Year"] term.quarter = term_data["Quarter"] term.last_day_add = parse_sws_date(term_data["LastAddDay"]) term.first_day_quarter = parse_sws_date(term_data["FirstDay"]) term.last_day_instruction = parse_sws_date(term_data["LastDayOfClasses"]) term.last_day_drop = parse_sws_date(term_data["LastDropDay"]) term.census_day = parse_sws_date(term_data["CensusDay"]) if term_data["ATermLastDay"] is not None: term.aterm_last_date = parse_sws_date(term_data["ATermLastDay"]) if term_data["BTermFirstDay"] is not None: term.bterm_first_date = parse_sws_date(term_data["BTermFirstDay"]) if term_data["LastAddDayATerm"] is not None: term.aterm_last_day_add = parse_sws_date(term_data["LastAddDayATerm"]) if term_data["LastAddDayBTerm"] is not None: term.bterm_last_day_add = parse_sws_date(term_data["LastAddDayBTerm"]) term.last_final_exam_date = parse_sws_date(term_data["LastFinalExamDay"]) term.grading_period_open = strptime(term_data["GradingPeriodOpen"], datetime_format) if term_data["GradingPeriodOpenATerm"] is not None: term.aterm_grading_period_open = strptime( term_data["GradingPeriodOpenATerm"], datetime_format) term.grading_period_close = strptime(term_data["GradingPeriodClose"], datetime_format) term.grade_submission_deadline = strptime( term_data["GradeSubmissionDeadline"], datetime_format) term.registration_services_start = parse_sws_date( term_data["RegistrationServicesStart"]) term.registration_period1_start = parse_sws_date( term_data["RegistrationPeriods"][0]["StartDate"]) term.registration_period1_end = parse_sws_date( term_data["RegistrationPeriods"][0]["EndDate"]) term.registration_period2_start = parse_sws_date( term_data["RegistrationPeriods"][1]["StartDate"]) term.registration_period2_end = parse_sws_date( term_data["RegistrationPeriods"][1]["EndDate"]) term.registration_period3_start = parse_sws_date( term_data["RegistrationPeriods"][2]["StartDate"]) term.registration_period3_end = parse_sws_date( term_data["RegistrationPeriods"][2]["EndDate"]) term.time_schedule_construction = [] for campus in term_data["TimeScheduleConstruction"]: tsc = TimeScheduleConstruction( campus=campus.lower(), is_on=(term_data["TimeScheduleConstruction"][campus] is True)) term.time_schedule_construction.append(tsc) term.clean_fields() return term
def _json_to_term_model(term_data): """ Returns a term model created from the passed json data. param: term_data loaded json data """ strptime = datetime.strptime day_format = "%Y-%m-%d" datetime_format = "%Y-%m-%dT%H:%M:%S" term = TermModel() term.year = term_data["Year"] term.quarter = term_data["Quarter"] term.last_day_add = parse_sws_date(term_data["LastAddDay"]) term.first_day_quarter = parse_sws_date(term_data["FirstDay"]) term.last_day_instruction = parse_sws_date(term_data["LastDayOfClasses"]) term.last_day_drop = parse_sws_date(term_data["LastDropDay"]) if term_data["ATermLastDay"] is not None: term.aterm_last_date = parse_sws_date(term_data["ATermLastDay"]) if term_data["BTermFirstDay"] is not None: term.bterm_first_date = parse_sws_date(term_data["BTermFirstDay"]) if term_data["LastAddDayATerm"] is not None: term.aterm_last_day_add = parse_sws_date(term_data["LastAddDayATerm"]) if term_data["LastAddDayBTerm"] is not None: term.bterm_last_day_add = parse_sws_date(term_data["LastAddDayBTerm"]) term.last_final_exam_date = parse_sws_date(term_data["LastFinalExamDay"]) term.grading_period_open = strptime( term_data["GradingPeriodOpen"], datetime_format) if term_data["GradingPeriodOpenATerm"] is not None: term.aterm_grading_period_open = strptime( term_data["GradingPeriodOpenATerm"], datetime_format) term.grading_period_close = strptime( term_data["GradingPeriodClose"], datetime_format) term.grade_submission_deadline = strptime( term_data["GradeSubmissionDeadline"], datetime_format) term.registration_services_start = parse_sws_date(term_data["RegistrationServicesStart"]) term.registration_period1_start = parse_sws_date(term_data["RegistrationPeriods"][0]["StartDate"]) term.registration_period1_end = parse_sws_date(term_data["RegistrationPeriods"][0]["EndDate"]) term.registration_period2_start = parse_sws_date(term_data["RegistrationPeriods"][1]["StartDate"]) term.registration_period2_end = parse_sws_date(term_data["RegistrationPeriods"][1]["EndDate"]) term.registration_period3_start = parse_sws_date(term_data["RegistrationPeriods"][2]["StartDate"]) term.registration_period3_end = parse_sws_date(term_data["RegistrationPeriods"][2]["EndDate"]) term.time_schedule_construction = [] for campus in term_data["TimeScheduleConstruction"]: tsc = TimeScheduleConstruction( campus=campus.lower(), is_on=(term_data["TimeScheduleConstruction"][campus] is True)) term.time_schedule_construction.append(tsc) term.clean_fields() return term