From 8b9ea34277f0a0a63a173e9e8dccffe19d635568 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Tue, 12 Mar 2024 08:44:13 +0100 Subject: [PATCH 01/14] chore: startup structure_checks add --- backend/api/serializers/project_serializer.py | 26 +++++++++++++++---- backend/api/views/project_view.py | 20 ++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/backend/api/serializers/project_serializer.py b/backend/api/serializers/project_serializer.py index dd564a33..3b2d6deb 100644 --- a/backend/api/serializers/project_serializer.py +++ b/backend/api/serializers/project_serializer.py @@ -5,6 +5,7 @@ from rest_framework.exceptions import ValidationError from api.models.submission import Submission, SubmissionFile from api.serializers.submission_serializer import SubmissionSerializer +from api.serializers.checks_serializer import StructureCheckSerializer class ProjectSerializer(serializers.ModelSerializer): @@ -52,11 +53,6 @@ class TeacherCreateGroupSerializer(serializers.Serializer): class SubmissionAddSerializer(SubmissionSerializer): def validate(self, data): - """ - # The validator needs the project context. - if "project" not in self.context: - raise ValidationError(gettext("project.error.context")) - """ group: Group = self.context["group"] project: Project = group.project @@ -72,3 +68,23 @@ def validate(self, data): raise ValidationError(gettext("project.error.submission.archived_project")) return data + + +class StructureCheckAddSerializer(StructureCheckSerializer): + def validate(self, data): + + project: Project = self.context["project"] + + """ + # Check if the project's deadline is not passed. + if project.deadline_passed(): + raise ValidationError(gettext("project.error.submission.past_project")) + + if not project.is_visible(): + raise ValidationError(gettext("project.error.submission.non_visible_project")) + + if project.is_archived(): + raise ValidationError(gettext("project.error.submission.archived_project")) + """ + + return data diff --git a/backend/api/views/project_view.py b/backend/api/views/project_view.py index 4365b78c..e2116612 100644 --- a/backend/api/views/project_view.py +++ b/backend/api/views/project_view.py @@ -9,8 +9,10 @@ from ..models.project import Project from ..serializers.checks_serializer import StructureCheckSerializer, ExtraCheckSerializer from api.serializers.project_serializer import ProjectSerializer, TeacherCreateGroupSerializer +from api.serializers.project_serializer import StructureCheckAddSerializer from api.serializers.group_serializer import GroupSerializer from api.serializers.submission_serializer import SubmissionSerializer +from rest_framework.request import Request class ProjectViewSet(CreateModelMixin, @@ -91,6 +93,24 @@ def structure_checks(self, request, **_): ) return Response(serializer.data) + @structure_checks.mapping.post + def _add_structure_check(self, request: Request, **_): + """Add an structure_check to the project""" + + project: Project = self.get_object() + + # Add submission to course + serializer = StructureCheckAddSerializer( + data=request.data, context={"project": project, "request": request} + ) + + if serializer.is_valid(raise_exception=True): + serializer.save(project=project) + + return Response({ + "message": gettext("project.success.structure_check.add") + }) + @action(detail=True, methods=["get"]) def extra_checks(self, request, **_): """Returns the extra checks for the given project""" From 4b4fb813e0f220b848863d98730e530a87972bd9 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Wed, 13 Mar 2024 15:03:16 +0100 Subject: [PATCH 02/14] chore: add endpoint to add structure checks --- backend/api/serializers/checks_serializer.py | 4 ++-- backend/api/serializers/project_serializer.py | 19 ++++++++++++++++++- backend/api/views/project_view.py | 9 ++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/backend/api/serializers/checks_serializer.py b/backend/api/serializers/checks_serializer.py index 4a876809..082a7da9 100644 --- a/backend/api/serializers/checks_serializer.py +++ b/backend/api/serializers/checks_serializer.py @@ -16,9 +16,9 @@ class StructureCheckSerializer(serializers.ModelSerializer): read_only=True ) - obligated_extensions = FileExtensionSerializer(many=True) + obligated_extensions = FileExtensionSerializer(many=True, required=False, default=[], read_only=True) - blocked_extensions = FileExtensionSerializer(many=True) + blocked_extensions = FileExtensionSerializer(many=True, required=False, default=[], read_only=True) class Meta: model = StructureCheck diff --git a/backend/api/serializers/project_serializer.py b/backend/api/serializers/project_serializer.py index 3b2d6deb..d42688c4 100644 --- a/backend/api/serializers/project_serializer.py +++ b/backend/api/serializers/project_serializer.py @@ -4,8 +4,10 @@ from api.models.group import Group from rest_framework.exceptions import ValidationError from api.models.submission import Submission, SubmissionFile +from api.models.checks import FileExtension from api.serializers.submission_serializer import SubmissionSerializer from api.serializers.checks_serializer import StructureCheckSerializer +from rest_framework.request import Request class ProjectSerializer(serializers.ModelSerializer): @@ -72,9 +74,24 @@ def validate(self, data): class StructureCheckAddSerializer(StructureCheckSerializer): def validate(self, data): - project: Project = self.context["project"] + obl_ext = set() + for ext in self.context["obligated"]: + extensie, _ = FileExtension.objects.get_or_create( + extension=ext + ) + obl_ext.add(extensie) + data["obligated_extensions"] = obl_ext + + block_ext = set() + for ext in self.context["blocked"]: + extensie, _ = FileExtension.objects.get_or_create( + extension=ext + ) + block_ext.add(extensie) + data["blocked_extensions"] = block_ext + """ # Check if the project's deadline is not passed. if project.deadline_passed(): diff --git a/backend/api/views/project_view.py b/backend/api/views/project_view.py index e2116612..fb9f01ad 100644 --- a/backend/api/views/project_view.py +++ b/backend/api/views/project_view.py @@ -94,6 +94,7 @@ def structure_checks(self, request, **_): return Response(serializer.data) @structure_checks.mapping.post + @structure_checks.mapping.put def _add_structure_check(self, request: Request, **_): """Add an structure_check to the project""" @@ -101,7 +102,13 @@ def _add_structure_check(self, request: Request, **_): # Add submission to course serializer = StructureCheckAddSerializer( - data=request.data, context={"project": project, "request": request} + data=request.data, + context={ + "project": project, + "request": request, + "obligated": request.data.getlist('obligated_extensions'), + "blocked": request.data.getlist('blocked_extensions') + } ) if serializer.is_valid(raise_exception=True): From a5ba61f8e6bb91d09cef20f7d6afe7153e60cb4f Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Wed, 13 Mar 2024 15:18:48 +0100 Subject: [PATCH 03/14] chore: finished structure_checks add endpoint --- backend/api/serializers/project_serializer.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/backend/api/serializers/project_serializer.py b/backend/api/serializers/project_serializer.py index d42688c4..4db1fb3e 100644 --- a/backend/api/serializers/project_serializer.py +++ b/backend/api/serializers/project_serializer.py @@ -75,6 +75,8 @@ def validate(self, data): class StructureCheckAddSerializer(StructureCheckSerializer): def validate(self, data): project: Project = self.context["project"] + if project.structure_checks.filter(name=data["name"]).count(): + raise ValidationError(gettext("project.error.structure_checks.already_existing")) obl_ext = set() for ext in self.context["obligated"]: @@ -89,19 +91,9 @@ def validate(self, data): extensie, _ = FileExtension.objects.get_or_create( extension=ext ) + if extensie in obl_ext: + raise ValidationError(gettext("project.error.structure_checks.extension_blocked_and_obligated")) block_ext.add(extensie) data["blocked_extensions"] = block_ext - """ - # Check if the project's deadline is not passed. - if project.deadline_passed(): - raise ValidationError(gettext("project.error.submission.past_project")) - - if not project.is_visible(): - raise ValidationError(gettext("project.error.submission.non_visible_project")) - - if project.is_archived(): - raise ValidationError(gettext("project.error.submission.archived_project")) - """ - return data From e8e6fa0d32aff7e07db7a70c750be6539d9e86f2 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 08:00:28 +0100 Subject: [PATCH 04/14] chore: started endpoint for deleting structure_checks of a project but doesnt work --- backend/api/serializers/project_serializer.py | 19 ++++++++++++- backend/api/views/project_view.py | 27 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/backend/api/serializers/project_serializer.py b/backend/api/serializers/project_serializer.py index 4db1fb3e..bd42dd4c 100644 --- a/backend/api/serializers/project_serializer.py +++ b/backend/api/serializers/project_serializer.py @@ -4,7 +4,7 @@ from api.models.group import Group from rest_framework.exceptions import ValidationError from api.models.submission import Submission, SubmissionFile -from api.models.checks import FileExtension +from api.models.checks import FileExtension, StructureCheck from api.serializers.submission_serializer import SubmissionSerializer from api.serializers.checks_serializer import StructureCheckSerializer from rest_framework.request import Request @@ -97,3 +97,20 @@ def validate(self, data): data["blocked_extensions"] = block_ext return data + + +class StructureCheckDeleteSerializer(StructureCheckSerializer): + def validate(self, data): + if "project" not in self.context: + raise ValidationError(gettext("project.error.context")) + + project: Project = self.context["project"] + + # Get the struture_check + structureCheck: StructureCheck = data["structure_check_id"] + + # Make sure the struture_check was in the project + if True or not project.structure_checks.filter(id=structureCheck.id).exists(): + raise ValidationError(gettext("struture_check.errors.not_present")) + + return data diff --git a/backend/api/views/project_view.py b/backend/api/views/project_view.py index fb9f01ad..0735a7d1 100644 --- a/backend/api/views/project_view.py +++ b/backend/api/views/project_view.py @@ -7,9 +7,10 @@ from api.permissions.project_permissions import ProjectGroupPermission, ProjectPermission from api.models.group import Group from ..models.project import Project +from api.models.checks import StructureCheck from ..serializers.checks_serializer import StructureCheckSerializer, ExtraCheckSerializer from api.serializers.project_serializer import ProjectSerializer, TeacherCreateGroupSerializer -from api.serializers.project_serializer import StructureCheckAddSerializer +from api.serializers.project_serializer import StructureCheckAddSerializer, StructureCheckDeleteSerializer from api.serializers.group_serializer import GroupSerializer from api.serializers.submission_serializer import SubmissionSerializer from rest_framework.request import Request @@ -118,6 +119,30 @@ def _add_structure_check(self, request: Request, **_): "message": gettext("project.success.structure_check.add") }) + @structure_checks.mapping.delete + def _delete_structure_check(self, request: Request, **_): # TODO test + """Remove an structure_check to the project""" + + project: Project = self.get_object() + + # Add submission to course + serializer = StructureCheckDeleteSerializer( + data=request.data, + context={ + "project": project, + "request": request + } + ) + + if serializer.is_valid(raise_exception=True): + project.structure_checks.remove( + serializer.validated_data["structure_check_id"] + ) + + return Response({ + "message": gettext("project.success.structure_check.remove") + }) + @action(detail=True, methods=["get"]) def extra_checks(self, request, **_): """Returns the extra checks for the given project""" From a187908caf5ca0f35075d2d793afbedb3a5c6eb7 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 10:35:52 +0100 Subject: [PATCH 05/14] chore: moved data to backend folder and added development enviroment --- backend/api/serializers/project_serializer.py | 17 -------------- backend/api/views/project_view.py | 22 +----------------- .../data}/production/structures/empty.zip | Bin .../production/structures/mixed_template.zip | Bin .../structures/only_files_template.zip | Bin .../structures/only_folders_template.zip | Bin .../data}/production/structures/remake.zip | Bin .../data}/production/structures/root.zip | Bin .../production/structures/zip_struct1.zip | Bin .../data}/production/tests/mixed.zip | Bin .../data}/production/tests/only_files.zip | Bin .../data}/production/tests/only_folders.zip | Bin .../production/tests/test_zip1struct1.zip | Bin .../production/tests/test_zip2struct1.zip | Bin .../production/tests/test_zip3struct1.zip | Bin .../production/tests/test_zip4struct1.zip | Bin .../testing/structures/mixed_template.zip | Bin .../structures/only_files_template.zip | Bin .../structures/only_folders_template.zip | Bin .../data}/testing/structures/remake.zip | Bin .../data}/testing/structures/root.zip | Bin .../data}/testing/structures/zip_struct1.zip | Bin .../data}/testing/tests/mixed.zip | Bin .../data}/testing/tests/only_files.zip | Bin .../data}/testing/tests/only_folders.zip | Bin .../data}/testing/tests/test_zip1struct1.zip | Bin .../data}/testing/tests/test_zip2struct1.zip | Bin .../data}/testing/tests/test_zip3struct1.zip | Bin .../data}/testing/tests/test_zip4struct1.zip | Bin backend/ypovoli/settings.py | 2 +- 30 files changed, 2 insertions(+), 39 deletions(-) rename {data => backend/data}/production/structures/empty.zip (100%) rename {data => backend/data}/production/structures/mixed_template.zip (100%) rename {data => backend/data}/production/structures/only_files_template.zip (100%) rename {data => backend/data}/production/structures/only_folders_template.zip (100%) rename {data => backend/data}/production/structures/remake.zip (100%) rename {data => backend/data}/production/structures/root.zip (100%) rename {data => backend/data}/production/structures/zip_struct1.zip (100%) rename {data => backend/data}/production/tests/mixed.zip (100%) rename {data => backend/data}/production/tests/only_files.zip (100%) rename {data => backend/data}/production/tests/only_folders.zip (100%) rename {data => backend/data}/production/tests/test_zip1struct1.zip (100%) rename {data => backend/data}/production/tests/test_zip2struct1.zip (100%) rename {data => backend/data}/production/tests/test_zip3struct1.zip (100%) rename {data => backend/data}/production/tests/test_zip4struct1.zip (100%) rename {data => backend/data}/testing/structures/mixed_template.zip (100%) rename {data => backend/data}/testing/structures/only_files_template.zip (100%) rename {data => backend/data}/testing/structures/only_folders_template.zip (100%) rename {data => backend/data}/testing/structures/remake.zip (100%) rename {data => backend/data}/testing/structures/root.zip (100%) rename {data => backend/data}/testing/structures/zip_struct1.zip (100%) rename {data => backend/data}/testing/tests/mixed.zip (100%) rename {data => backend/data}/testing/tests/only_files.zip (100%) rename {data => backend/data}/testing/tests/only_folders.zip (100%) rename {data => backend/data}/testing/tests/test_zip1struct1.zip (100%) rename {data => backend/data}/testing/tests/test_zip2struct1.zip (100%) rename {data => backend/data}/testing/tests/test_zip3struct1.zip (100%) rename {data => backend/data}/testing/tests/test_zip4struct1.zip (100%) diff --git a/backend/api/serializers/project_serializer.py b/backend/api/serializers/project_serializer.py index cfdb73bb..47af0ed5 100644 --- a/backend/api/serializers/project_serializer.py +++ b/backend/api/serializers/project_serializer.py @@ -126,20 +126,3 @@ def validate(self, data): data["blocked_extensions"] = block_ext return data - - -class StructureCheckDeleteSerializer(StructureCheckSerializer): - def validate(self, data): - if "project" not in self.context: - raise ValidationError(gettext("project.error.context")) - - project: Project = self.context["project"] - - # Get the struture_check - structureCheck: StructureCheck = data["structure_check_id"] - - # Make sure the struture_check was in the project - if True or not project.structure_checks.filter(id=structureCheck.id).exists(): - raise ValidationError(gettext("struture_check.errors.not_present")) - - return data diff --git a/backend/api/views/project_view.py b/backend/api/views/project_view.py index 7776a493..cd5beeea 100644 --- a/backend/api/views/project_view.py +++ b/backend/api/views/project_view.py @@ -11,7 +11,7 @@ from api.models.checks import StructureCheck from ..serializers.checks_serializer import StructureCheckSerializer, ExtraCheckSerializer from api.serializers.project_serializer import ProjectSerializer, TeacherCreateGroupSerializer -from api.serializers.project_serializer import StructureCheckAddSerializer, StructureCheckDeleteSerializer, SubmissionStatusSerializer +from api.serializers.project_serializer import StructureCheckAddSerializer, SubmissionStatusSerializer from api.serializers.group_serializer import GroupSerializer from api.serializers.submission_serializer import SubmissionSerializer from rest_framework.request import Request @@ -120,26 +120,6 @@ def _add_structure_check(self, request: Request, **_): "message": gettext("project.success.structure_check.add") }) - @structure_checks.mapping.delete - def _delete_structure_check(self, request: Request, **_): # TODO test - """Remove an structure_check to the project""" - - project: Project = self.get_object() - - # Add submission to course - serializer = StructureCheckDeleteSerializer( - data=request.data, - context={ - "project": project, - "request": request - } - ) - - if serializer.is_valid(raise_exception=True): - project.structure_checks.remove( - serializer.validated_data["structure_check_id"] - ) - return Response({ "message": gettext("project.success.structure_check.remove") }) diff --git a/data/production/structures/empty.zip b/backend/data/production/structures/empty.zip similarity index 100% rename from data/production/structures/empty.zip rename to backend/data/production/structures/empty.zip diff --git a/data/production/structures/mixed_template.zip b/backend/data/production/structures/mixed_template.zip similarity index 100% rename from data/production/structures/mixed_template.zip rename to backend/data/production/structures/mixed_template.zip diff --git a/data/production/structures/only_files_template.zip b/backend/data/production/structures/only_files_template.zip similarity index 100% rename from data/production/structures/only_files_template.zip rename to backend/data/production/structures/only_files_template.zip diff --git a/data/production/structures/only_folders_template.zip b/backend/data/production/structures/only_folders_template.zip similarity index 100% rename from data/production/structures/only_folders_template.zip rename to backend/data/production/structures/only_folders_template.zip diff --git a/data/production/structures/remake.zip b/backend/data/production/structures/remake.zip similarity index 100% rename from data/production/structures/remake.zip rename to backend/data/production/structures/remake.zip diff --git a/data/production/structures/root.zip b/backend/data/production/structures/root.zip similarity index 100% rename from data/production/structures/root.zip rename to backend/data/production/structures/root.zip diff --git a/data/production/structures/zip_struct1.zip b/backend/data/production/structures/zip_struct1.zip similarity index 100% rename from data/production/structures/zip_struct1.zip rename to backend/data/production/structures/zip_struct1.zip diff --git a/data/production/tests/mixed.zip b/backend/data/production/tests/mixed.zip similarity index 100% rename from data/production/tests/mixed.zip rename to backend/data/production/tests/mixed.zip diff --git a/data/production/tests/only_files.zip b/backend/data/production/tests/only_files.zip similarity index 100% rename from data/production/tests/only_files.zip rename to backend/data/production/tests/only_files.zip diff --git a/data/production/tests/only_folders.zip b/backend/data/production/tests/only_folders.zip similarity index 100% rename from data/production/tests/only_folders.zip rename to backend/data/production/tests/only_folders.zip diff --git a/data/production/tests/test_zip1struct1.zip b/backend/data/production/tests/test_zip1struct1.zip similarity index 100% rename from data/production/tests/test_zip1struct1.zip rename to backend/data/production/tests/test_zip1struct1.zip diff --git a/data/production/tests/test_zip2struct1.zip b/backend/data/production/tests/test_zip2struct1.zip similarity index 100% rename from data/production/tests/test_zip2struct1.zip rename to backend/data/production/tests/test_zip2struct1.zip diff --git a/data/production/tests/test_zip3struct1.zip b/backend/data/production/tests/test_zip3struct1.zip similarity index 100% rename from data/production/tests/test_zip3struct1.zip rename to backend/data/production/tests/test_zip3struct1.zip diff --git a/data/production/tests/test_zip4struct1.zip b/backend/data/production/tests/test_zip4struct1.zip similarity index 100% rename from data/production/tests/test_zip4struct1.zip rename to backend/data/production/tests/test_zip4struct1.zip diff --git a/data/testing/structures/mixed_template.zip b/backend/data/testing/structures/mixed_template.zip similarity index 100% rename from data/testing/structures/mixed_template.zip rename to backend/data/testing/structures/mixed_template.zip diff --git a/data/testing/structures/only_files_template.zip b/backend/data/testing/structures/only_files_template.zip similarity index 100% rename from data/testing/structures/only_files_template.zip rename to backend/data/testing/structures/only_files_template.zip diff --git a/data/testing/structures/only_folders_template.zip b/backend/data/testing/structures/only_folders_template.zip similarity index 100% rename from data/testing/structures/only_folders_template.zip rename to backend/data/testing/structures/only_folders_template.zip diff --git a/data/testing/structures/remake.zip b/backend/data/testing/structures/remake.zip similarity index 100% rename from data/testing/structures/remake.zip rename to backend/data/testing/structures/remake.zip diff --git a/data/testing/structures/root.zip b/backend/data/testing/structures/root.zip similarity index 100% rename from data/testing/structures/root.zip rename to backend/data/testing/structures/root.zip diff --git a/data/testing/structures/zip_struct1.zip b/backend/data/testing/structures/zip_struct1.zip similarity index 100% rename from data/testing/structures/zip_struct1.zip rename to backend/data/testing/structures/zip_struct1.zip diff --git a/data/testing/tests/mixed.zip b/backend/data/testing/tests/mixed.zip similarity index 100% rename from data/testing/tests/mixed.zip rename to backend/data/testing/tests/mixed.zip diff --git a/data/testing/tests/only_files.zip b/backend/data/testing/tests/only_files.zip similarity index 100% rename from data/testing/tests/only_files.zip rename to backend/data/testing/tests/only_files.zip diff --git a/data/testing/tests/only_folders.zip b/backend/data/testing/tests/only_folders.zip similarity index 100% rename from data/testing/tests/only_folders.zip rename to backend/data/testing/tests/only_folders.zip diff --git a/data/testing/tests/test_zip1struct1.zip b/backend/data/testing/tests/test_zip1struct1.zip similarity index 100% rename from data/testing/tests/test_zip1struct1.zip rename to backend/data/testing/tests/test_zip1struct1.zip diff --git a/data/testing/tests/test_zip2struct1.zip b/backend/data/testing/tests/test_zip2struct1.zip similarity index 100% rename from data/testing/tests/test_zip2struct1.zip rename to backend/data/testing/tests/test_zip2struct1.zip diff --git a/data/testing/tests/test_zip3struct1.zip b/backend/data/testing/tests/test_zip3struct1.zip similarity index 100% rename from data/testing/tests/test_zip3struct1.zip rename to backend/data/testing/tests/test_zip3struct1.zip diff --git a/data/testing/tests/test_zip4struct1.zip b/backend/data/testing/tests/test_zip4struct1.zip similarity index 100% rename from data/testing/tests/test_zip4struct1.zip rename to backend/data/testing/tests/test_zip4struct1.zip diff --git a/backend/ypovoli/settings.py b/backend/ypovoli/settings.py index 5e4ce6de..5a3f7c23 100644 --- a/backend/ypovoli/settings.py +++ b/backend/ypovoli/settings.py @@ -18,7 +18,7 @@ # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent -MEDIA_ROOT = os.path.normpath(os.path.join(BASE_DIR, "../data/production")) +MEDIA_ROOT = os.path.normpath(os.path.join(BASE_DIR, "data/production")) TESTING_BASE_LINK = "http://testserver" From ac6e22fd5406b1b1845fc5d9fd2c4da0e922a8e7 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 12:28:50 +0100 Subject: [PATCH 06/14] chore: checks structure checks --- backend/api/tests/test_submission.py | 62 ++++++++++++++++++++++++++++ backend/api/views/project_view.py | 4 -- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/backend/api/tests/test_submission.py b/backend/api/tests/test_submission.py index a9aa6c9f..f053cdb5 100644 --- a/backend/api/tests/test_submission.py +++ b/backend/api/tests/test_submission.py @@ -1,4 +1,5 @@ import json +from django.utils.translation import gettext from datetime import timedelta from django.utils import timezone from django.urls import reverse @@ -10,6 +11,7 @@ from api.models.course import Course from api.models.checks import ExtraCheck from django.conf import settings +from django.core.files.uploadedfile import SimpleUploadedFile def create_course(name, academic_startyear, description=None, parent_course=None): @@ -32,6 +34,15 @@ def create_project(name, description, days, course): ) +def create_past_project(name, description, days, course, daysStartDate): + """Create a Project with the given arguments.""" + deadline = timezone.now() + timedelta(days=days) + startDate = timezone.now() + timedelta(days=daysStartDate) + return Project.objects.create( + name=name, description=description, deadline=deadline, course=course, score_visible=True, start_date=startDate + ) + + def create_group(project, score): """Create a Group with the given arguments.""" return Group.objects.create(project=project, score=score) @@ -292,3 +303,54 @@ def test_submission_extra_checks(self): self.assertEqual( retrieved_extra_check["passed"], extra_check_result.passed ) + + def test_submission_before_deadline(self): + """ + Able to subbmit to a project before the deadline. + """ + zip_file_path = "data/testing/tests/mixed.zip" + + with open(zip_file_path, 'rb') as f: + files = {'files': SimpleUploadedFile('mixed.zip', f.read())} + course = create_course(name="sel2", academic_startyear=2023) + project = create_project( + name="Project 1", description="Description 1", days=7, course=course + ) + group = create_group(project=project, score=10) + + response = self.client.post( + reverse("group-submissions", args=[str(group.id)]), + files, + follow=True, + ) + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.accepted_media_type, "application/json") + self.assertEqual(json.loads(response.content), {"message": gettext("group.success.submissions.add")}) + + def test_submission_after_deadline(self): + """ + Not able to subbmit to a project after the deadline. + """ + zip_file_path = "data/testing/tests/mixed.zip" + + with open(zip_file_path, 'rb') as f: + files = {'files': SimpleUploadedFile('mixed.zip', f.read())} + + course = create_course(name="sel2", academic_startyear=2023) + project = create_past_project( + name="Project 1", description="Description 1", days=-7, course=course, daysStartDate=-84 + ) + # project.increase_deadline(days=-10) + + group = create_group(project=project, score=10) + + response = self.client.post( + reverse("group-submissions", args=[str(group.id)]), + files, + follow=True, + ) + + self.assertEqual(response.status_code, 400) + self.assertEqual(response.accepted_media_type, "application/json") + self.assertEqual(json.loads(response.content), {'non_field_errors': [gettext("project.error.submissions.past_project")]}) diff --git a/backend/api/views/project_view.py b/backend/api/views/project_view.py index cd5beeea..abe0a9f1 100644 --- a/backend/api/views/project_view.py +++ b/backend/api/views/project_view.py @@ -120,10 +120,6 @@ def _add_structure_check(self, request: Request, **_): "message": gettext("project.success.structure_check.add") }) - return Response({ - "message": gettext("project.success.structure_check.remove") - }) - @action(detail=True, methods=["get"]) def extra_checks(self, request, **_): """Returns the extra checks for the given project""" From bb205027f9e9a46262b8d82e59e795324b482f49 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 13:46:31 +0100 Subject: [PATCH 07/14] chore: added tests --- .../api/serializers/submission_serializer.py | 2 +- backend/api/tests/test_submission.py | 106 +++++++++++++++++- 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/backend/api/serializers/submission_serializer.py b/backend/api/serializers/submission_serializer.py index d75cd853..6059e96d 100644 --- a/backend/api/serializers/submission_serializer.py +++ b/backend/api/serializers/submission_serializer.py @@ -84,7 +84,7 @@ def create(self, validated_data): if not status: pas = False - # Set structure_checks_passed to True + # Set structure_checks_passed submission.structure_checks_passed = pas submission.save() return submission diff --git a/backend/api/tests/test_submission.py b/backend/api/tests/test_submission.py index f053cdb5..c47a84f3 100644 --- a/backend/api/tests/test_submission.py +++ b/backend/api/tests/test_submission.py @@ -12,6 +12,7 @@ from api.models.checks import ExtraCheck from django.conf import settings from django.core.files.uploadedfile import SimpleUploadedFile +from django.db.models import Max def create_course(name, academic_startyear, description=None, parent_course=None): @@ -341,7 +342,6 @@ def test_submission_after_deadline(self): project = create_past_project( name="Project 1", description="Description 1", days=-7, course=course, daysStartDate=-84 ) - # project.increase_deadline(days=-10) group = create_group(project=project, score=10) @@ -353,4 +353,106 @@ def test_submission_after_deadline(self): self.assertEqual(response.status_code, 400) self.assertEqual(response.accepted_media_type, "application/json") - self.assertEqual(json.loads(response.content), {'non_field_errors': [gettext("project.error.submissions.past_project")]}) + self.assertEqual(json.loads(response.content), { + 'non_field_errors': [gettext("project.error.submissions.past_project")]}) + + def test_submission_number_increases_by_1(self): + """ + When submiting a submission the submission number should be the prev one + 1 + """ + zip_file_path = "data/testing/tests/mixed.zip" + + with open(zip_file_path, 'rb') as f: + files = {'files': SimpleUploadedFile('mixed.zip', f.read())} + + course = create_course(name="sel2", academic_startyear=2023) + project = create_project( + name="Project 1", description="Description 1", days=7, course=course + ) + group = create_group(project=project, score=10) + + max_submission_number_before = group.submissions.aggregate(Max('submission_number'))['submission_number__max'] + + if max_submission_number_before is None: + max_submission_number_before = 0 + + old_submissions = group.submissions.count() + response = self.client.post( + reverse("group-submissions", args=[str(group.id)]), + files, + follow=True, + ) + + group.refresh_from_db() + new_submissions = group.submissions.count() + + max_submission_number_after = group.submissions.aggregate(Max('submission_number'))['submission_number__max'] + + if max_submission_number_after is None: + max_submission_number_after = 0 + self.assertEqual(max_submission_number_after - max_submission_number_before, 1) + self.assertEqual(new_submissions - old_submissions, 1) + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.accepted_media_type, "application/json") + self.assertEqual(json.loads(response.content), {"message": gettext("group.success.submissions.add")}) + + def test_submission_invisible_project(self): + """ + Not able to subbmit to a project if its not visible. + """ + zip_file_path = "data/testing/tests/mixed.zip" + + with open(zip_file_path, 'rb') as f: + files = {'files': SimpleUploadedFile('mixed.zip', f.read())} + + course = create_course(name="sel2", academic_startyear=2023) + project = create_project( + name="Project 1", description="Description 1", days=7, course=course + ) + + project.toggle_visible() + project.save() + + group = create_group(project=project, score=10) + + response = self.client.post( + reverse("group-submissions", args=[str(group.id)]), + files, + follow=True, + ) + + self.assertEqual(response.status_code, 400) + self.assertEqual(response.accepted_media_type, "application/json") + self.assertEqual(json.loads(response.content), { + 'non_field_errors': [gettext("project.error.submissions.non_visible_project")]}) + + def test_submission_archived_project(self): + """ + Not able to subbmit to a project if its archived. + """ + zip_file_path = "data/testing/tests/mixed.zip" + + with open(zip_file_path, 'rb') as f: + files = {'files': SimpleUploadedFile('mixed.zip', f.read())} + + course = create_course(name="sel2", academic_startyear=2023) + project = create_project( + name="Project 1", description="Description 1", days=7, course=course + ) + + project.toggle_archived() + project.save() + + group = create_group(project=project, score=10) + + response = self.client.post( + reverse("group-submissions", args=[str(group.id)]), + files, + follow=True, + ) + + self.assertEqual(response.status_code, 400) + self.assertEqual(response.accepted_media_type, "application/json") + self.assertEqual(json.loads(response.content), { + 'non_field_errors': [gettext("project.error.submissions.archived_project")]}) \ No newline at end of file From 680013269976162a534375b01b69e8f1313f00a6 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 14:23:52 +0100 Subject: [PATCH 08/14] chore: tests --- backend/api/tests/test_submission.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/tests/test_submission.py b/backend/api/tests/test_submission.py index c47a84f3..441a0c3f 100644 --- a/backend/api/tests/test_submission.py +++ b/backend/api/tests/test_submission.py @@ -455,4 +455,4 @@ def test_submission_archived_project(self): self.assertEqual(response.status_code, 400) self.assertEqual(response.accepted_media_type, "application/json") self.assertEqual(json.loads(response.content), { - 'non_field_errors': [gettext("project.error.submissions.archived_project")]}) \ No newline at end of file + 'non_field_errors': [gettext("project.error.submissions.archived_project")]}) From 14b0eaddfb94791eb084dcd1add0e4bd54af41b3 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 14:41:30 +0100 Subject: [PATCH 09/14] fix: fix github problems --- .env | 13 ------------- .gitignore | 3 +-- backend/data/production/structures/empty.zip | Bin 22 -> 0 bytes .../production/structures/mixed_template.zip | Bin 822 -> 0 bytes .../structures/only_files_template.zip | Bin 474 -> 0 bytes .../structures/only_folders_template.zip | Bin 638 -> 0 bytes backend/data/production/structures/remake.zip | Bin 3234 -> 0 bytes backend/data/production/structures/root.zip | Bin 226 -> 0 bytes .../data/production/structures/zip_struct1.zip | Bin 2136 -> 0 bytes backend/data/production/tests/mixed.zip | Bin 1660 -> 0 bytes backend/data/production/tests/only_files.zip | Bin 618 -> 0 bytes backend/data/production/tests/only_folders.zip | Bin 990 -> 0 bytes .../data/production/tests/test_zip1struct1.zip | Bin 2136 -> 0 bytes .../data/production/tests/test_zip2struct1.zip | Bin 1988 -> 0 bytes .../data/production/tests/test_zip3struct1.zip | Bin 2258 -> 0 bytes .../data/production/tests/test_zip4struct1.zip | Bin 1822 -> 0 bytes 16 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 .env delete mode 100644 backend/data/production/structures/empty.zip delete mode 100644 backend/data/production/structures/mixed_template.zip delete mode 100644 backend/data/production/structures/only_files_template.zip delete mode 100644 backend/data/production/structures/only_folders_template.zip delete mode 100644 backend/data/production/structures/remake.zip delete mode 100644 backend/data/production/structures/root.zip delete mode 100644 backend/data/production/structures/zip_struct1.zip delete mode 100644 backend/data/production/tests/mixed.zip delete mode 100644 backend/data/production/tests/only_files.zip delete mode 100644 backend/data/production/tests/only_folders.zip delete mode 100644 backend/data/production/tests/test_zip1struct1.zip delete mode 100644 backend/data/production/tests/test_zip2struct1.zip delete mode 100644 backend/data/production/tests/test_zip3struct1.zip delete mode 100644 backend/data/production/tests/test_zip4struct1.zip diff --git a/.env b/.env deleted file mode 100644 index 0d3f97be..00000000 --- a/.env +++ /dev/null @@ -1,13 +0,0 @@ -PUID=1000 -PGID=1000 -TZ="Europe/Brussels" - -DATADIR="./data" - -BACKEND_DIR="./backend" - -FRONTEND_DIR="./frontend" - -REDIS_IP="192.168.90.10" -REDIS_PORT=6379 -REDIS_PASSWORD="oqOsNX1PXGOX5soJtKkw" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 73b3aa42..34d3f12c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,8 @@ data/* data/nginx/ssl/* data/postres* data/redis/* +backend/data/* backend/staticfiles/* !data/nginx/ssl/.gitkeep -!data/production/* -!data/testing/* \ No newline at end of file diff --git a/backend/data/production/structures/empty.zip b/backend/data/production/structures/empty.zip deleted file mode 100644 index 15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22 NcmWIWW@Tf*000g10H*)| diff --git a/backend/data/production/structures/mixed_template.zip b/backend/data/production/structures/mixed_template.zip deleted file mode 100644 index 456c258b7a948ec1e68ae92e48baa5437412adde..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 822 zcmWIWW@h1H0D-^BX%S!sl;B{HVMxo*Nl7g-)DI2eWMI|}d6D`$_(f`I1vdjD%L`@( z1~3tT(*$886UtJHigOav^$Jqb;D&(=#A(=LoX#q9(d ztPAxTGtea<^KiNb-7IOWW|b$Fq!#I=XF|LPG8BX{3}s}JW5yNc641~WV0h~YVj^OI z6%qp^m?q2sGmU{^Nuv{zX(+Kl*kH`KfEf&OWw>PZU#n{ z7t9O{U?Ko+jxL%xoIrCja}(23^$POR!A7(JwSzEDBecMSO(WoE hbkk5>c>&2ZQ0|N^X`Y})LL8nLpm^1YecoxR!lv3JKiw)%eF`_An9-tL2X;~K%wohRLW z{xJTzL0TlGN&2)q=!KN6B`F&Q=~{d5@l{fPzcr#~P{X6^q}CYK3E@AxMzvLgS{N}J zqyu)m!w&ox(FtYVVUi;dV?=Bz4Yv%4WcaM_$K%E?LGg`EbyHDYaj3qeEa~|NUN{Jj zc;BBv9n0AFeT8t_K}cyo?)h*O!ul_u{b3sYjmr8t$wQtP2XR=&anxg2cHlC@;;_s8 z!V|$V0s_S^`#G-*m;Qm`g-z90R81FD+@AF|z6$rE9!&Hn^>EMxPJ6oh>>2m~%qFBlVkfI60upxRS~a1zC^G~;7F z1KNaDBGhJX)lGZ;=6K`Jk>8v6sNeccvGu1=UL~0_A#Y!88!uGI8aWrS?eiDUqpHWehToC_HZ=ZPG&e0Rh90xa#yHnTQz@9?O; zR%YeYEHT_@_1Kmt(06C5nab0{eS+oeD0=$Z3d1A;f_4c@C(AjK5zxs$4uX;@fYT<5 z#Hj-GHH%eWs z^EnEKp$?QtA)q)`YdM25%kVB-R-hCT32@pplKz$RsEAu=+Wo_!WI6#&n@p0XTDX#1 bh{K&$pvj~%S=pS${F#IAJ9zp9nuPoZU*!%e diff --git a/backend/data/production/structures/root.zip b/backend/data/production/structures/root.zip deleted file mode 100644 index 4e703157f5a0929e00ca8b7dd224e0f3e31150ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 226 zcmWIWW@Zs#0D+R2vO?J3$a1~ hY7?3*2(8%cL1@)Rbs)%ARyL3{6A+dG=`aw70RSa#9%=vp diff --git a/backend/data/production/structures/zip_struct1.zip b/backend/data/production/structures/zip_struct1.zip deleted file mode 100644 index bd156cd2a3301c7dd2b28cc7520b8b7447a1ddb4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2136 zcma)-y-ve05XaLGSYfEdz(Dwz7!ulUAQmK8I?#~~g~V+m5*pbl(C!R80(}D}76cLx zz{<=6u(BZ-v1`b=t}l(F8}k84(18XDOW05}_|S^lSkZ<{i5JAgi37ak zDxS@#uate$%A#U5T#+bd$?=l}D!*$0!^FvXkpMn8=fvr$gjbC)r-f0N@R3c1&_ZFo zo5~OW)~cd?H(frg=}{OF=A=v+lTVGXhG{MdBD>uxm1`Ehs+_=&J$V*gTp*fskf>!I z4*0EE0W2~O5vweZfL!q#fn@v0MFyN{wI$Bx;i(8N1OG2N&`qlj^lAxhc6#vvXj**$ z9?l0&i~xA~pX3JP31a|=$r_-k7aXD(1<>@CgjL8RKJX7tlg0rclXXat%|pG6h_4$7 z08Lf`K$;I!j0K1$YXRb8J`s!tfVz0%-%%bR-WLWG#sd(O^+<@#!*&G`ZpMg!XtE+8 XM)^c(Obd%5VToUNRm-~PDVFsMDkRQV diff --git a/backend/data/production/tests/mixed.zip b/backend/data/production/tests/mixed.zip deleted file mode 100644 index 509911007ed853f9249aa3ede21c717e5d25b976..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1660 zcmb8wPfo%>6bA5z1*5nTFvbXB>5dYL9zeIcAV!ICCDMWz3ojTb(&}VVmy9#fj%LY`SHyZlEq*1@T*aW9`J`WCX zJ-uu}COdZk!b{64loVkWOdf}wzB~4N0wd6h{aWLAEY2DJy0MB-5OKWvY~TkY_hEb( zh9QcUHB7D>pG{Gr*o?edG^J~Fj+R-DX6+lTZfEM=kAr@guZM2@^!40TF%BB;m(h>cDSZ#g zGVwjoGj`VaY^YkO8LJ=@>t!g$61Npitr@y0ZP4AaaB0#XMpvnv?E$%UJW`Oy?+E`m Ievkq91EnNEO#lD@ diff --git a/backend/data/production/tests/only_files.zip b/backend/data/production/tests/only_files.zip deleted file mode 100644 index 55a7402c58fd5025e0827be9af1f98886c1802d0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 618 zcmWIWW@h1H0D;9xX%S!sl;C5KVaQ0$$;mIzFUm>L%StQ?4dG;9UKscy6@*JGxEUB( zUNAE-fQbOOIcw0&;RKqKnVXoNs#lPg4mM&lP&)|YG-3{#5gb4xit|$o^hzp9z$Q!w z>IPw)CQL&!fg5N-S!z*nPGY)VK}s6fkZzy>AdF!MBa<96t}u~+2hoy75EDIwSRo;V z$4t!dK{nF^XeLr<0gb~NQV1tvh841L-9Y0IAqO-KYp5Yi!wffM)6N1-LkUHofmlP3 Ul?|wpfdvSi7#SFZfS7>+00f?N$p8QV diff --git a/backend/data/production/tests/only_folders.zip b/backend/data/production/tests/only_folders.zip deleted file mode 100644 index 012a030475b2e794d5b13dfec96d37dce82581db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 990 zcmb8t%?g4*5C`xvHLNb-sYCb%B6;j)bcrqo1<@%YJq1P|(6J}znR=S=(mOPxtGnr% zrtGp8e=|FO{kf`jfu7?oTqg&%88Cz}I_!hf$XP8rpiUQYFvfMg^+3^L6(HICTsRj5 zQxKSByQwuphrGs?CAD(ZW<8QitI~}c^vEm^9a@#vy&-s`pP1{UcXP9w zkwvT2jncBzssslt%Ran4I`TaAG|wMeIZaWU2wI*3W{a+L{=CbgYk}xKq;6gznMQq$ za>`5q5J)@# zD>Dzk%7$RXt|8~TzBI0q>vF%lobUf{w<^_|B~Im_dph~^_uAsIJBR{8J1nI`Kdrk# zNQs{g=;(y@yo+#5sMBZdjIi68Cala7*zhd&lDdm0t>Z~4iId1n2~*PV_NQy^6iLrO zj=)_*GtU}r6Q^Ag$|A4l1Os0IJZON8`G6$oLIZ_I*idHhp%t~Uq79c4FNlc~2T*cP zyR}t3n^9jW`=*seht+UJqSz(JPZFs7t^o`iC-+4H_~M)sr>_!THNu=0#$m!&HW@(+ z`p2Uy+f+XMTdRup-E{e~rpIAKn3FPPO+Gck8a8uD5ZUcksa&&gsd558_T*huxIi@R zokT73aL6Cc3P8v>L`Yd40lDH20?G8qhYUEAv?b2w;i(8N1OE#h=q9NHy;?$>ofbX- zP0|P8(R|><2!NM=B{vvP7z02|)&Nbt;1I|f`4$DG!6intV4oq9_nRe z__~n*&}1b5r1?O_Sb%7<79c+66TxTzs1HwAjXYv_Ul>pr4?s-TBOx{q+ZAMRGe!hN alNA9m$|p)=T38ebOZ<0RwXA!dVp+et6wGG; diff --git a/backend/data/production/tests/test_zip2struct1.zip b/backend/data/production/tests/test_zip2struct1.zip deleted file mode 100644 index fbce9306ed2d477e01496bd8c176376a7840c84d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1988 zcmb7_u};G<5QbA)7!gAy1_nZ5Vn}Ga!G;739q7mgA#qEjgj%)>v^y`sOE4gT!~?MM z6i7_0Fk;t`bB(VJ7bTbFzPp_7zjQm*THRAt-Rqr9UVa{1()R{gLf9!6Y#57Xn52xv zV!%entRG#bW5R+9-Yp1?vuVQWUjiSV=Mim&c+dtOBuGxPNDyv>-|bH4+$j@YfC7cP zfnuI4+9poBB8+EIKS&0#0l2pSjrjnY^q_#!Eo>P*c(aoFSkhL=NR;Fx$P+x}8XnDA zY@~g)(xT03g(^_ZQV>%LnP2_~7^hSY9326mbhp|@*`HQc$DHdaZHIEy#9^8d9tdt6 z@`puO$2z77D!SXLEYv+*Xp$h!pFGRT4v4NkXw-^y`|`Gg3^K$aN{HGNao)Hq+d$1=DA{3}zSyMzk#S_Lh3TDAam2^W9|^MMl?18??`++sW>Yk;_f4MjcU z5JTobvrAG!*QO5m3#Vz>1IQ(O4f3UHE+Eaf*8l)rivWOZHW1bV0PRmzeWsu%Mj1|1~c=ijsO4v diff --git a/backend/data/production/tests/test_zip3struct1.zip b/backend/data/production/tests/test_zip3struct1.zip deleted file mode 100644 index 315fd52e9e46cda79198cf42847465798587c850..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2258 zcma)+y-ve05P;Jkm^)NrU?BWV3<+(SfC&i}20C_wkhpC`LL(;y+MSo+4VYLENIU>5 zGfOu%#D-wRt|8~RzBH~9cZk2cT<*U1QKecp_^Rx7JJUaZw+*&;2Z2ZENu1E3n>1|C zr^HPLbaYI6&V@fF)au9Wl+ZcN5|(BO@$f8kqK1thTE!0~B#Z(lA+dD)b|)KitH|*b zWO3XzB=e-u)^XY;p>g2!EN|dSfO`e7HXjgqT}YsC37b+4-j$#x7PM(o;&>skLJtqQ zjGvCFD}{Yk!lK1$+Wa8zCCiN>i2SAiG#w}UMF3dioD-`r6J8X;oD{}>#9B5QK?;TI z-I8AXTZxM1-LhG;CWn4NVk?QIHu+QtD_G41fuDw)KlZXMkB-?k%ehpp8~A*)uxy#r zd(mkJqON!XRb$&eyA*%G^y3gd|6*~-6}u2fI>ec`)cHW*Otw81!KL7TJ3z8JKLEX2 zLX*wf0)RSS0PtWwaB2_W<$sbJjK^&P5S>pTsb?G_*#&57O587E@elli(}ZmRr1Omc znQUv6k>acN0ie!50Hpaq$wolb`3Q&)`9!c20M+90Sr>~J?+XKRTLDDpD*-Xtwpl?6 rH)Ag#>ih-7AfG5~1~8q^1dPAq9R}leTUg`|*4S@SHH-;+)G&Sl8(!uQ diff --git a/backend/data/production/tests/test_zip4struct1.zip b/backend/data/production/tests/test_zip4struct1.zip deleted file mode 100644 index 9acfea0241389ce71f27778ac5980ed9b7272931..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1822 zcma)+F;9a)6o6?_Hxq{@4w^{R#7RioO*aRZ4l=qa!cj&tHBY`y$5EaYX0^<8&7Ct{0`0gnUZp zXLJ}`rwc;eg!z92epx1L{wJ{6)g;Ke9wa>-m6P`Hq#HunI2gLoG`s`AqXyWm2V_wU z`Hj2o6}nz(MIEeY&!Z%WCd8dYc*!k1o6)dP_Ejs34y)(MM0tE}m}OA;O#>JXSsjrA zh_f0IHz^WcG(t@ai!>8oNj8TT8qd35*!Y)L745t4al-g%Iws8Jtnit9YJ?qZ=87P* z{XwhUv2Z&CK`bYKHgyGvra36oh6pF(*6ag!0AjL7K^zfoaY)%E0Gez9;B!4NcMEvc zyZpv@(lvmXY=fo_Tga$N?g342N!q8D9Q+8UDHj1`vQdE?5gw{R;3fb~b^>r&4J^0{ zM3b#RJZPhnlY0es0jLj8{^Qk>!%HxrbQvHfn-#eiOTiWHJPw3 Mt`FO?w#98(KeNV#0RR91 From 36430ed58a9ae7f2341334144af8bf7748407541 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 14:43:30 +0100 Subject: [PATCH 10/14] chore: cleanup gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 34d3f12c..17cb6539 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ data/* data/nginx/ssl/* data/postres* data/redis/* -backend/data/* +backend/data/production* backend/staticfiles/* From 68adeca024178a9086143128d3058930fa7536a0 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 14:52:28 +0100 Subject: [PATCH 11/14] chore: cleanup linting --- backend/api/views/project_view.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/api/views/project_view.py b/backend/api/views/project_view.py index 0ee3a6aa..16d4aa7d 100644 --- a/backend/api/views/project_view.py +++ b/backend/api/views/project_view.py @@ -10,7 +10,11 @@ from api.models.project import Project from api.models.checks import StructureCheck from api.serializers.checks_serializer import StructureCheckSerializer, ExtraCheckSerializer -from api.serializers.project_serializer import ProjectSerializer, TeacherCreateGroupSerializer, StructureCheckAddSerializer, SubmissionStatusSerializer +from api.serializers.project_serializer import ( + StructureCheckAddSerializer, SubmissionStatusSerializer, + ProjectSerializer, TeacherCreateGroupSerializer +) + from api.serializers.group_serializer import GroupSerializer from api.serializers.submission_serializer import SubmissionSerializer from rest_framework.request import Request From f5e14c57b8b7bc739054873f32ed0d201e25dcec Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 15:00:35 +0100 Subject: [PATCH 12/14] chore: add python naming conventions --- backend/api/tests/test_submission.py | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/backend/api/tests/test_submission.py b/backend/api/tests/test_submission.py index 441a0c3f..e5959167 100644 --- a/backend/api/tests/test_submission.py +++ b/backend/api/tests/test_submission.py @@ -15,13 +15,13 @@ from django.db.models import Max -def create_course(name, academic_startyear, description=None, parent_course=None): +def create_course(name, academic_start_year, description=None, parent_course=None): """ Create a Course with the given arguments. """ return Course.objects.create( name=name, - academic_startyear=academic_startyear, + academic_startyear=academic_start_year, description=description, parent_course=parent_course, ) @@ -35,10 +35,10 @@ def create_project(name, description, days, course): ) -def create_past_project(name, description, days, course, daysStartDate): +def create_past_project(name, description, days, course, days_start_ate): """Create a Project with the given arguments.""" deadline = timezone.now() + timedelta(days=days) - startDate = timezone.now() + timedelta(days=daysStartDate) + startDate = timezone.now() + timedelta(days=days_start_ate) return Project.objects.create( name=name, description=description, deadline=deadline, course=course, score_visible=True, start_date=startDate ) @@ -86,7 +86,7 @@ def test_submission_exists(self): """ Able to retrieve a single submission after creating it. """ - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) @@ -125,7 +125,7 @@ def test_multiple_submission_exists(self): """ Able to retrieve multiple submissions after creating them. """ - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) @@ -177,7 +177,7 @@ def test_submission_detail_view(self): """ Able to retrieve details of a single submission. """ - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) @@ -214,7 +214,7 @@ def test_submission_group(self): """ Able to retrieve group of a single submission. """ - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) @@ -266,7 +266,7 @@ def test_submission_extra_checks(self): """ Able to retrieve extra checks of a single submission. """ - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) @@ -311,9 +311,9 @@ def test_submission_before_deadline(self): """ zip_file_path = "data/testing/tests/mixed.zip" - with open(zip_file_path, 'rb') as f: - files = {'files': SimpleUploadedFile('mixed.zip', f.read())} - course = create_course(name="sel2", academic_startyear=2023) + with open(zip_file_path, 'rb') as file: + files = {'files': SimpleUploadedFile('mixed.zip', file.read())} + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) @@ -338,9 +338,9 @@ def test_submission_after_deadline(self): with open(zip_file_path, 'rb') as f: files = {'files': SimpleUploadedFile('mixed.zip', f.read())} - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_past_project( - name="Project 1", description="Description 1", days=-7, course=course, daysStartDate=-84 + name="Project 1", description="Description 1", days=-7, course=course, days_start_ate=-84 ) group = create_group(project=project, score=10) @@ -365,7 +365,7 @@ def test_submission_number_increases_by_1(self): with open(zip_file_path, 'rb') as f: files = {'files': SimpleUploadedFile('mixed.zip', f.read())} - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) @@ -406,7 +406,7 @@ def test_submission_invisible_project(self): with open(zip_file_path, 'rb') as f: files = {'files': SimpleUploadedFile('mixed.zip', f.read())} - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) @@ -436,7 +436,7 @@ def test_submission_archived_project(self): with open(zip_file_path, 'rb') as f: files = {'files': SimpleUploadedFile('mixed.zip', f.read())} - course = create_course(name="sel2", academic_startyear=2023) + course = create_course(name="sel2", academic_start_year=2023) project = create_project( name="Project 1", description="Description 1", days=7, course=course ) From 262f85ca4e593b410d9f3d7824b6af7e01e9adbd Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 15:06:50 +0100 Subject: [PATCH 13/14] fix: fixed gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 06a5c57d..ef08eecc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ data/* data/nginx/ssl/* data/postres* data/redis/* -backend/data/production* +backend/data/production/* /node_modules backend/staticfiles/* From 8c905e4c7dec15b9ee94e29870366dd89c1cd434 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Thu, 14 Mar 2024 15:07:51 +0100 Subject: [PATCH 14/14] =?UTF-8?q?fix:=20fixed=20ty=C3=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/api/tests/test_submission.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/api/tests/test_submission.py b/backend/api/tests/test_submission.py index e5959167..cc2d58ca 100644 --- a/backend/api/tests/test_submission.py +++ b/backend/api/tests/test_submission.py @@ -35,10 +35,10 @@ def create_project(name, description, days, course): ) -def create_past_project(name, description, days, course, days_start_ate): +def create_past_project(name, description, days, course, days_start_date): """Create a Project with the given arguments.""" deadline = timezone.now() + timedelta(days=days) - startDate = timezone.now() + timedelta(days=days_start_ate) + startDate = timezone.now() + timedelta(days=days_start_date) return Project.objects.create( name=name, description=description, deadline=deadline, course=course, score_visible=True, start_date=startDate ) @@ -340,7 +340,7 @@ def test_submission_after_deadline(self): course = create_course(name="sel2", academic_start_year=2023) project = create_past_project( - name="Project 1", description="Description 1", days=-7, course=course, days_start_ate=-84 + name="Project 1", description="Description 1", days=-7, course=course, days_start_date=-84 ) group = create_group(project=project, score=10)