def test_validate_review_post_request_nonexistent_course_code(self): # Course code not in reviewable courses test_data = {"courseCode": "TDT4290", "score": 1, "workload": 1, "difficulty": 1, "reviewText": "Lorem ipsum"} with self.assertRaises(ValueError): validate_review_post_request(test_data, ["TDT4120", "TMA4100", "EXPH0600", "EXFAC1002"], "*****@*****.**")
def test_validate_review_post_request_missing_values(self): # Missing attributes test_data = {"courseCode": "TDT4290", "score": 1, "workload": 1, "difficulty": 1, "reviewText": "Lorem ipsum"} for key in test_data.keys(): data_subset = {k: test_data[k] for k in filter(lambda k: k != key, test_data.keys())} with self.assertRaises(KeyError): validate_review_post_request(data_subset, [], "")
def test_validate_review_post_request_review_exists(self): # Review exists already test_data = {"courseCode": "TDT4290", "score": 1, "workload": 1, "difficulty": 1, "reviewText": "Lorem ipsum"} test_review = Review(user_email="*****@*****.**", course_code="TDT4290", score=4, workload=5, difficulty=3, review_text="Test review", full_name="Test Testesen", study_programme="MTDT") test_review.save() with self.assertRaises(ValueError): validate_review_post_request(test_data, ["TDT4290", "TMA4125"], "*****@*****.**")
def test_validate_review_post_request_wrong_workload(self): test_data = {"courseCode": "TDT4290", "score": 1, "workload": 1, "difficulty": 1, "reviewText": "Lorem ipsum"} # Wrong workload workloads = [-1253, 3, float("inf"), "abasd"] for elem in workloads: data = {k: test_data[k] for k in test_data.keys()} data["workload"] = elem with self.assertRaises(ValueError): validate_review_post_request(data, ["TDT4290", "TMA4125"], "*****@*****.**")
def test_validate_review_post_request_valid_review(self): test_data = {"courseCode": "TDT4290", "score": 1, "workload": 1, "difficulty": 1, "reviewText": "Lorem ipsum"} # Valid request self.assertIsNone(validate_review_post_request(test_data, ["TDT4290", "TMA4125"], "*****@*****.**"))
def test_validate_review_post_request_no_or_wrong_attributes(self): # No attributes and wrong attributes with self.assertRaises(KeyError): validate_review_post_request({}, [], "") with self.assertRaises(KeyError): validate_review_post_request( {"course_code": "TDT4120", "score": 1, "workload": 1, "difficulty": 1, "reviewText": "Lorem ipsum"}, [], "") with self.assertRaises(KeyError): validate_review_post_request({"test": "should raise KeyError"}, [], "")