Example #1
0
 def test_find_friends(self):
     request = self.factory.get("/user/classmates/Fall/2000/")
     response = get_auth_response(request, self.user3,
                                  "/user/classmates/Fall/2016/", "Fall",
                                  "2000")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response.data), 2)
Example #2
0
 def test_rename_timetable(self):
     data = {
         "id": 10,
         "semester": {
             "name": "Winter",
             "year": "1995"
         },
         "slots": [{
             "course": 1,
             "section": 1,
             "offerings": [1],
         }],
         "events": [],
         "name": "renamed",
         "has_conflict": False,
     }
     PersonalTimetable.objects.create(id=10,
                                      name="oldtt",
                                      school="uoft",
                                      semester=self.sem,
                                      student=self.student)
     request = self.factory.post("/user/timetables/", data, format="json")
     response = get_auth_response(request, self.user, "/user/timetables/")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(PersonalTimetable.objects.get(id=10).name, "renamed")
Example #3
0
    def test_add_reaction(self):
        data = {"cid": 1, "title": self.title}
        request = self.factory.post("/user/reactions/", data, format="json")
        response = get_auth_response(request, self.user, "/user/reactions/")
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertTrue("reactions" in response.data)
        Reaction.objects.get(student=self.student, title=self.title)
        self.assertGreater(Course.objects.get(id=1).reaction_set.count(), 0)
Example #4
0
 def test_get_timetables(self):
     request = self.factory.get("/user/timetables/Winter/1995/",
                                format="json")
     response = get_auth_response(request, self.user,
                                  "/user/timetables/Winter/1995/", "Winter",
                                  "1995")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response.data["timetables"]), 1)
     self.assertEqual(len(response.data["courses"]), 1)
Example #5
0
 def test_set_token(self):
     """Test updating an existing token."""
     self.test_create_token_student()
     new_token = {
         "auth": "somenewauth",
         "p256dh": "somenewthing",
         "endpoint": "somenew endpoint",
     }
     request = self.putTokenAuth(new_token)
     response = get_auth_response(request, self.user, "/registration-token/")
     self.assert_token_data(response, new_token)
Example #6
0
 def test_duplicate_timetable(self):
     data = {
         "source": "tt",
         "semester": {
             "name": "Winter",
             "year": "1995"
         },
         "name": "dupe tt",
     }
     request = self.factory.post("/user/timetables/", data, format="json")
     response = get_auth_response(request, self.user, "/user/timetables/")
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     PersonalTimetable.objects.get(name="dupe tt")
Example #7
0
 def test_update_settings(self):
     new_settings = {
         "emails_enabled": True,
         "social_courses": True,
         "major": "CS"
     }
     request = self.factory.patch("/user/settings/",
                                  new_settings,
                                  format="json")
     response = get_auth_response(request, self.user, "/user/settings/")
     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
     self.student = Student.objects.get(user=self.user)
     self.assertDictContainsSubset(new_settings,
                                   model_to_dict(self.student))
Example #8
0
    def test_get_classmates(self):
        request = self.factory.get("/user/classmates/Fall/2000/",
                                   {"course_ids[]": [1]})
        response = get_auth_response(request, self.user2,
                                     "/user/classmates/Fall/2016/", "Fall",
                                     "2000")
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(len(response.data), 1)
        classmates = response.data[1]["current"]  # key is course id
        self.assertEqual(len(classmates), 1)
        self.assertEqual(classmates[0]["first_name"], self.user1.first_name)
        self.assertEqual(classmates[0]["last_name"], self.user1.last_name)
        self.assertEqual(len(response.data[1]["past"]), 0)
Example #9
0
 def test_get_classmate_counts(self):
     request = self.factory.get("/user/classmates/Fall/2000/", {
         "count": True,
         "course_ids[]": [1]
     })
     response = get_auth_response(request, self.user2,
                                  "/user/classmates/Fall/2016/", "Fall",
                                  "2000")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertDictEqual(response.data, {
         "id": 1,
         "count": 1,
         "total_count": 1
     })
Example #10
0
 def test_delete_timetable(self):
     PersonalTimetable.objects.create(
         id=20,
         name="todelete",
         school="uoft",
         semester=self.sem,
         student=self.student,
     )
     request = self.factory.delete("/user/timetables/Winter/1995/todelete")
     response = get_auth_response(
         request,
         self.user,
         "/user/timetables/",
         "Winter",
         "1995",
         "todelete",
     )
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertFalse(PersonalTimetable.objects.filter(id=20).exists())
Example #11
0
 def test_create_timetable_exists(self):
     data = {
         "semester": {
             "name": "Winter",
             "year": "1995"
         },
         "slots": [{
             "course": 1,
             "section": 1,
             "offerings": [1],
         }],
         "events": [],
         "name": "tt",
         "has_conflict": False,
     }
     request = self.factory.post("/user/timetables/", data, format="json")
     force_authenticate(request, user=self.user)
     response = get_auth_response(request, self.user, "/user/timetables/")
     self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
Example #12
0
 def test_create_timetable(self):
     data = {
         "semester": {
             "name": "Winter",
             "year": "1995"
         },
         "slots": [{
             "course": 1,
             "section": 1,
             "offerings": [1],
         }],
         "events": [],
         "name": "new tt",
         "has_conflict": False,
     }
     request = self.factory.post("/user/timetables/", data, format="json")
     response = get_auth_response(request, self.user, "/user/timetables/")
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     PersonalTimetable.objects.get(name="new tt")
Example #13
0
    def test_delete_user(self):
        sem = Semester.objects.create(name="Winter", year="2000")
        course = Course.objects.create(school="skool",
                                       code="A101",
                                       name="intro")
        section = Section.objects.create(course=course,
                                         meeting_section="A",
                                         semester=sem)
        reaction = Reaction.objects.create(student=self.student, title="FIRE")
        reaction.course.add(course)
        reaction.save()

        tt = PersonalTimetable.objects.create(semester=sem,
                                              school="skool",
                                              name="mytt",
                                              student=self.student)
        event = PersonalEvent.objects.create(name="gym",
                                             day="T",
                                             time_start="8:00",
                                             time_end="9:00")
        tt.events.add(event)
        tt.courses.add(course)
        tt.sections.add(section)
        tt.save()

        request = self.factory.delete("/user/settings/")
        response = get_auth_response(request, self.user, "/user/settings/")
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # all student related data should be deleted
        self.assertFalse(User.objects.exists())
        self.assertFalse(Student.objects.exists())
        self.assertFalse(PersonalTimetable.objects.exists())
        self.assertFalse(PersonalEvent.objects.exists())
        self.assertFalse(RegistrationToken.objects.exists())

        # course data should be untouched
        self.assertTrue(Course.objects.exists())
        self.assertTrue(Section.objects.exists())
        self.assertTrue(Semester.objects.exists())
Example #14
0
 def test_create_token_student(self):
     """Test creating a new token when logged in."""
     self.setUpAuth()
     request = self.putTokenAuth(self.token)
     response = get_auth_response(request, self.user, "/registration-token/")
     self.assert_token_data(response, self.token)