Example #1
0
    def test_json_for_evaluation(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS,
                           RESTCLIENTS_IASYSTEM_DAO_CLASS=FDAO_IAS):

            evals = get_evaluation_by_id(132136, "seattle")
            self.assertIsNotNone(evals)
            now_request = RequestFactory().get("/")
            # before open date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-11"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertEqual(len(json_data), 0)

            # after open date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-13"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data), 1)
            self.assertEqual(json_data[0]['close_date'],
                             "2013-03-23 07:59:59 UTC+0000")

            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-22"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data), 1)
            self.assertEqual(json_data[0]['close_date'],
                             "2013-03-23 07:59:59 UTC+0000")
            # after close date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-24"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertEqual(len(json_data), 0)
Example #2
0
    def test_json_for_evaluation(self):
        with self.settings(
            RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
            RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS,
            RESTCLIENTS_IASYSTEM_DAO_CLASS=FDAO_IAS,
        ):

            evals = get_evaluation_by_id(132136, "seattle")
            self.assertIsNotNone(evals)
            now_request = RequestFactory().get("/")
            # after show date, before open date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-11"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNone(json_data)
            # after open date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-13"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data["evals"]), 1)
            self.assertEqual(json_data["close_date"], "2013-03-23T07:59:59+00:00")

            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-22"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data["evals"]), 1)
            self.assertEqual(json_data["close_date"], "2013-03-23T07:59:59+00:00")
            # before hide date but after close date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-24"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNone(json_data)
Example #3
0
def load_course_eval(request, schedule, summer_term=""):
    """
    @return the course schedule sections having
    the attribute ["evaluation_data"] with the evaluations
    that should be shown; or
    "{}" if whouldn't display any; or
    None if a data error.
    """
    json_data = schedule.json_data()
    json_data["summer_term"] = summer_term

    section_index = 0
    for section in schedule.sections:
        section_data = json_data["sections"][section_index]
        section_index += 1
        try:
            section_data["evaluation_data"] = json_for_evaluation(
                request, get_evaluations_by_section(section), section)
        except Exception as ex:
            section_data["evaluation_data"] = None

    json_data["sections"] = sorted(json_data["sections"],
                                   key=itemgetter('curriculum_abbr',
                                                  'course_number',
                                                  'section_id'))
    return json_data
Example #4
0
def load_course_eval(request, schedule, summer_term=""):
    """
    @return the course schedule sections having
    the attribute ["evaluation_data"] with the evaluations
    that should be shown; or
    "{}" if whouldn't display any; or
    None if a data error.
    """
    json_data = schedule.json_data()
    json_data["summer_term"] = summer_term

    section_index = 0
    for section in schedule.sections:
        section_data = json_data["sections"][section_index]
        section_index += 1
        try:
            section_data["evaluation_data"] = json_for_evaluation(
                request, get_evaluations_by_section(section), section)
        except Exception as ex:
            section_data["evaluation_data"] = None

    json_data["sections"] = sorted(json_data["sections"],
                                   key=itemgetter('curriculum_abbr',
                                                  'course_number',
                                                  'section_id'))
    return json_data
Example #5
0
    def test_multiple_evals(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS,
                           RESTCLIENTS_IASYSTEM_DAO_CLASS=FDAO_IAS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"
            term = Term()
            term.year = 2013
            term.quarter = "spring"
            schedule = _get_schedule(regid, term)
            evals = None
            for section in schedule.sections:
                if section.curriculum_abbr == 'TRAIN' and\
                        section.course_number == '100' and\
                        section.section_id == 'A':
                    evals = _get_evaluations_by_section_and_student(
                        section, 1033334)
                    break
            self.assertIsNotNone(evals)
            self.assertEqual(len(evals), 3)
            self.assertEqual(evals[0].section_sln, 17169)
            self.assertEqual(
                evals[0].eval_open_date,
                datetime.datetime(2013, 5, 30, 15, 0, 0, tzinfo=pytz.utc))
            self.assertEqual(
                evals[0].eval_close_date,
                datetime.datetime(2013, 7, 1, 7, 59, 59, tzinfo=pytz.utc))
            self.assertFalse(evals[0].is_completed)
            self.assertEqual(
                evals[1].eval_open_date,
                datetime.datetime(2013, 6, 5, 7, 0, 0, tzinfo=pytz.utc))
            self.assertEqual(
                evals[1].eval_close_date,
                datetime.datetime(2013, 6, 17, 6, 59, 59, tzinfo=pytz.utc))
            self.assertFalse(evals[1].is_completed)
            self.assertEqual(
                evals[2].eval_open_date,
                datetime.datetime(2013, 6, 10, 7, 0, 0, tzinfo=pytz.utc))
            self.assertEqual(
                evals[2].eval_close_date,
                datetime.datetime(2013, 6, 19, 6, 59, 59, tzinfo=pytz.utc))
            self.assertTrue(evals[2].is_completed)
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-05-30"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertEqual(len(json_data), 0)

            # open dates of 1 eval
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-05-31"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data), 1)
            self.assertEqual(json_data[0]['close_date'],
                             "2013-07-01 07:59:59 UTC+0000")
            # after open dates of 1 eval
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-04"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data), 1)

            # after open dates of two evals
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-05"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data), 2)
            self.assertEqual(json_data[0]['close_date'],
                             "2013-07-01 07:59:59 UTC+0000")
            self.assertEqual(json_data[1]['close_date'],
                             "2013-06-17 06:59:59 UTC+0000")

            # after open dates of three evals
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-10"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data), 2)

            # after close date of one eval
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-17"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertEqual(len(json_data), 1)
            self.assertEqual(json_data[0]['close_date'],
                             "2013-07-01 07:59:59 UTC+0000")

            # after close date of two evals
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-19"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertEqual(len(json_data), 1)

            # after close date of last eval
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-07-02"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertEqual(len(json_data), 0)
Example #6
0
class IASystemDaoTest(TestCase):
    def setUp(self):
        fake_request = RequestFactory()
        fake_request.session = {}
        UserServiceMiddleware().process_request(fake_request)

    def test_summer_term_overlaped(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS):
            term = Term()
            term.year = 2013
            term.quarter = "summer"
            section = Section()
            section.summer_term = "A-term"
            section.term = term

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-07-10"
            self.assertTrue(summer_term_overlaped(now_request, section))
            section.summer_term = "Full-term"
            self.assertFalse(summer_term_overlaped(now_request, section))
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-08-10"
            self.assertTrue(summer_term_overlaped(now_request, section))

            section.summer_term = "B-term"
            self.assertTrue(summer_term_overlaped(now_request, section))

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-10"
            self.assertTrue(summer_term_overlaped(now_request, 'None'))
            self.assertTrue(summer_term_overlaped(now_request, '-'))

    def test_get_evaluations_by_section(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS,
                           RESTCLIENTS_IASYSTEM_DAO_CLASS=FDAO_IAS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"
            term = Term()
            term.year = 2013
            term.quarter = "summer"
            section = Section()
            section.summer_term = "A-term"
            section.term = term
            schedule = _get_schedule(regid, term)
            evals = None
            for section in schedule.sections:
                if section.curriculum_abbr == 'ELCBUS':
                    evals = _get_evaluations_by_section_and_student(
                        section, 1443336)
                    break
            self.assertIsNotNone(evals)
            self.assertEqual(evals[0].section_sln, 13833)
            self.assertEqual(
                evals[0].eval_open_date,
                datetime.datetime(2013, 7, 02, 14, 0, tzinfo=pytz.utc))
            self.assertEqual(
                evals[0].eval_close_date,
                datetime.datetime(2013, 7, 23, 6, 59, 59, tzinfo=pytz.utc))
            self.assertFalse(evals[0].is_completed)

            now_request = RequestFactory().get("/")

            # after open date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-07-03"
            json_data = json_for_evaluation(now_request, evals, section)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data), 1)
            self.assertEqual(json_data[0]['close_date'],
                             "2013-07-23 06:59:59 UTC+0000")
            # before close date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-07-22"
            json_data = json_for_evaluation(now_request, evals, section)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data), 1)

            # after close date
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-07-24"
            json_data = json_for_evaluation(now_request, evals, section)
            self.assertEqual(len(json_data), 0)
Example #7
0
    def test_multiple_instructor(self):
        with self.settings(
            RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
            RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS,
            RESTCLIENTS_IASYSTEM_DAO_CLASS=FDAO_IAS,
        ):

            regid = "9136CCB8F66711D5BE060004AC494FFE"
            term = Term()
            term.year = 2013
            term.quarter = "spring"
            schedule = _get_schedule(regid, term)
            evals = None
            for section in schedule.sections:
                if section.curriculum_abbr == "TRAIN" and section.course_number == "100" and section.section_id == "A":
                    evals = _get_evaluations_by_section_and_student(section, 1033334)
                    break
            self.assertIsNotNone(evals)
            self.assertEqual(len(evals), 3)
            self.assertEqual(evals[0].section_sln, 17169)
            self.assertEqual(evals[0].eval_open_date, datetime.datetime(2013, 5, 30, 15, 0, 0, tzinfo=pytz.utc))
            self.assertEqual(evals[0].eval_close_date, datetime.datetime(2013, 7, 1, 7, 59, 59, tzinfo=pytz.utc))
            self.assertEqual(evals[1].eval_open_date, datetime.datetime(2013, 6, 5, 7, 0, 0, tzinfo=pytz.utc))
            self.assertEqual(evals[1].eval_close_date, datetime.datetime(2013, 6, 17, 6, 59, 59, tzinfo=pytz.utc))
            self.assertEqual(evals[2].eval_open_date, datetime.datetime(2013, 6, 10, 7, 0, 0, tzinfo=pytz.utc))
            self.assertEqual(evals[2].eval_close_date, datetime.datetime(2013, 6, 19, 6, 59, 59, tzinfo=pytz.utc))
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-05-30"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNone(json_data)
            # after show date and open dates of 1 eval
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-05-31"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data["evals"]), 1)
            self.assertEqual(json_data["close_date"], "2013-07-01T07:59:59+00:00")
            # after open dates of 1 eval
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-04"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data["evals"]), 1)
            self.assertEqual(json_data["close_date"], "2013-07-01T07:59:59+00:00")
            # after open dates of two evals
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-05"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data["evals"]), 2)
            self.assertEqual(json_data["close_date"], "2013-06-17T06:59:59+00:00")
            # after open dates of three evals
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-10"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertIsNotNone(json_data)
            self.assertEqual(len(json_data["evals"]), 3)
            self.assertEqual(json_data["close_date"], "2013-06-17T06:59:59+00:00")
            # after close date of one eval
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-17"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertEqual(len(json_data["evals"]), 2)
            self.assertEqual(json_data["close_date"], "2013-06-19T06:59:59+00:00")
            # after close date of two evals
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-19"
            json_data = json_for_evaluation(now_request, evals, None)
            self.assertEqual(len(json_data["evals"]), 1)
            self.assertEqual(json_data["close_date"], "2013-07-01T07:59:59+00:00")
Example #8
0
def load_schedule(request, schedule, summer_term=""):
    filter_schedule_sections_by_summer_term(schedule, summer_term)
    json_data = schedule.json_data()
    json_data["summer_term"] = summer_term

    if len(schedule.sections) == 0:
        return json_data

    colors = get_colors_by_schedule(schedule)
    if colors is None and len(schedule.sections) > 0:
        return None

    buildings = get_buildings_by_schedule(schedule)

    # Removing call to Canvas pending MUWM-2106
    # Too much!  MUWM-2270
    # canvas_data_by_course_id = []
    canvas_data_by_primary_course_id = get_canvas_enrolled_courses()

    primary = canvas_data_by_primary_course_id
    canvas_data_by_course_id = get_indexed_by_decrosslisted(primary, schedule.sections)

    # Since the schedule is restclients, and doesn't know
    # about color ids, backfill that data
    section_index = 0
    for section in schedule.sections:
        section_data = json_data["sections"][section_index]
        color = colors[section.section_label()]
        section_data["color_id"] = color
        section_index += 1
        #        if section.is_primary_section:
        section_data["lib_subj_guide"] = get_subject_guide_by_section(section)

        try:
            evaluation_json_data = json_for_evaluation(
                request, get_evaluations_by_section(section), section.summer_term
            )
        except Exception as ex:
            evaluation_json_data = None

        if evaluation_json_data is not None:
            section_data["evaluation_data"] = evaluation_json_data

        if section.section_label() in canvas_data_by_course_id:
            enrollment = canvas_data_by_course_id[section.section_label()]
            canvas_url = enrollment.course_url
            canvas_name = enrollment.course_name
            # canvas_grade = enrollment.final_grade
            section_data["canvas_url"] = canvas_url
            section_data["canvas_name"] = canvas_name
            # section_data["canvas_grade"] = canvas_grade

        # MUWM-596
        if section.final_exam and section.final_exam.building:
            building = buildings[section.final_exam.building]
            if building:
                section_data["final_exam"]["longitude"] = building.longitude
                section_data["final_exam"]["latitude"] = building.latitude
                section_data["final_exam"]["building_name"] = building.name

        # Also backfill the meeting building data
        meeting_index = 0
        for meeting in section.meetings:
            try:
                mdata = section_data["meetings"][meeting_index]
                if not mdata["building_tbd"]:
                    building = buildings[mdata["building"]]
                    if building is not None:
                        mdata["latitude"] = building.latitude
                        mdata["longitude"] = building.longitude
                        mdata["building_name"] = building.name

                for instructor in mdata["instructors"]:
                    if (
                        not instructor["email1"]
                        and not instructor["email2"]
                        and not instructor["phone1"]
                        and not instructor["phone2"]
                        and not instructor["voicemail"]
                        and not instructor["fax"]
                        and not instructor["touchdial"]
                        and not instructor["address1"]
                        and not instructor["address2"]
                    ):
                        instructor["whitepages_publish"] = False
                meeting_index += 1
            except IndexError as ex:
                pass

    # MUWM-443
    json_data["sections"] = sorted(
        json_data["sections"], key=itemgetter("curriculum_abbr", "course_number", "section_id")
    )
    json_data["is_grad_student"] = is_grad_student()
    return json_data