def test_get_reviews_from_db_invalid_offset(self): # Not number, and larger than num_reviews req = self.rf.get("/review/get/?courseCode=TMA4100&offset=abc", HTTP_AUTHORIZATION="valid_token") with self.assertRaises(ValueError): get_reviews_from_db(req) req = self.rf.get("/review/get/?courseCode=TMA4100&offset=10", HTTP_AUTHORIZATION="valid_token") with self.assertRaises(ValueError): get_reviews_from_db(req)
def test_get_reviews_from_db_invalid_token(self): # Invalid token provided req = self.rf.get("/review/get/?courseCode=TMA4100", HTTP_AUTHORIZATION="invalid_token") with self.assertRaises(ValueError): get_reviews_from_db(req) req = self.rf.get( "/review/get/?courseCode=TMA4100&showMyProgramme=true", HTTP_AUTHORIZATION="invalid_token") with self.assertRaises(ValueError): get_reviews_from_db(req)
def test_get_reviews_from_db_valid_request(self): # Check correct count and number of reviews returned req = self.rf.get("/review/get/?courseCode=TMA4100&n=2", HTTP_AUTHORIZATION="valid_token") res = get_reviews_from_db(req) self.assertEqual(res["count"], 7) self.assertEqual(len(res["data"]), 2) req = self.rf.get("/review/get/?courseCode=TMA4100", HTTP_AUTHORIZATION="valid_token") res = get_reviews_from_db(req) self.assertEqual(res["count"], 7) self.assertEqual(len(res["data"]), 7)
def test_get_reviews_from_db_no_reviews_for_course(self): # Check count = 0 req = self.rf.get("/review/get/?courseCode=TDT4136", HTTP_AUTHORIZATION="valid_token") res = get_reviews_from_db(req) self.assertEqual(res["count"], 0) self.assertFalse(res["data"])
def test_get_reviews_from_db_valid_request_sorting(self): # The user's own review is the first review req = self.rf.get("/review/get/?courseCode=TMA4100&n=2", HTTP_AUTHORIZATION="valid_token") res = get_reviews_from_db(req) self.assertEqual(res["data"][0]["full_name"], "Test Testesen")
def test_get_reviews_from_db_invalid_n(self): # N not a number req = self.rf.get("/review/get/?courseCode=TMA4100&n=abc", HTTP_AUTHORIZATION="valid_token") with self.assertRaises(ValueError): get_reviews_from_db(req)
def test_get_reviews_from_db_no_token(self): # No expiring token provided req = self.rf.get("/review/get/?courseCode=TMA4100") with self.assertRaises(KeyError): get_reviews_from_db(req)
def test_get_reviews_from_db_no_course_code(self): # No course code argument passed req = self.rf.get("/review/get/?n=25&offset=10", HTTP_AUTHORIZATION="valid_token") with self.assertRaises(ValueError): get_reviews_from_db(req)
def test_get_reviews_from_db_invalid_course_code(self): # Course code not in Course db req = self.rf.get("/review/get/?courseCode=TMA4900", HTTP_AUTHORIZATION="valid_token") with self.assertRaises(ValueError): get_reviews_from_db(req)