Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
PJDeSmijter committed Mar 2, 2024
1 parent 9187b93 commit 18e78e7
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 29 deletions.
15 changes: 13 additions & 2 deletions backend/pigeonhole/tests/test_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@

# python3 manage.py test backend/


class CourseTestCase(TestCase):
def setUp(self):
# Create teacher user
teacher_user = User.objects.create_user(username="teacher_username", email="teacher@gmail.com", first_name="Kermit", last_name="The Frog")
teacher_user = User.objects.create_user(
username="teacher_username",
email="teacher@gmail.com",
first_name="Kermit",
last_name="The Frog"
)
# Create student user
student_user = User.objects.create_user(username="student_username", email="student@gmail.com", first_name="Miss", last_name="Piggy")
student_user = User.objects.create_user(
username="student_username",
email="student@gmail.com",
first_name="Miss",
last_name="Piggy"
)

# Create teacher and student using the created users
teacher = Teacher.objects.create(id=teacher_user)
Expand Down
44 changes: 33 additions & 11 deletions backend/pigeonhole/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@

# python3 manage.py test backend/


class ProjectTestCase(TestCase):
def setUp(self):
# Create teacher user
teacher_user = User.objects.create_user(username="teacher_username", email="teacher@gmail.com", first_name="Kermit", last_name="The Frog")
teacher_user = User.objects.create_user(
username="teacher_username",
email="teacher@gmail.com",
first_name="Kermit",
last_name="The Frog"
)
# Create student user
student_user = User.objects.create_user(username="student_username", email="student@gmail.com", first_name="Miss", last_name="Piggy")
student_user = User.objects.create_user(
username="student_username",
email="student@gmail.com",
first_name="Miss",
last_name="Piggy"
)

# Create teacher and student using the created users
teacher = Teacher.objects.create(id=teacher_user)
Expand All @@ -22,7 +33,12 @@ def setUp(self):
student.course.add(course)

# Create project
Project.objects.create(name="Project", course_id=course, description="Project Description", deadline="2021-12-12 12:12:12")
Project.objects.create(
name="Project",
course_id=course,
description="Project Description",
deadline="2021-12-12 12:12:12"
)

def test_project_course_relation(self):
project = Project.objects.get(name="Project")
Expand All @@ -41,15 +57,26 @@ def test_project_student_relation(self):

def test_course_name_length_validation(self):
with self.assertRaises(Exception):
Course.objects.create(name="A" * 300, description="Mock")
Course.objects.create(
name="A" * 300,
description="Mock"
)

def test_create_project_without_course(self):
with self.assertRaises(Exception):
Project.objects.create(name="Project", description="Project Description", deadline="2021-12-12 12:12:12")
Project.objects.create(
name="Project",
description="Project Description",
deadline="2021-12-12 12:12:12"
)

def test_create_project_without_deadline(self):
with self.assertRaises(Exception):
Project.objects.create(name="Project", course_id=Course.objects.get(name="Math"), description="Project Description")
Project.objects.create(
name="Project",
course_id=Course.objects.get(name="Math"),
description="Project Description"
)

def test_update_and_delete_project(self):
project = Project.objects.get(name="Project")
Expand All @@ -61,8 +88,3 @@ def test_update_and_delete_project(self):
project.delete()
with self.assertRaises(Project.DoesNotExist):
Project.objects.get(name="Project 2")





54 changes: 43 additions & 11 deletions backend/pigeonhole/tests/test_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@

# python3 manage.py test backend/


class SubmissionTestCase(TestCase):
def setUp(self):
# Create teacher user
teacher_user = User.objects.create_user(username="teacher_username", email="teacher@gmail.com", first_name="Kermit", last_name="The Frog")
# Create teacher user
teacher_user = User.objects.create_user(
username="teacher_username",
email="teacher@gmail.com",
first_name="Kermit",
last_name="The Frog"
)
# Create student user
student_user = User.objects.create_user(username="student_username", email="student@gmail.com", first_name="Miss", last_name="Piggy")
student_user = User.objects.create_user(
username="student_username",
email="student@gmail.com",
first_name="Miss",
last_name="Piggy"
)

# Create teacher and student using the created users
teacher = Teacher.objects.create(id=teacher_user)
Expand All @@ -23,28 +34,49 @@ def setUp(self):
student.course.add(course)

# Create project
Project.objects.create(name="Project", course_id=course, description="Project Description", deadline="2021-12-12 12:12:12")
project = Project.objects.create(
name="Project",
course_id=course,
description="Project Description",
deadline="2021-12-12 12:12:12"
)

# Create submission
Submissions.objects.create(student_id=student, project_id=Project.objects.get(name="Project"))
Submissions.objects.create(
student_id=student,
project_id=project
)

def test_submission_student_relation(self):
submission = Submissions.objects.get(student_id__id__email="student@gmail.com")
submission = Submissions.objects.get(
student_id__id__email="student@gmail.com"
)
student = Student.objects.get(id__email="student@gmail.com")
self.assertEqual(submission.student_id, student)

def test_submission_project_relation(self):
submission = Submissions.objects.get(student_id__id__email="student@gmail.com")
submission = Submissions.objects.get(
student_id__id__email="student@gmail.com"
)
project = Project.objects.get(name="Project")
self.assertEqual(submission.project_id, project)

def update_and_delete_submission(self):
submission = Submissions.objects.get(student_id__id__email="student@gmail.com", project_id__name="Project")
submission = Submissions.objects.get(
student_id__id__email="student@gmail.com",
project_id__name="Project"
)
submission.grade = 10
submission.save()
submission = Submissions.objects.get(student_id__id__email="student@gmail.Com", project_id__name="Project")
submission = Submissions.objects.get(
student_id__id__email="student@gmail.Com",
project_id__name="Project"
)
self.assertEqual(submission.grade, 10)

submission.delete()
with self.assertRaises(Submissions.DoesNotExist):
Submissions.objects.get(student_id__id__email="student@gmail.com", project=Project.objects.get(name="Project"))
Submissions.objects.get(
student_id__id__email="student@gmail.com",
project=Project.objects.get(name="Project")
)
19 changes: 14 additions & 5 deletions backend/pigeonhole/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
class UserTestCase(TestCase):
def setUp(self):
# Create teacher user
teacher_user = User.objects.create_user(username="teacher_username", email="teacher@gmail.com", first_name="Kermit", last_name="The Frog")
teacher_user = User.objects.create_user(
username="teacher_username",
email="teacher@gmail.com",
first_name="Kermit",
last_name="The Frog"
)
# Create student user
student_user = User.objects.create_user(username="student_username", email="student@gmail.com", first_name="Miss", last_name="Piggy")
student_user = User.objects.create_user(
username="student_username",
email="student@gmail.com",
first_name="Miss",
last_name="Piggy"
)

# Create teacher and student using the created users
Teacher.objects.create(id=teacher_user)
Expand Down Expand Up @@ -52,12 +62,11 @@ def test_teacher(self):
teacher.delete()
with self.assertRaises(Teacher.DoesNotExist):
Teacher.objects.get(id__email="teacher@gmail.com")

def test_create_student_without_user(self):
with self.assertRaises(Exception):
Student.objects.create(number=1234)

def test_create_teacher_without_user(self):
with self.assertRaises(Exception):
Teacher.objects.create(is_admin=True, is_assistent=True)

0 comments on commit 18e78e7

Please sign in to comment.