Beispiel #1
0
 def setUp(self) -> None:
     UserAuth(expiring_token="valid_token",
              access_token="valid_token",
              user_email="*****@*****.**").save()
     UserAuth(expiring_token="expired_token",
              access_token="expired_token",
              user_email="*****@*****.**").save()
     Course(course_code="TMA4100",
            course_name="Matematikk 1",
            credit=7.5,
            average_grade=2,
            pass_rate=100.0).save()
Beispiel #2
0
 def setUp(self) -> None:
     courses = [
         Course(course_code="TDT4120", course_name="AlgDat", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TMA4100", course_name="Matte 1", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="EXPH0004", course_name="Exphil", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TFE4101", course_name="KretsDigtek", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TFY4125", course_name="Fysikk", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TDT4290", course_name="KPro", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TDT4136", course_name="AI Intro", credit=7.5, average_grade=1, pass_rate=100.0),
     ]
     for c in courses: c.save()
     reviews = [
         Review(id=1, course_code="TMA4100", user_email="*****@*****.**", score=5, workload=1, difficulty=2,
                review_text="Bra f*g", full_name="Test test", study_programme="MTDT"),
         Review(id=2, course_code="TMA4100", user_email="*****@*****.**", score=3, workload=0, difficulty=0,
                review_text="Givende", full_name="KPro Kproson", study_programme="MTKPRO"),
         Review(id=3, course_code="TMA4100", user_email="*****@*****.**", score=4, workload=1, difficulty=2,
                review_text="Lattice", full_name="Heman 2015", study_programme="MTDT"),
         Review(id=4, course_code="TDT4120", user_email="*****@*****.**", score=5, workload=2, difficulty=2,
                review_text="Kult", full_name="KPro Kproson", study_programme="MTKPRO"),
         Review(id=5, course_code="TDT4120", user_email="*****@*****.**", score=1, workload=0, difficulty=0,
                review_text="Kjipt", full_name="Test test", study_programme="MTDT"),
         Review(id=6, course_code="EXPH0004", user_email="*****@*****.**", score=3, workload=1, difficulty=0,
                review_text="<3", full_name="KPro Kproson", study_programme="MTDT")
     ]
     for r in reviews: r.save()
     UserAuth(expiring_token="valid_token", access_token="valid_token", user_email="*****@*****.**").save()
     User.objects.create(username="******", email="*****@*****.**").save()
Beispiel #3
0
 def test_get_user(self):
     self.assertEqual(get_user('valid_token').email, "*****@*****.**")
     User.objects.get(username="******").delete()
     self.assertIsNone(get_user('valid_token'))
     # Making user auth without corresponding user
     UserAuth(expiring_token="valid_token_missing_user",
              access_token="valid_token_missing_user",
              user_email="*****@*****.**").save()
     self.assertIsNone(get_user('valid_token_missing_user'))
Beispiel #4
0
 def setUp(self) -> None:
     # Crowd database with courses
     UserAuth(expiring_token="valid_token",
              access_token="valid_token",
              user_email="*****@*****.**").save()
     courses = _create_models_without_saving()
     for course in courses:
         course.save()
     self.rf = RequestFactory()
Beispiel #5
0
 def test_delete_upvote_missing_user(self):
     User.objects.get(username="******").delete()
     self.assertEqual(
         self.api_client.delete("/upvote/delete/?reviewId=1").status_code,
         401)
     UserAuth(expiring_token="valid_token_missing_user",
              access_token="valid_token_missing_user",
              user_email="*****@*****.**").save()
     api_client_missing_user = APIClient()
     api_client_missing_user.credentials(
         HTTP_AUTHORIZATION="valid_token_missing_user")
     self.assertEqual(
         api_client_missing_user.delete(
             "/upvote/delete/?reviewId=1").status_code, 401)
Beispiel #6
0
 def test_post_upvote_missing_user(self):
     # The website mainly uses authentication and user data from Feide.
     # Upvotes however, use the User that is created in our database during authentication.
     User.objects.get(username="******").delete()
     self.assertEqual(
         self.api_client.post("/upvote/?reviewId=1").status_code, 401)
     UserAuth(expiring_token="valid_token_missing_user",
              access_token="valid_token_missing_user",
              user_email="*****@*****.**").save()
     api_client_missing_user = APIClient()
     api_client_missing_user.credentials(
         HTTP_AUTHORIZATION="valid_token_missing_user")
     self.assertEqual(
         api_client_missing_user.post("/upvote/?reviewId=1").status_code,
         401)
Beispiel #7
0
 def setUp(self):
     UserAuth(expiring_token="valid_token",
              access_token="valid_token",
              user_email="*****@*****.**").save()
     self.api_client = APIClient()
     self.api_client.credentials(HTTP_AUTHORIZATION="valid_token")
     User.objects.create(username="******",
                         email="*****@*****.**").save()
     User.objects.create(username="******",
                         email="*****@*****.**").save()
     Course(course_code="TMA4100",
            course_name="Matte 1",
            credit=7.5,
            average_grade=1,
            pass_rate=100.0).save()
     Review(course_code="TMA4100",
            user_email="*****@*****.**",
            score=5,
            workload=1,
            difficulty=2,
            review_text="Bra f*g",
            full_name="Test test",
            study_programme="MTDT").save()
     Review(course_code="TMA4100",
            user_email="*****@*****.**",
            score=3,
            workload=1,
            difficulty=2,
            review_text="Givende",
            full_name="KPro Kproson",
            study_programme="MTKPRO").save()
     self.curr_user = User.objects.get(username="******")
     self.other_user = User.objects.get(username="******")
     self.review1 = Review.objects.get(course_code="TMA4100",
                                       user_email="*****@*****.**")
     self.review2 = Review.objects.get(course_code="TMA4100",
                                       user_email="*****@*****.**")
     Upvote(user=self.curr_user, review=self.review1).save()
     Upvote(user=self.other_user, review=self.review1).save()
Beispiel #8
0
    def setUp(self):
        UserAuth(expiring_token="valid_token",
                 access_token="valid_token",
                 user_email="*****@*****.**").save()
        self.api_client = APIClient()
        self.api_client.credentials(HTTP_AUTHORIZATION="valid_token")
        User.objects.create(username="******",
                            email="*****@*****.**").save()
        # More users?

        courses = [
            Course(course_code="TDT4120",
                   course_name="AlgDat",
                   credit=7.5,
                   average_grade=1,
                   pass_rate=100.0),
            Course(course_code="TMA4100",
                   course_name="Matte 1",
                   credit=7.5,
                   average_grade=1,
                   pass_rate=100.0),
            Course(course_code="EXPH0004",
                   course_name="Exphil",
                   credit=7.5,
                   average_grade=1,
                   pass_rate=100.0),
            Course(course_code="TFE4101",
                   course_name="KretsDigtek",
                   credit=7.5,
                   average_grade=1,
                   pass_rate=100.0),
            Course(course_code="TFY4125",
                   course_name="Fysikk",
                   credit=7.5,
                   average_grade=1,
                   pass_rate=100.0),
            Course(course_code="TDT4290",
                   course_name="KPro",
                   credit=7.5,
                   average_grade=1,
                   pass_rate=100.0),
            Course(course_code="TDT4136",
                   course_name="AI Intro",
                   credit=7.5,
                   average_grade=1,
                   pass_rate=100.0),
        ]
        for c in courses:
            c.save()
        reviews = [
            Review(course_code="TMA4100",
                   user_email="*****@*****.**",
                   score=5,
                   workload=1,
                   difficulty=2,
                   review_text="Bra f*g",
                   full_name="Test test",
                   study_programme="MTDT"),
            Review(course_code="TMA4100",
                   user_email="*****@*****.**",
                   score=3,
                   workload=1,
                   difficulty=2,
                   review_text="Givende",
                   full_name="KPro Kproson",
                   study_programme="MTKPRO"),
            Review(course_code="TMA4100",
                   user_email="*****@*****.**",
                   score=4,
                   workload=1,
                   difficulty=2,
                   review_text="Lattice",
                   full_name="Heman 2015",
                   study_programme="MTDT"),
            Review(course_code="TMA4100",
                   user_email="*****@*****.**",
                   score=2,
                   workload=1,
                   difficulty=2,
                   review_text="Helt ok f*g",
                   full_name="Hanna Montana",
                   study_programme="MTTEST"),
            Review(course_code="TMA4100",
                   user_email="*****@*****.**",
                   score=5,
                   workload=1,
                   difficulty=1,
                   review_text="Sykt lett",
                   full_name="PU PUsen",
                   study_programme="MTDT"),
            Review(course_code="TMA4100",
                   user_email="*****@*****.**",
                   score=4,
                   workload=1,
                   difficulty=2,
                   review_text="Morn du",
                   full_name="Mons Bertilsen",
                   study_programme="MTHEI"),
            Review(course_code="EXPH0004",
                   user_email="*****@*****.**",
                   score=1,
                   workload=5,
                   difficulty=2,
                   review_text="Meget filosofisk",
                   full_name="Erasmus Montanus",
                   study_programme="MTDT"),
        ]
        for r in reviews:
            r.save()
Beispiel #9
0
 def setUp(self):
     UserAuth(expiring_token="valid_token", access_token="valid_token", user_email="*****@*****.**").save()