From 5cb75743127b8cd7a9f86ad79daa915a328e41b7 Mon Sep 17 00:00:00 2001 From: liv Date: Fri, 24 May 2024 21:42:15 +1000 Subject: [PATCH] updated some tests maybe --- integration_tests/backend/test_courses.py | 6 +++++- integration_tests/backend/test_exams.py | 12 ++++++++++++ integration_tests/backend/test_full_suite.py | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/integration_tests/backend/test_courses.py b/integration_tests/backend/test_courses.py index 28b4e7d..1d04e1f 100644 --- a/integration_tests/backend/test_courses.py +++ b/integration_tests/backend/test_courses.py @@ -76,7 +76,8 @@ def setUp(self): # Creates a new user userData = { - "userId": self.USER_ID + "userId": self.USER_ID, + "role": 1 # admin role } newUser = self.User(**userData) @@ -118,6 +119,7 @@ def test_course_post(self): Checks for the correct response message """ courseData = { + "userId": self.USER_ID, "courseCode": "COMP3506", "courseName": "Data Structures and Algorithms", "courseDescription": "Doing some DSA", @@ -148,6 +150,7 @@ def test_course_post_null_coursecode(self): Checks for the correct response message """ courseData = { + "userId": self.USER_ID, "courseCode": "", "courseName": "Software Architecture", "courseDescription": "Doing some software architecture stuff with Richard and Evan (my bestie)", @@ -173,6 +176,7 @@ def test_course_post_duplicate_coursecode(self): Checks for the correct response message """ courseData = { + "userId": self.USER_ID, "courseCode": "CSSE6400", "courseName": "Software Architecture", "courseDescription": "Doing some software architecture stuff with Richard and Evan (my bestie)", diff --git a/integration_tests/backend/test_exams.py b/integration_tests/backend/test_exams.py index 280ac8b..f0267d7 100644 --- a/integration_tests/backend/test_exams.py +++ b/integration_tests/backend/test_exams.py @@ -30,6 +30,15 @@ def setUp(self): self.COMMENT_PNG = None self.PARENT_COMMENT_ID = None + # Creates a new user + userData = { + "userId": self.USER_ID, + "role": 1 # admin role + } + + newUser = self.User(**userData) + self.session.add(newUser) + # Create course courseData = { "courseCode": self.COURSE_CODE, @@ -94,6 +103,7 @@ def test_exam_post(self): Checks for the correct response message """ body = { + "userId": self.USER_ID, "examYear": self.EXAM_YEAR, "examSemester": self.EXAM_SEMESTER, "examType": self.EXAM_TYPE, @@ -118,6 +128,7 @@ def test_exam_post_missing_courseCode(self): Checks for the correct response message """ body = { + "userId": self.USER_ID, "examYear": self.EXAM_YEAR, "examSemester": self.EXAM_SEMESTER, "examType": self.EXAM_TYPE @@ -140,6 +151,7 @@ def test_exam_post_course_not_found(self): Checks for the correct response message """ body = { + "userId": self.USER_ID, "examYear": self.EXAM_YEAR, "examSemester": self.EXAM_SEMESTER, "examType": self.EXAM_TYPE, diff --git a/integration_tests/backend/test_full_suite.py b/integration_tests/backend/test_full_suite.py index f470838..1b1fa55 100644 --- a/integration_tests/backend/test_full_suite.py +++ b/integration_tests/backend/test_full_suite.py @@ -62,6 +62,7 @@ def test_full_1(self): """ course = { + "userId": self.USER_ID, "courseCode": self.COURSE_CODE, "courseName": self.COURSE_NAME, "courseDescription": self.COURSE_DESCRIPTION, @@ -78,6 +79,17 @@ def test_full_1(self): response = requests.post(self.host() + '/users', json=user) self.assertEqual(201, response.status_code) + # Give them admin perms (has to be done manually for ~security~ reasons) + created_user = self.session.query(self.User).filter_by( + userId=str(self.USER_ID)).first() + created_user.role = 1 + self.session.commit() + + # Check they have the correct role + response = requests.get(self.host() + '/users/' + str(self.USER_ID) + '/role') + self.assertEqual(200, response.status_code) + self.assertEqual(1, response.json()) + # Create a course response = requests.post(self.host() + '/courses', json=course) self.assertEqual(201, response.status_code) @@ -99,6 +111,7 @@ def test_full_1(self): # Create an exam for the course exam = { + "userId": self.USER_ID, "examYear": self.EXAM_YEAR, "examSemester": self.EXAM_SEMESTER, "examType": self.EXAM_TYPE,