Skip to content

Commit

Permalink
layout fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PJDeSmijter committed Mar 12, 2024
1 parent cba6b28 commit 88a52a1
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion backend/pigeonhole/apps/groups/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core.exceptions import ValidationError
from django.db import models
from rest_framework import serializers
from django.core.exceptions import ValidationError

from backend.pigeonhole.apps.projects.models import Project
from backend.pigeonhole.apps.users.models import User
Expand Down
1 change: 1 addition & 0 deletions backend/pigeonhole/apps/groups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from backend.pigeonhole.apps.groups.models import Group, GroupSerializer
from backend.pigeonhole.apps.projects.models import Project


# TODO tests for score/max_score


Expand Down
2 changes: 1 addition & 1 deletion backend/pigeonhole/apps/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class Test(models.Model):
str(project_id) + '/' + str(test_nr), null=True, blank=False,
max_length=255)

objects = models.Manager()
objects = models.Manager()
7 changes: 4 additions & 3 deletions backend/pigeonhole/apps/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from .models import Project, ProjectSerializer, Course
from backend.pigeonhole.apps.groups.models import Group
from .models import Project, ProjectSerializer, Course
from .permissions import CanAccessProject


# TODO hier nog zorgen als een project niet visible is, dat de students het niet kunnen zien.
# TODO tests for visibility and deadline

Expand All @@ -34,10 +35,10 @@ def create(self, request, *args, **kwargs):

serializer = ProjectSerializer(data=request.data)
if serializer.is_valid():
project = serializer.save() # Save the project and get the instance
project = serializer.save() # Save the project and get the instance
# make NUMBER OF GROUP groups
for i in range(serializer.validated_data['number_of_groups']):
group = Group.objects.create(group_nr=i+1, project_id=project) # Assign the Project instance
group = Group.objects.create(group_nr=i + 1, project_id=project) # Assign the Project instance
group.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
Expand Down
2 changes: 1 addition & 1 deletion backend/pigeonhole/apps/submissions/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db import models
from rest_framework import serializers
from django.core.exceptions import ValidationError

from backend.pigeonhole.apps.groups.models import Group

Expand Down Expand Up @@ -31,6 +30,7 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields
self.submission_nr = max_submission_nr + 1
super().save(force_insert=force_insert, force_update=force_update, using=using, update_fields=update_fields)


class SubmissionsSerializer(serializers.ModelSerializer):
class Meta:
model = Submissions
Expand Down
2 changes: 1 addition & 1 deletion backend/pigeonhole/tests/test_models/test_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUp(self):
last_name="Piggy",
role=3
)

# Create course
course = Course.objects.create(name="Math", description="Mathematics")
teacher.course.add(course)
Expand Down
2 changes: 1 addition & 1 deletion backend/pigeonhole/tests/test_models/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
last_name="The Frog",
role=2
)

# Create student user
student = User.objects.create(
id=2,
Expand Down
14 changes: 5 additions & 9 deletions backend/pigeonhole/tests/test_models/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setUp(self):
last_name="The Frog",
role=2
)

# Create student user
User.objects.create(
id=2,
Expand All @@ -33,15 +33,15 @@ def test_student_fields(self):
self.assertEqual(student[0].first_name, "Kermit")
self.assertEqual(student[0].last_name, "The Frog")
self.assertEqual(student[0].role, 2)

def test_teacher_fields(self):
teacher = User.objects.get(id=2),
self.assertEqual(teacher[0].username, "student_username")
self.assertEqual(teacher[0].email, "[email protected]"),
self.assertEqual(teacher[0].first_name, "Miss")
self.assertEqual(teacher[0].last_name, "Piggy")
self.assertEqual(teacher[0].role, 3)

def test_user_name_length_validation(self):
with self.assertRaises(Exception):
User.objects.create(
Expand All @@ -51,7 +51,7 @@ def test_user_name_length_validation(self):
last_name="Piggy",
role=3
)

# TODO
def test_user_correct_email(self):
with self.assertRaises(Exception):
Expand All @@ -62,7 +62,7 @@ def test_user_correct_email(self):
last_name="Piggy",
role=3
)

def test_user_role_validation(self):
with self.assertRaises(Exception):
User.objects.create(
Expand All @@ -72,7 +72,3 @@ def test_user_role_validation(self):
last_name="Piggy",
role=4
)




4 changes: 1 addition & 3 deletions backend/pigeonhole/tests/test_views/test_complete/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUp(self):
last_name="LastName",
role=2 # Teacher role
)

# Create a student user
self.student = User.objects.create(
username="student_username",
Expand Down Expand Up @@ -86,5 +86,3 @@ def test_create_submission(self):
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")


Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_create_project(self):
# Check that the number of projects has increased by 1
# This assumes that there was already one project before this test
self.assertEqual(Project.objects.count(), 2)

# test whether 4 group objects are created
self.assertEqual(Group.objects.count(), 4)

Expand All @@ -71,7 +71,6 @@ def test_create_project(self):
# Check that the name of the newly created project is correct
self.assertEqual(new_project.name, "Test Project 2")


def test_retrieve_project(self):
response = self.client.get(
API_ENDPOINT + f'{self.course.course_id}/projects/{self.project.project_id}/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_retrieve_invalid_project(self):
API_ENDPOINT + f'{self.course.course_id}/projects/100/'
)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_update_project_invalid_project(self):
response = self.client.patch(
API_ENDPOINT + f'{self.course.course_id}/projects/100/',
Expand All @@ -174,7 +174,7 @@ def test_update_project_invalid_project(self):
format='json'
)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_delete_project_invalid_project(self):
response = self.client.delete(
API_ENDPOINT + f'{self.course.course_id}/projects/100/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_partial_update_project_unauthenticated(self):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

# tests with an invalid course

def test_create_project_invalid_course_unauthenticated(self):
response = self.client.post(
API_ENDPOINT + f'100/projects/',
Expand Down

0 comments on commit 88a52a1

Please sign in to comment.