-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa2a7b2
commit 3376aa2
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
backend/pigeonhole/tests/test_views/test_complete/admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from django.test import TestCase | ||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
|
||
from backend.pigeonhole.apps.courses.models import Course | ||
from backend.pigeonhole.apps.projects.models import Project | ||
from backend.pigeonhole.apps.users.models import User | ||
from backend.pigeonhole.apps.submissions.models import Submission | ||
|
||
ROUTES_PREFIX = '/courses/' | ||
|
||
|
||
class CompleteTestAdmin(TestCase): | ||
def setUp(self): | ||
self.client = APIClient() | ||
|
||
# Create a teacher user | ||
self.teacher = User.objects.create( | ||
username="teacher_username", | ||
email="teacher@gmail.com", | ||
first_name="Teacher", | ||
last_name="LastName", | ||
role=2 # Teacher role | ||
) | ||
|
||
# Create a student user | ||
self.student = User.objects.create( | ||
username="student_username", | ||
email="student@gmail.com", | ||
first_name="Student", | ||
last_name="LastName", | ||
role=3 # Student role | ||
) | ||
|
||
# Authenticate the teacher user | ||
self.client.force_authenticate(self.teacher) | ||
|
||
self.course = Course.objects.create( | ||
name="Test Course", | ||
description="Test Course Description", | ||
) | ||
|
||
def test_create_course(self): | ||
# Use the teacher to create the course | ||
response = self.client.post( | ||
ROUTES_PREFIX, | ||
{ | ||
"name": "Test Course 2", | ||
"description": "Test Course 2 Description", | ||
}, | ||
format='json' | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(Course.objects.count(), 2) | ||
self.assertEqual(Course.objects.get(course_id=2).name, "Test Course 2") | ||
|
||
def test_create_project(self): | ||
# Use the teacher to create the project for the course | ||
response = self.client.post( | ||
ROUTES_PREFIX + f'{self.course.course_id}/projects/', | ||
{ | ||
"name": "Test Project", | ||
"description": "Test Project Description", | ||
"course_id": self.course.course_id | ||
}, | ||
format='json' | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(Project.objects.count(), 1) | ||
self.assertEqual(Project.objects.get(project_id=1).name, "Test Project") | ||
|
||
def test_create_submission(self): | ||
# Authenticate the student user | ||
self.client.force_authenticate(self.student) | ||
|
||
# Use the student to create the submission for the project | ||
response = self.client.post( | ||
ROUTES_PREFIX + f'{self.course.course_id}/projects/1/submissions/', | ||
{ | ||
"project_id": 1, | ||
"student_id": self.student.id, # Use the student's id | ||
"submission": "Test Submission", | ||
}, | ||
format='json' | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(Submission.objects.count(), 1) | ||
self.assertEqual(Submission.objects.get(submission_id=1).submission, "Test Submission") | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.