From df77e107ec69be11646cf912b15f7b81c6fc4402 Mon Sep 17 00:00:00 2001 From: Tybo Verslype Date: Sat, 9 Mar 2024 22:03:38 +0100 Subject: [PATCH] chore: finished file_structure tests --- backend/api/tests/test_file_structure.py | 76 ++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/backend/api/tests/test_file_structure.py b/backend/api/tests/test_file_structure.py index 84b261af..7132d6a2 100644 --- a/backend/api/tests/test_file_structure.py +++ b/backend/api/tests/test_file_structure.py @@ -3,7 +3,7 @@ from django.utils import timezone from django.urls import reverse from rest_framework.test import APITestCase -from api.views.check_folder_structure import check_zip_content, parseZipFile +from api.views.check_folder_structure import checkZipFile, parseZipFile from api.models.checks import StructureCheck from api.models.extension import FileExtension from api.models.course import Course @@ -12,7 +12,6 @@ from django.conf import settings - def create_course(id, name, academic_startyear): """ Create a Course with the given arguments. @@ -22,11 +21,11 @@ def create_course(id, name, academic_startyear): ) -def create_fileExtension(id, extension): +def create_fileExtension(extension): """ Create a FileExtension with the given arguments. """ - return FileExtension.objects.create(id=id, extension=extension) + return FileExtension.objects.create(extension=extension) def create_project(name, description, visible, archived, days, course): @@ -72,7 +71,7 @@ def tearDown(self): # Restore the original MEDIA_ROOT after tests settings.MEDIA_ROOT = self.old_media_root - def test_your_function(self): + def test_your_parsing(self): course = create_course(id=3, name="test course", academic_startyear=2024) project = create_project( name="test", @@ -148,3 +147,70 @@ def test_your_function(self): self.assertEqual(content["project"], expected_project_url) self.assertEqual(len(content["obligated_extensions"]), 2) self.assertEqual(len(content["blocked_extensions"]), 0) + + def test_your_checking(self): + course = create_course(id=3, name="test course", academic_startyear=2024) + project = create_project( + name="test", + description="descr", + visible=True, + archived=False, + days=100, + course=course, + ) + + fileExtensionHS = create_fileExtension(extension="hs") + fileExtensionPDF = create_fileExtension(extension="pdf") + fileExtensionDOCX = create_fileExtension(extension="docx") + fileExtensionLATEX = create_fileExtension(extension="latex") + fileExtensionMD = create_fileExtension(extension="md") + fileExtensionPY = create_fileExtension(extension="py") + fileExtensionHPP = create_fileExtension(extension="hpp") + fileExtensionCPP = create_fileExtension(extension="cpp") + fileExtensionTS = create_fileExtension(extension="ts") + fileExtensionTSX = create_fileExtension(extension="tsx") + + create_structureCheck( + name=".", + project=project, + obligated=[], + blocked=[]) + + create_structureCheck( + name="folder_struct1", + project=project, + obligated=[fileExtensionHS], + blocked=[]) + + create_structureCheck( + name="folder_struct1/submap1", + project=project, + obligated=[fileExtensionPDF, fileExtensionDOCX], + blocked=[]) + + create_structureCheck( + name="folder_struct1/submap1/templates", + project=project, + obligated=[fileExtensionLATEX], + blocked=[]) + + create_structureCheck( + name="folder_struct1/submap2", + project=project, + obligated=[fileExtensionMD], + blocked=[]) + + create_structureCheck( + name="folder_struct1/submap2/src", + project=project, + obligated=[fileExtensionPY, fileExtensionHPP, fileExtensionCPP], + blocked=[]) + + create_structureCheck( + name="folder_struct1/submap3", + project=project, + obligated=[fileExtensionTS, fileExtensionTSX], + blocked=[]) + + succes = (True, 'zip.success') + self.assertEqual(checkZipFile(project=project, dir_path="structures/zip_struct1.zip"), succes)