Skip to content

Commit

Permalink
chore: finished file_structure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyboro2002 committed Mar 9, 2024
1 parent 3da961a commit df77e10
Showing 1 changed file with 71 additions and 5 deletions.
76 changes: 71 additions & 5 deletions backend/api/tests/test_file_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,7 +12,6 @@
from django.conf import settings



def create_course(id, name, academic_startyear):
"""
Create a Course with the given arguments.
Expand All @@ -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):
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)

0 comments on commit df77e10

Please sign in to comment.