Пример #1
0
 def test_update_schedule_general(self):
     _, cis121, cis121_reviews = create_mock_data_with_reviews("CIS-121-001", TEST_SEMESTER, 2)
     _, cis160, cis160_reviews = create_mock_data_with_reviews("CIS-160-001", TEST_SEMESTER, 2)
     response = self.client.post(
         "/api/plan/schedules/",
         json.dumps(
             {
                 "id": str(self.s.id),
                 "semester": TEST_SEMESTER,
                 "name": "New Test Schedule",
                 "sections": [
                     {"id": "CIS-121-001", "semester": TEST_SEMESTER},
                     {"id": "CIS-160-001", "semester": TEST_SEMESTER},
                 ],
             }
         ),
         content_type="application/json",
     )
     self.assertEqual(response.status_code, 200)
     response = self.client.get("/api/plan/schedules/")
     self.assertEqual(200, response.status_code)
     self.assertEqual(1, len(response.data))
     self.assertEqual(response.data[0]["name"], "New Test Schedule")
     self.assertEqual(response.data[0]["semester"], TEST_SEMESTER)
     self.assertEqual(len(response.data[0]["sections"]), 2)
     self.assertEquals(1, sum([s["id"] == "CIS-121-001" for s in response.data[0]["sections"]]))
     self.assertEquals(1, sum([s["id"] == "CIS-160-001" for s in response.data[0]["sections"]]))
     for s in response.data[0]["sections"]:
         if s["id"] == "CIS-121-001":
             section_cis121 = s
         if s["id"] == "CIS-160-001":
             section_cis160 = s
     self.check_serialized_section(section_cis121, cis121, cis121_reviews, True)
     self.check_serialized_section(section_cis160, cis160, cis160_reviews, True)
Пример #2
0
 def test_section_dne_one(self):
     create_mock_data_with_reviews("CIS-160-001", TEST_SEMESTER, 2)
     response = self.client.post(
         "/api/plan/schedules/",
         json.dumps(
             {
                 "semester": TEST_SEMESTER,
                 "name": "New Test Schedule",
                 "sections": [
                     {"id": "CIS-121-001", "semester": TEST_SEMESTER},
                     {"id": "CIS-160-001", "semester": TEST_SEMESTER},
                 ],
             }
         ),
         content_type="application/json",
     )
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.data["detail"], "One or more sections not found in database.")
Пример #3
0
 def test_name_already_exists(self):
     create_mock_data_with_reviews("CIS-121-001", TEST_SEMESTER, 2)
     create_mock_data_with_reviews("CIS-160-001", TEST_SEMESTER, 2)
     response = self.client.post(
         "/api/plan/schedules/",
         json.dumps(
             {
                 "semester": TEST_SEMESTER,
                 "name": "My Test Schedule",
                 "sections": [
                     {"id": "CIS-121-001", "semester": TEST_SEMESTER},
                     {"id": "CIS-160-001", "semester": TEST_SEMESTER},
                 ],
             }
         ),
         content_type="application/json",
     )
     self.assertEqual(400, response.status_code)
Пример #4
0
 def test_semesters_not_uniform(self):
     create_mock_data_with_reviews("CIS-121-001", "1739C", 2)
     create_mock_data_with_reviews("CIS-160-001", TEST_SEMESTER, 2)
     response = self.client.post(
         "/api/plan/schedules/",
         json.dumps(
             {
                 "semester": TEST_SEMESTER,
                 "name": "New Test Schedule",
                 "sections": [
                     {"id": "CIS-121-001", "semester": "1739C"},
                     {"id": "CIS-160-001", "semester": TEST_SEMESTER},
                 ],
             }
         ),
         content_type="application/json",
     )
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.data["detail"], "Semester uniformity invariant violated.")
Пример #5
0
 def setUp(self):
     set_semester()
     _, self.cis120, self.cis120_reviews = create_mock_data_with_reviews(
         "CIS-120-001", TEST_SEMESTER, 2
     )
     self.s = Schedule(
         person=User.objects.create_user(
             username="******", email="*****@*****.**", password="******"
         ),
         semester=TEST_SEMESTER,
         name="My Test Schedule",
     )
     self.s.save()
     self.s.sections.set([self.cis120])
     self.client = APIClient()
     self.client.login(username="******", password="******")