Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #449

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bbf55fb
chore: better submission status
francisvaut May 13, 2024
522ff18
chore: add tests + fix tests
francisvaut May 13, 2024
de0b363
Merge branch 'submission-status2' into fix-tests
francisvaut May 13, 2024
275b14d
test: fix group type test
francisvaut May 13, 2024
88dbf86
test: fix course type test
francisvaut May 13, 2024
bffd2d5
Merge branch 'development' into submission-status2
francisvaut May 15, 2024
67bad52
fix: backend tests
francisvaut May 15, 2024
8fcf4fe
Merge branch 'submission-status2' into fix-tests
francisvaut May 15, 2024
abd1ce0
chore: use File type in submission tests
francisvaut May 15, 2024
f597931
chore: project data by id test
francisvaut May 15, 2024
3304c0b
chore: add zips to projects in data.ts
francisvaut May 15, 2024
16b7d97
chore: fix project service tests
francisvaut May 15, 2024
3bf8253
chore: use project object instead of id in groups
francisvaut May 15, 2024
8e3be47
Merge branch 'development' into submission-status2
francisvaut May 15, 2024
3c334cd
Merge branch 'submission-status2' into fix-tests
francisvaut May 15, 2024
bb99148
Revert "chore: use project object instead of id in groups"
francisvaut May 15, 2024
046ac35
chore: fix null submissions in project
francisvaut May 15, 2024
2b607af
chore: fix status service tests
francisvaut May 15, 2024
32b16f0
Merge branch 'development' into fix-tests
francisvaut May 19, 2024
6b88966
Merge branch 'development' into fix-tests
francisvaut May 21, 2024
a95fed8
chore: fix submission data types
francisvaut May 21, 2024
f9c2e89
chore: fix submission by project
francisvaut May 21, 2024
dd44641
chore: commit changes beause i need to fix something else
francisvaut May 21, 2024
465b7b9
chore: fix submission by group
francisvaut May 21, 2024
96beae4
chore: fix get group by id
francisvaut May 21, 2024
f519cdf
chore: fix get groups by project
francisvaut May 21, 2024
6f9086a
chore: fix get groups by student
francisvaut May 21, 2024
043cac8
chore: remove create group
francisvaut May 21, 2024
b129289
chore: linting autofix
francisvaut May 21, 2024
d457f69
chore: fix asserttypes
francisvaut May 21, 2024
8db35b0
chore: fix linting errors
francisvaut May 21, 2024
8715811
chore: remove unused imports and vars
francisvaut May 21, 2024
cbc203c
fix: add File imports
francisvaut May 21, 2024
6f96e4a
fix: backend linting
francisvaut May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
22 changes: 0 additions & 22 deletions backend/Dockerfile.prod

This file was deleted.

9 changes: 0 additions & 9 deletions backend/api/fixtures/realistic/realistic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
time_limit: 10
memory_limit: 50
show_log: false
show_artifact: false
- model: api.extracheck
pk: 1
fields:
Expand All @@ -183,7 +182,6 @@
time_limit: 30
memory_limit: 128
show_log: true
show_artifact: true

# MARK: Students
- model: api.student
Expand Down Expand Up @@ -693,43 +691,36 @@
fields:
extra_check: 0
log_file: fixtures/realistic/projects/0/0/submissions/0/submission_1/logs/log_extra_check_0.txt
artifact: ""
- model: api.extracheckresult
pk: 3
fields:
extra_check: 1
log_file: fixtures/realistic/projects/0/0/submissions/0/submission_1/logs/log_extra_check_1.txt
artifact: fixtures/realistic/projects/0/0/submissions/0/submission_1/artifacts/artifact_extra_check_1.zip
- model: api.extracheckresult
pk: 5
fields:
extra_check: 0
log_file: fixtures/realistic/projects/0/0/submissions/0/submission_2/logs/log_extra_check_0.txt
artifact: ""
- model: api.extracheckresult
pk: 6
fields:
extra_check: 1
log_file: fixtures/realistic/projects/0/0/submissions/0/submission_2/logs/log_extra_check_1.txt
artifact: fixtures/realistic/projects/0/0/submissions/0/submission_2/artifacts/artifact_extra_check_1.zip
- model: api.extracheckresult
pk: 8
fields:
extra_check: 0
log_file: ""
artifact: ""
- model: api.extracheckresult
pk: 9
fields:
extra_check: 1
log_file: ""
artifact: ""
- model: api.extracheckresult
pk: 11
fields:
extra_check: 0
log_file: fixtures/realistic/projects/0/0/submissions/1/submission_2/logs/log_extra_check_0.txt
artifact: ""
- model: api.extracheckresult
pk: 12
fields:
Expand Down
28 changes: 14 additions & 14 deletions backend/api/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,61 +34,61 @@ msgstr "Docker image is ready"
msgid "dockerimage.state.error"
msgstr "Docker image failed to build"

#: models/submission.py:62
#: models/submission.py:61
msgid "submission.state.queued"
msgstr "Queued"

#: models/submission.py:63
#: models/submission.py:62
msgid "submission.state.running"
msgstr "Running"

#: models/submission.py:64
#: models/submission.py:63
msgid "submission.state.success"
msgstr "Success"

#: models/submission.py:65
#: models/submission.py:64
msgid "submission.state.failed"
msgstr "Failed"

#: models/submission.py:70
#: models/submission.py:69
msgid "submission.error.blockedextension"
msgstr "The zip file contains a file with a non-allowed extension."

#: models/submission.py:71
#: models/submission.py:70
msgid "submission.error.obligatedextensionnotfound"
msgstr ""
"The submitted zip file doesn't have any file with an obligated file "
"extension."

#: models/submission.py:72
#: models/submission.py:71
msgid "submission.error.filedirnotfound"
msgstr "The submitted zip file lacks an obligated directory."

#: models/submission.py:75
#: models/submission.py:74
msgid "submission.error.dockerimageerror"
msgstr "try again later."

#: models/submission.py:76
#: models/submission.py:75
msgid "submission.error.timelimit"
msgstr "Timelimit exceeded."

#: models/submission.py:77
#: models/submission.py:76
msgid "submission.error.memorylimit"
msgstr "Memorylimit exceeded."

#: models/submission.py:78
#: models/submission.py:77
msgid "submission.error.checkerror"
msgstr "A check failed."

#: models/submission.py:79
#: models/submission.py:78
msgid "submission.error.runtimeerror"
msgstr "Crashed."

#: models/submission.py:80
#: models/submission.py:79
msgid "submission.error.unknown"
msgstr "Unkown error."

#: models/submission.py:81
#: models/submission.py:80
msgid "submission.error.failedstructurecheck"
msgstr "The zip file doesn't have the right structure."

Expand Down
28 changes: 14 additions & 14 deletions backend/api/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,61 +34,61 @@ msgstr "Docker image is klaar."
msgid "dockerimage.state.error"
msgstr "Docker image is gefaald om te bouwen."

#: models/submission.py:62
#: models/submission.py:61
msgid "submission.state.queued"
msgstr "wachten"

#: models/submission.py:63
#: models/submission.py:62
msgid "submission.state.running"
msgstr "lopen"

#: models/submission.py:64
#: models/submission.py:63
msgid "submission.state.success"
msgstr "succes"

#: models/submission.py:65
#: models/submission.py:64
msgid "submission.state.failed"
msgstr "gefaald"

#: models/submission.py:70
#: models/submission.py:69
msgid "submission.error.blockedextension"
msgstr "De zip file bevat een niet toegelaten bestandstype."

#: models/submission.py:71
#: models/submission.py:70
msgid "submission.error.obligatedextensionnotfound"
msgstr ""
"Er is geen enkel bestand met een bepaalde bestandstype die verplicht is in "
"het ingediende zip-bestand."

#: models/submission.py:72
#: models/submission.py:71
msgid "submission.error.filedirnotfound"
msgstr "De ingediende zip file mankeerd een verplichtte map."

#: models/submission.py:75
#: models/submission.py:74
msgid "submission.error.dockerimageerror"
msgstr "Probeer later opnieuw."

#: models/submission.py:76
#: models/submission.py:75
msgid "submission.error.timelimit"
msgstr "Tijdslimit bereikt."

#: models/submission.py:77
#: models/submission.py:76
msgid "submission.error.memorylimit"
msgstr "Geheugenlimiet bereikt."

#: models/submission.py:78
#: models/submission.py:77
msgid "submission.error.checkerror"
msgstr "Een check faalde."

#: models/submission.py:79
#: models/submission.py:78
msgid "submission.error.runtimeerror"
msgstr "Crashed."

#: models/submission.py:80
#: models/submission.py:79
msgid "submission.error.unknown"
msgstr "Onbekende fout."

#: models/submission.py:81
#: models/submission.py:80
msgid "submission.error.failedstructurecheck"
msgstr "De ingediende zip file heeft niet de juiste structuur."

Expand Down
5 changes: 0 additions & 5 deletions backend/api/logic/get_file_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,3 @@ def get_docker_image_file_path(instance: DockerImage, _: str) -> str:

def get_docker_image_tag(instance: DockerImage) -> str:
return f"{DOCKER_BUILD_ROOT_NAME}_{instance.id}"


def get_extra_check_artifact_file_path(instance: ExtraCheckResult, uuid: str) -> str:
return (f"{_get_project_dir_path(instance.submission.group.project)}"
f"submissions/{instance.submission.group.id}/{uuid}/artifacts/{_get_uuid()}.zip")
24 changes: 0 additions & 24 deletions backend/api/migrations/0025_extracheckresult_artifact.py

This file was deleted.

10 changes: 3 additions & 7 deletions backend/api/models/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class FileExtension(models.Model):
unique=True
)

# TODO: Remove zip.* translations


class StructureCheck(models.Model):
"""Model that represents a structure check for a project.
Expand Down Expand Up @@ -98,6 +100,7 @@ class ExtraCheck(models.Model):
)

# Maximum memory the container uses in MB
# TODO: Set max and min
memory_limit = models.PositiveSmallIntegerField(
default=128,
blank=False,
Expand All @@ -110,10 +113,3 @@ class ExtraCheck(models.Model):
blank=False,
null=False
)

# Whether the artifacts should made available to the student
show_artifact = models.BooleanField(
default=True,
blank=False,
null=False
)
11 changes: 1 addition & 10 deletions backend/api/models/submission.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import TYPE_CHECKING

from api.logic.get_file_path import (get_extra_check_artifact_file_path,
get_extra_check_log_file_path,
from api.logic.get_file_path import (get_extra_check_log_file_path,
get_submission_file_path)
from api.models.checks import ExtraCheck, StructureCheck
from api.models.group import Group
Expand Down Expand Up @@ -138,11 +137,3 @@ class ExtraCheckResult(CheckResult):
blank=False,
null=True
)

# File path for the artifact of the extra checks
artifact = models.FileField(
upload_to=get_extra_check_artifact_file_path,
max_length=256,
blank=False,
null=True
)
19 changes: 0 additions & 19 deletions backend/api/permissions/group_permissions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from api.models.group import Group
from api.permissions.role_permissions import (is_assistant, is_student,
is_teacher)
from authentication.models import User
from rest_framework.permissions import SAFE_METHODS, BasePermission
from rest_framework.request import Request
from rest_framework.views import APIView
from rest_framework.viewsets import ViewSet


Expand Down Expand Up @@ -61,23 +59,6 @@ def has_object_permission(self, request: Request, view: ViewSet, group) -> bool:
class GroupSubmissionPermission(BasePermission):
"""Permission class for submission related group endpoints"""

def has_permission(self, request: Request, view: APIView) -> bool:
user: User = request.user
group_id = view.kwargs.get('pk')
group: Group | None = Group.objects.get(id=group_id) if group_id else None

if group is None:
return True

# Teachers and assistants of that course can view all submissions
if is_teacher(user):
return group.project.course.teachers.filter(id=user.teacher.id).exists()

if is_assistant(user):
return group.project.course.assistants.filter(id=user.assistant.id).exists()

return is_student(user) and group.students.filter(id=user.student.id).exists()

def had_object_permission(self, request: Request, view: ViewSet, group) -> bool:
user: User = request.user
course = group.project.course
Expand Down
5 changes: 5 additions & 0 deletions backend/api/permissions/project_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def has_permission(self, request: Request, view: ViewSet) -> bool:
"""Check if user has permission to view a general project endpoint."""
user: User = request.user

# TODO: Sure return True corresponds with the comments made above
# The general project endpoint that lists all projects is not accessible for any role.
if request.method in SAFE_METHODS:
return True

# We only allow teachers and assistants to create new projects.
return is_teacher(user) or is_assistant(user)

Expand Down
15 changes: 0 additions & 15 deletions backend/api/permissions/submission_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,3 @@ def has_object_permission(self, request: Request, view: APIView, obj: ExtraCheck
return obj.extra_check.show_log

return True


class ExtraCheckResultArtifactPermission(ExtraCheckResultPermission):
def has_object_permission(self, request: Request, view: APIView, obj: ExtraCheckResult) -> bool:
result = super().has_object_permission(request, view, obj)

if not result:
return False

user: User = cast(User, request.user)

if is_student(user):
return obj.extra_check.show_artifact

return True
3 changes: 0 additions & 3 deletions backend/api/serializers/submission_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ def to_representation(self, instance: ExtraCheckResult) -> dict | None:
representation["log_file"] = request.build_absolute_uri(
reverse("extra-check-result-detail", args=[str(instance.id)]) + "log/"
)
representation["artifact"] = request.build_absolute_uri(
reverse("extra-check-result-detail", args=[str(instance.id)]) + "artifact/"
)
return representation

return None
Expand Down
Loading