Skip to content

Commit

Permalink
updated some tests maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
vilnor committed May 24, 2024
1 parent 75ba674 commit 993ad8a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 5 additions & 1 deletion integration_tests/backend/test_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)",
Expand All @@ -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)",
Expand Down
12 changes: 12 additions & 0 deletions integration_tests/backend/test_exams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions integration_tests/backend/test_full_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,19 @@ 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)
response = requests.post(self.host() + '/courses', json={**course, "userId": self.USER_ID})
self.assertEqual(201, response.status_code)

# Check the course params set correctly
Expand All @@ -106,7 +117,7 @@ def test_full_1(self):
}

# Create the exam
response = requests.post(self.host() + '/exams', json=exam)
response = requests.post(self.host() + '/exams', json={**exam, "userId": self.USER_ID})
self.assertEqual(201, response.status_code)
# Testing examId returned and is a valid int
examId = response.json()['examId']
Expand Down

0 comments on commit 993ad8a

Please sign in to comment.