Exemplo n.º 1
0
 def test_double_count_req(self):
     req2 = PreNGSSRequirement(semester=TEST_SEMESTER, code="REQ2", school="SEAS")
     req2.save()
     req2.courses.add(self.math)
     response = self.client.get(
         reverse("courses-search", args=["current"]),
         {"pre_ngss_requirements": "REQ@SAS,REQ2@SEAS"},
     )
     self.assertEqual(1, len(response.data))
     self.assertEqual("MATH-114", response.data[0]["id"])
Exemplo n.º 2
0
    def test_multi_req(self):
        course3, section3 = create_mock_data("CIS-240-001", TEST_SEMESTER)
        req2 = PreNGSSRequirement(semester=TEST_SEMESTER, code="REQ2", school="SEAS")
        req2.save()
        req2.courses.add(course3)

        response = self.client.get(
            reverse("courses-search", args=["current"]),
            {"pre_ngss_requirements": "REQ@SAS,REQ2@SEAS"},
        )
        self.assertEqual(0, len(response.data))
Exemplo n.º 3
0
 def setUp(self):
     self.course, self.section = create_mock_data("CIS-120-001", TEST_SEMESTER)
     self.math, self.math1 = create_mock_data("MATH-114-001", TEST_SEMESTER)
     self.different_math, self.different_math1 = create_mock_data(
         "MATH-116-001", ("2019A" if TEST_SEMESTER == "2019C" else "2019C")
     )
     self.req = PreNGSSRequirement(semester=TEST_SEMESTER, code="REQ", school="SAS")
     self.req.save()
     self.req.courses.add(self.math)
     print(self.req.satisfying_courses)
     self.client = APIClient()
     set_semester()
Exemplo n.º 4
0
 def test_filter_for_req_dif_sem(self):
     req2 = PreNGSSRequirement(
         semester=("2019A" if TEST_SEMESTER == "2019C" else "2019C"), code="REQ", school="SAS"
     )
     req2.save()
     req2.courses.add(self.different_math)
     response = self.client.get(
         reverse("courses-search", args=["current"]), {"pre_ngss_requirements": "REQ@SAS"}
     )
     self.assertEqual(200, response.status_code)
     self.assertEqual(1, len(response.data))
     self.assertEqual("MATH-114", response.data[0]["id"])
     self.assertEqual(TEST_SEMESTER, response.data[0]["semester"])
Exemplo n.º 5
0
    def setUp(self):
        set_semester()
        get_or_create_course(
            "CIS", "120",
            "2012A")  # dummy course to make sure we're filtering by semester
        self.course, _ = get_or_create_course("CIS", "120", TEST_SEMESTER)
        self.course2, _ = get_or_create_course("CIS", "125", TEST_SEMESTER)
        self.department = Department.objects.get(code="CIS")

        self.req1 = PreNGSSRequirement(semester=TEST_SEMESTER,
                                       school="SAS",
                                       code="TEST1",
                                       name="Test 1")
        self.req2 = PreNGSSRequirement(semester=TEST_SEMESTER,
                                       school="SAS",
                                       code="TEST2",
                                       name="Test 2")
        self.req3 = PreNGSSRequirement(semester="XXXXX",
                                       school="SAS",
                                       code="TEST1",
                                       name="Test 1+")

        self.req1.save()
        self.req2.save()
        self.req3.save()

        self.req1.departments.add(self.department)
        self.req1.overrides.add(self.course2)
        self.req2.courses.add(self.course)
        self.req2.courses.add(self.course2)
        self.req3.departments.add(self.department)

        self.client = APIClient()
Exemplo n.º 6
0
class PreNGSSRequirementFilterTestCase(TestCase):
    def setUp(self):
        self.course, self.section = create_mock_data("CIS-120-001", TEST_SEMESTER)
        self.math, self.math1 = create_mock_data("MATH-114-001", TEST_SEMESTER)
        self.different_math, self.different_math1 = create_mock_data(
            "MATH-116-001", ("2019A" if TEST_SEMESTER == "2019C" else "2019C")
        )
        self.req = PreNGSSRequirement(semester=TEST_SEMESTER, code="REQ", school="SAS")
        self.req.save()
        self.req.courses.add(self.math)
        print(self.req.satisfying_courses)
        self.client = APIClient()
        set_semester()

    def test_return_all_courses(self):
        response = self.client.get(reverse("courses-search", args=["current"]))
        self.assertEqual(200, response.status_code)
        self.assertEqual(2, len(response.data))

    def test_filter_for_req(self):
        response = self.client.get(
            reverse("courses-search", args=["current"]), {"pre_ngss_requirements": "REQ@SAS"}
        )
        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(response.data))
        self.assertEqual("MATH-114", response.data[0]["id"])

    def test_filter_for_req_dif_sem(self):
        req2 = PreNGSSRequirement(
            semester=("2019A" if TEST_SEMESTER == "2019C" else "2019C"), code="REQ", school="SAS"
        )
        req2.save()
        req2.courses.add(self.different_math)
        response = self.client.get(
            reverse("courses-search", args=["current"]), {"pre_ngss_requirements": "REQ@SAS"}
        )
        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(response.data))
        self.assertEqual("MATH-114", response.data[0]["id"])
        self.assertEqual(TEST_SEMESTER, response.data[0]["semester"])

    def test_multi_req(self):
        course3, section3 = create_mock_data("CIS-240-001", TEST_SEMESTER)
        req2 = PreNGSSRequirement(semester=TEST_SEMESTER, code="REQ2", school="SEAS")
        req2.save()
        req2.courses.add(course3)

        response = self.client.get(
            reverse("courses-search", args=["current"]),
            {"pre_ngss_requirements": "REQ@SAS,REQ2@SEAS"},
        )
        self.assertEqual(0, len(response.data))

    def test_double_count_req(self):
        req2 = PreNGSSRequirement(semester=TEST_SEMESTER, code="REQ2", school="SEAS")
        req2.save()
        req2.courses.add(self.math)
        response = self.client.get(
            reverse("courses-search", args=["current"]),
            {"pre_ngss_requirements": "REQ@SAS,REQ2@SEAS"},
        )
        self.assertEqual(1, len(response.data))
        self.assertEqual("MATH-114", response.data[0]["id"])
Exemplo n.º 7
0
class PreNGSSRequirementTestCase(TestCase):
    def setUp(self):
        set_semester()
        get_or_create_course(
            "CIS", "120",
            "2012A")  # dummy course to make sure we're filtering by semester
        self.course, _ = get_or_create_course("CIS", "120", TEST_SEMESTER)
        self.course2, _ = get_or_create_course("CIS", "125", TEST_SEMESTER)
        self.department = Department.objects.get(code="CIS")

        self.req1 = PreNGSSRequirement(semester=TEST_SEMESTER,
                                       school="SAS",
                                       code="TEST1",
                                       name="Test 1")
        self.req2 = PreNGSSRequirement(semester=TEST_SEMESTER,
                                       school="SAS",
                                       code="TEST2",
                                       name="Test 2")
        self.req3 = PreNGSSRequirement(semester="XXXXX",
                                       school="SAS",
                                       code="TEST1",
                                       name="Test 1+")

        self.req1.save()
        self.req2.save()
        self.req3.save()

        self.req1.departments.add(self.department)
        self.req1.overrides.add(self.course2)
        self.req2.courses.add(self.course)
        self.req2.courses.add(self.course2)
        self.req3.departments.add(self.department)

        self.client = APIClient()

    def assertCoursesEqual(self, expected, actual):
        def get_codes(x):
            sorted([f"{c.department.code}-{c.code}" for c in x])

        self.assertEqual(get_codes(expected), get_codes(actual))

    def test_requirements_nooverride(self):
        reqs = self.course.pre_ngss_requirements
        self.assertTrue(2, len(reqs))

    def test_requirements_override(self):
        reqs = self.course2.pre_ngss_requirements
        self.assertEqual(1, len(reqs))
        self.assertEqual(self.req2, reqs[0])

    def test_satisfying_courses(self):
        # make it so req1 has one department-level requirement, one course-level one,
        # and one override.
        c1, _ = get_or_create_course("MEAM", "101", TEST_SEMESTER)
        self.req1.courses.add(c1)
        courses = self.req1.satisfying_courses.all()
        self.assertEqual(2, len(courses))

        self.assertCoursesEqual([self.course, c1], courses)

    def test_override_precedent(self):
        # even if a course is in the list of courses, don't include it if it's in the
        # list of overrides
        self.req1.courses.add(self.course2)
        courses = self.req1.satisfying_courses.all()
        self.assertEqual(1, len(courses))
        self.assertCoursesEqual([self.course], courses)
        reqs = self.course2.pre_ngss_requirements
        self.assertEqual(1, len(reqs))
        self.assertEqual(self.req2, reqs[0])