diff --git a/backend/api/models/project.py b/backend/api/models/project.py index 88e587fc..839907a1 100644 --- a/backend/api/models/project.py +++ b/backend/api/models/project.py @@ -1,4 +1,3 @@ -from datetime import datetime from django.db import models from django.utils import timezone from api.models.course import Course @@ -21,7 +20,7 @@ class Project(models.Model): start_date = models.DateTimeField( # The default value is the current date and time - default=datetime.now, + default=timezone.now, blank=True, ) diff --git a/backend/api/tests/test_checks.py b/backend/api/tests/test_checks.py index b66251b8..d1c66580 100644 --- a/backend/api/tests/test_checks.py +++ b/backend/api/tests/test_checks.py @@ -7,6 +7,7 @@ from api.models.extension import FileExtension from api.models.project import Project from api.models.course import Course +from django.conf import settings def create_fileExtension(id, extension): @@ -300,4 +301,4 @@ def test_extra_checks_exists(self): # Assert the details of the retrieved Checks match the created Checks retrieved_checks = content_json[0] self.assertEqual(int(retrieved_checks["id"]), checks.id) - self.assertEqual(retrieved_checks["run_script"], "http://testserver" + checks.run_script.url) + self.assertEqual(retrieved_checks["run_script"], settings.TESTING_BASE_LINK + checks.run_script.url) diff --git a/backend/api/tests/test_file_structure.py b/backend/api/tests/test_file_structure.py index 5f83044c..84b261af 100644 --- a/backend/api/tests/test_file_structure.py +++ b/backend/api/tests/test_file_structure.py @@ -92,8 +92,59 @@ def test_your_function(self): content_json = json.loads(response.content.decode("utf-8")) - # print("strucCheck:", content_json["structure_checks"]) - # TODO get the structure checks from this now its following - # strucCheck: http://testserver/projects/1/structure_checks/ + response = self.client.get( + content_json["structure_checks"], follow=True + ) + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.accepted_media_type, "application/json") + + content_json = json.loads(response.content.decode("utf-8")) + + self.assertEqual(len(content_json), 7) + + expected_project_url = settings.TESTING_BASE_LINK + reverse( + "project-detail", args=[str(project.id)] + ) - self.assertEqual(True, True) + content = content_json[0] + self.assertEqual(content["name"], ".") + self.assertEqual(content["project"], expected_project_url) + self.assertEqual(len(content["obligated_extensions"]), 0) + self.assertEqual(len(content["blocked_extensions"]), 0) + + content = content_json[1] + self.assertEqual(content["name"], "folder_struct1") + self.assertEqual(content["project"], expected_project_url) + self.assertEqual(len(content["obligated_extensions"]), 1) + self.assertEqual(len(content["blocked_extensions"]), 0) + + content = content_json[2] + self.assertEqual(content["name"], "folder_struct1/submap1") + self.assertEqual(content["project"], expected_project_url) + self.assertEqual(len(content["obligated_extensions"]), 2) + self.assertEqual(len(content["blocked_extensions"]), 0) + + content = content_json[3] + self.assertEqual(content["name"], "folder_struct1/submap1/templates") + self.assertEqual(content["project"], expected_project_url) + self.assertEqual(len(content["obligated_extensions"]), 1) + self.assertEqual(len(content["blocked_extensions"]), 0) + + content = content_json[4] + self.assertEqual(content["name"], "folder_struct1/submap2") + self.assertEqual(content["project"], expected_project_url) + self.assertEqual(len(content["obligated_extensions"]), 1) + self.assertEqual(len(content["blocked_extensions"]), 0) + + content = content_json[5] + self.assertEqual(content["name"], "folder_struct1/submap2/src") + self.assertEqual(content["project"], expected_project_url) + self.assertEqual(len(content["obligated_extensions"]), 3) + self.assertEqual(len(content["blocked_extensions"]), 0) + + content = content_json[6] + self.assertEqual(content["name"], "folder_struct1/submap3") + self.assertEqual(content["project"], expected_project_url) + self.assertEqual(len(content["obligated_extensions"]), 2) + self.assertEqual(len(content["blocked_extensions"]), 0) diff --git a/backend/api/tests/test_group.py b/backend/api/tests/test_group.py index f10e87d4..e90e80de 100644 --- a/backend/api/tests/test_group.py +++ b/backend/api/tests/test_group.py @@ -8,6 +8,7 @@ from api.models.student import Student from api.models.group import Group from api.models.course import Course +from django.conf import settings def create_course(name, academic_startyear, description=None, parent_course=None): @@ -83,7 +84,7 @@ def test_group_exists(self): self.assertEqual(len(content_json), 1) retrieved_group = content_json[0] - expected_project_url = "http://testserver" + reverse( + expected_project_url = settings.TESTING_BASE_LINK + reverse( "project-detail", args=[str(project.id)] ) @@ -122,10 +123,10 @@ def test_multiple_groups(self): self.assertEqual(len(content_json), 2) retrieved_group1, retrieved_group2 = content_json - expected_project_url1 = "http://testserver" + reverse( + expected_project_url1 = settings.TESTING_BASE_LINK + reverse( "project-detail", args=[str(project1.id)] ) - expected_project_url2 = "http://testserver" + reverse( + expected_project_url2 = settings.TESTING_BASE_LINK + reverse( "project-detail", args=[str(project2.id)] ) @@ -159,7 +160,7 @@ def test_group_detail_view(self): content_json = json.loads(response.content.decode("utf-8")) - expected_project_url = "http://testserver" + reverse( + expected_project_url = settings.TESTING_BASE_LINK + reverse( "project-detail", args=[str(project.id)] ) @@ -203,7 +204,7 @@ def test_group_project(self): # Parse the JSON content from the response content_json = json.loads(response.content.decode("utf-8")) - expected_course_url = "http://testserver" + reverse( + expected_course_url = settings.TESTING_BASE_LINK + reverse( "course-detail", args=[str(course.id)] ) diff --git a/backend/api/tests/test_project.py b/backend/api/tests/test_project.py index 126e4257..a5885712 100644 --- a/backend/api/tests/test_project.py +++ b/backend/api/tests/test_project.py @@ -7,6 +7,7 @@ from api.models.course import Course from api.models.checks import StructureCheck, ExtraCheck from api.models.extension import FileExtension +from django.conf import settings def create_course(id, name, academic_startyear): @@ -212,7 +213,7 @@ def test_project_exists(self): retrieved_project = content_json[0] - expected_course_url = "http://testserver" + reverse( + expected_course_url = settings.TESTING_BASE_LINK + reverse( "course-detail", args=[str(course.id)] ) @@ -256,7 +257,7 @@ def test_multiple_project(self): retrieved_project = content_json[0] - expected_course_url = "http://testserver" + reverse( + expected_course_url = settings.TESTING_BASE_LINK + reverse( "course-detail", args=[str(course.id)] ) @@ -268,7 +269,7 @@ def test_multiple_project(self): retrieved_project = content_json[1] - expected_course_url = "http://testserver" + reverse( + expected_course_url = settings.TESTING_BASE_LINK + reverse( "course-detail", args=[str(course.id)] ) @@ -361,7 +362,7 @@ def test_project_structure_checks(self): retrieved_project = content_json[0] - expected_course_url = "http://testserver" + reverse( + expected_course_url = settings.TESTING_BASE_LINK + reverse( "course-detail", args=[str(course.id)] ) @@ -449,7 +450,7 @@ def test_project_extra_checks(self): content_json = json.loads(response.content.decode("utf-8"))[0] self.assertEqual(int(content_json["id"]), checks.id) - self.assertEqual(content_json["project"], "http://testserver" + reverse( + self.assertEqual(content_json["project"], settings.TESTING_BASE_LINK + reverse( "project-detail", args=[str(project.id)] )) - self.assertEqual(content_json["run_script"], "http://testserver" + checks.run_script.url) + self.assertEqual(content_json["run_script"], settings.TESTING_BASE_LINK + checks.run_script.url) diff --git a/backend/api/tests/test_submission.py b/backend/api/tests/test_submission.py index ac0b52ab..ec426a03 100644 --- a/backend/api/tests/test_submission.py +++ b/backend/api/tests/test_submission.py @@ -9,6 +9,7 @@ from api.models.group import Group from api.models.course import Course from api.models.checks import ExtraCheck +from django.conf import settings def create_course(name, academic_startyear, description=None, parent_course=None): @@ -98,7 +99,7 @@ def test_submission_exists(self): # Assert the details of the retrieved submission # match the created submission retrieved_submission = content_json[0] - expected_group_url = "http://testserver" + reverse( + expected_group_url = settings.TESTING_BASE_LINK + reverse( "group-detail", args=[str(group.id)] ) self.assertEqual(int(retrieved_submission["id"]), submission.id) @@ -139,7 +140,7 @@ def test_multiple_submission_exists(self): # Assert the details of the retrieved submission # match the created submission retrieved_submission = content_json[0] - expected_group_url = "http://testserver" + reverse( + expected_group_url = settings.TESTING_BASE_LINK + reverse( "group-detail", args=[str(group.id)] ) self.assertEqual(int(retrieved_submission["id"]), submission1.id) @@ -150,7 +151,7 @@ def test_multiple_submission_exists(self): self.assertEqual(retrieved_submission["group"], expected_group_url) retrieved_submission = content_json[1] - expected_group_url = "http://testserver" + reverse( + expected_group_url = settings.TESTING_BASE_LINK + reverse( "group-detail", args=[str(group.id)] ) self.assertEqual(int(retrieved_submission["id"]), submission2.id) @@ -188,7 +189,7 @@ def test_submission_detail_view(self): # Assert the details of the retrieved submission # match the created submission retrieved_submission = content_json - expected_group_url = "http://testserver" + reverse( + expected_group_url = settings.TESTING_BASE_LINK + reverse( "group-detail", args=[str(group.id)] ) self.assertEqual(int(retrieved_submission["id"]), submission.id) @@ -241,7 +242,7 @@ def test_submission_group(self): # Parse the JSON content from the response content_json = json.loads(response.content.decode("utf-8")) - expected_project_url = "http://testserver" + reverse( + expected_project_url = settings.TESTING_BASE_LINK + reverse( "project-detail", args=[str(project.id)] ) diff --git a/backend/api/views/check_folder_structure.py b/backend/api/views/check_folder_structure.py index 3fec83bd..c85d0f63 100644 --- a/backend/api/views/check_folder_structure.py +++ b/backend/api/views/check_folder_structure.py @@ -9,7 +9,11 @@ def parseZipFile(project, dir_path): # TODO block paths that start with .. dir_path = os.path.normpath(os.path.join(settings.MEDIA_ROOT, dir_path)) struct = get_zip_structure(dir_path) - for key, value in struct.items(): + + sorted_keys = sorted(struct.keys()) + + for key in sorted_keys: + value = struct[key] check = StructureCheck.objects.create( name=key, project=project diff --git a/backend/ypovoli/settings.py b/backend/ypovoli/settings.py index 2fd97375..f06ed720 100644 --- a/backend/ypovoli/settings.py +++ b/backend/ypovoli/settings.py @@ -18,6 +18,8 @@ BASE_DIR = Path(__file__).resolve().parent.parent MEDIA_ROOT = os.path.normpath(os.path.join(BASE_DIR, "../data/production")) +TESTING_BASE_LINK = "http://testserver" + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/