Skip to content

Commit

Permalink
Merge pull request #227 from SELab-2/extra_checks
Browse files Browse the repository at this point in the history
Extra checks
  • Loading branch information
EwoutV authored Apr 3, 2024
2 parents 4a83e9b + a50adf0 commit ce7764e
Show file tree
Hide file tree
Showing 18 changed files with 336 additions and 217 deletions.
14 changes: 4 additions & 10 deletions backend/api/fixtures/checks.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
- model: api.extracheck
pk: 1
fields:
project: 123456
run_script: 'scripts/run.sh'

- model: api.fileextension
pk: 1
fields:
extension: 'class'
extension: "class"
- model: api.fileextension
pk: 2
fields:
extension: 'png'
extension: "png"
- model: api.fileextension
pk: 3
fields:
extension: 'java'
extension: "java"
- model: api.fileextension
pk: 4
fields:
extension: 'py'
extension: "py"
21 changes: 4 additions & 17 deletions backend/api/fixtures/submissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,23 @@
fields:
group: 1
submission_number: 1
submission_time: '2021-01-01T00:00:00Z'
submission_time: "2021-01-01T00:00:00Z"
structure_checks_passed: True
- model: api.submission
pk: 2
fields:
group: 1
submission_number: 2
submission_time: '2021-01-02T00:00:00Z'
submission_time: "2021-01-02T00:00:00Z"
structure_checks_passed: True

- model: api.submissionfile
pk: 1
fields:
submission: 1
file: 'submissions/1/1/1.txt'
file: "submissions/1/1/1.txt"
- model: api.submissionfile
pk: 2
fields:
submission: 2
file: 'submissions/1/2/1.txt'

- model: api.extrachecksresult
pk: 1
fields:
submission: 1
extra_check: 1
passed: False
- model: api.extrachecksresult
pk: 2
fields:
submission: 2
extra_check: 1
passed: True
file: "submissions/1/2/1.txt"
65 changes: 65 additions & 0 deletions backend/api/migrations/0008_add_extra_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from api.models.checks import DockerImage
from api.models.submission import ErrorTemplates
from django.db import migrations, models
from ypovoli.settings import FILE_PATHS


class Migration(migrations.Migration):

dependencies = [
('api', '0007_merge_20240313_0639'),
]

operations = [
migrations.CreateModel(
name="dockerimage",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=256, blank=False, null=False)),
('file_path', models.FileField(upload_to=FILE_PATHS["docker_images"], max_length=256, blank=False, null=False)),
('custom', models.BooleanField(default=False, blank=False, null=False)),
]
),
migrations.CreateModel(
name="errortemplate",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('message_key', models.CharField(max_length=256, blank=False, null=False)),
]
),
migrations.RemoveField(
model_name="extracheck",
name="run_script",
),
migrations.AddField(
model_name="extracheck",
name="docker_image_id",
field=models.ForeignKey(to="api.dockerimage", on_delete=models.CASCADE, related_name="extra_checks"),
),
migrations.AddField(
model_name="extracheck",
name="file_path",
field=models.CharField(max_length=256, blank=False, null=False)
),
migrations.AddField(
model_name="extracheck",
name="timeout",
field=models.SmallIntegerField(default=300, blank=False, null=False)
),
migrations.AddField(
model_name="extracheck",
name="show_log",
field=models.BooleanField(default=True, blank=False, null=False)
),
migrations.AddField(
model_name="extrachecksresult",
name="error_message",
field=models.ForeignKey(to="api.errortemplate", on_delete=models.CASCADE,
related_name="extra_checks_results", blank=True, null=True)
),
migrations.AddField(
model_name="extrachecksresult",
name="log_file",
field=models.CharField(max_length=256, blank=False, null=True)
)
]
64 changes: 58 additions & 6 deletions backend/api/models/checks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from api.models.project import Project
from api.models.extension import FileExtension
from api.models.project import Project
from django.db import models
from ypovoli.settings import FILE_PATHS


class StructureCheck(models.Model):
Expand Down Expand Up @@ -42,6 +42,37 @@ class StructureCheck(models.Model):
# ID check should be generated automatically


class DockerImage(models.Model):
"""
Models that represents the different docker environments to run tests in
"""

# ID should be generated automatically
id = models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')

# Name of the docker image
name = models.CharField(
max_length=256,
blank=False,
null=False
)

# File path of the docker image
file_path = models.FileField(
upload_to=FILE_PATHS["docker_images"],
max_length=256,
blank=False,
null=False
)

# Whether the image is custom uploaded by a prof.
custom = models.BooleanField(
default=True,
blank=False,
null=False
)


class ExtraCheck(models.Model):
"""Model that represents an extra check for a project.
These checks are not obligated to pass."""
Expand All @@ -55,9 +86,30 @@ class ExtraCheck(models.Model):
related_name="extra_checks"
)

# Run script
# TODO set upload_to
run_script = models.FileField(
docker_image = models.ForeignKey(
DockerImage,
on_delete=models.CASCADE,
related_name="extra_checks"
)

# File path of the script that runs the checks
file_path = models.CharField(
max_length=256,
blank=False,
null=False
)

# Maximum time the script can run for
# TODO: Set a max of 1000 seconds
timeout = models.SmallIntegerField(
default=300,
blank=False,
null=False
)

# Whether the log files should be kept and made available to the user
show_log = models.BooleanField(
default=True,
blank=False,
null=False
)
40 changes: 36 additions & 4 deletions backend/api/models/submission.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from api.models.group import Group
from api.models.checks import ExtraCheck
from api.models.group import Group
from django.db import models


class Submission(models.Model):
Expand Down Expand Up @@ -49,9 +49,25 @@ class SubmissionFile(models.Model):
null=False,
)

# TODO: Set upload_to (use ypovoli.settings)
file = models.FileField(blank=False, null=False)


class ErrorTemplates(models.Model):
"""
Model possible error templates for a submission checks result.
"""

# ID should be generated automatically

# Key of the error template message
message_key = models.CharField(
max_length=256,
blank=False,
null=False
)


class ExtraChecksResult(models.Model):
"""Model for the result of extra checks on a submission."""

Expand All @@ -62,7 +78,7 @@ class ExtraChecksResult(models.Model):
on_delete=models.CASCADE,
related_name="extra_checks_results",
blank=False,
null=False,
null=False
)

# Link to the extra checks that were performed
Expand All @@ -71,7 +87,7 @@ class ExtraChecksResult(models.Model):
on_delete=models.CASCADE,
related_name="results",
blank=False,
null=False,
null=False
)

# True if the submission passed the extra checks
Expand All @@ -80,3 +96,19 @@ class ExtraChecksResult(models.Model):
null=False,
default=False
)

# Error message if the submission failed the extra checks
error_message = models.ForeignKey(
ErrorTemplates,
on_delete=models.CASCADE,
related_name="extra_checks_results",
blank=True,
null=True
)

# File path for the log file of the extra checks
log_file = models.CharField(
max_length=256,
blank=False,
null=True
)
6 changes: 3 additions & 3 deletions backend/api/serializers/checks_serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import serializers

from ..models.checks import ExtraCheck, StructureCheck
from ..models.extension import FileExtension
from ..models.checks import StructureCheck, ExtraCheck


class FileExtensionSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -36,6 +37,5 @@ class Meta:
model = ExtraCheck
fields = [
"id",
"project",
"run_script"
"project"
]
Loading

0 comments on commit ce7764e

Please sign in to comment.