diff --git a/backend/api/fixtures/realistic/realistic.yaml b/backend/api/fixtures/realistic/realistic.yaml index f7664d29..3224250e 100644 --- a/backend/api/fixtures/realistic/realistic.yaml +++ b/backend/api/fixtures/realistic/realistic.yaml @@ -139,7 +139,7 @@ - model: api.structurecheck pk: 1 fields: - path: "verslag/" + path: "verslag" project: 0 obligated_extensions: - 3 @@ -147,7 +147,7 @@ - model: api.structurecheck pk: 2 fields: - path: src/ + path: src project: 1 obligated_extensions: - 1 @@ -156,7 +156,7 @@ - model: api.structurecheck pk: 3 fields: - path: verslag/ + path: verslag project: 1 obligated_extensions: - 3 diff --git a/backend/api/logic/parse_zip_files.py b/backend/api/logic/parse_zip_files.py index cc21f531..9ec68de3 100644 --- a/backend/api/logic/parse_zip_files.py +++ b/backend/api/logic/parse_zip_files.py @@ -24,7 +24,7 @@ def parse_zip(project: Project, zip_file: InMemoryUploadedFile) -> bool: if common_prefix[-1] != '/': prefixes = prefixes[:-1] - directories += [prefix + '/' for prefix in prefixes] + directories += [f"{prefix}/" for prefix in prefixes] # Add for each directory a structure check for directory in directories: @@ -41,7 +41,7 @@ def parse_zip(project: Project, zip_file: InMemoryUploadedFile) -> bool: def create_check(project: Project, directory_path: str, files: list[str]): check = StructureCheck.objects.create( - path=directory_path, + path=directory_path[:-1], project=project ) diff --git a/backend/api/tasks/structure_check.py b/backend/api/tasks/structure_check.py index d22cd866..8d7cdaac 100644 --- a/backend/api/tasks/structure_check.py +++ b/backend/api/tasks/structure_check.py @@ -89,4 +89,4 @@ def _get_all_name_ext(path: str) -> dict[str, str]: with zipfile.ZipFile(zip_data, 'r') as inner_zip: file_list = inner_zip.namelist() - return {file: file.split('.')[-1] for file in file_list} + return {'/'.join(file.split('/')[:-1]): file.split('.')[-1] for file in file_list} diff --git a/backend/api/tests/test_file_structure.py b/backend/api/tests/test_file_structure.py index be463dee..ad484acd 100644 --- a/backend/api/tests/test_file_structure.py +++ b/backend/api/tests/test_file_structure.py @@ -56,37 +56,37 @@ def test_parsing(self): ) content = content_json[0] - self.assertEqual(content["path"], "folder_struct1/submap1/") + self.assertEqual(content["path"], "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[1] - self.assertEqual(content["path"], "folder_struct1/submap1/templates/") + self.assertEqual(content["path"], "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[2] - self.assertEqual(content["path"], "folder_struct1/submap2/") + self.assertEqual(content["path"], "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[3] - self.assertEqual(content["path"], "folder_struct1/submap2/src/") + self.assertEqual(content["path"], "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[4] - self.assertEqual(content["path"], "folder_struct1/submap3/") + self.assertEqual(content["path"], "folder_struct1/submap3") self.assertEqual(content["project"], expected_project_url) self.assertEqual(len(content["obligated_extensions"]), 2) self.assertEqual(len(content["blocked_extensions"]), 0) content = content_json[5] - self.assertEqual(content["path"], "folder_struct1/") + self.assertEqual(content["path"], "folder_struct1") self.assertEqual(content["project"], expected_project_url) self.assertEqual(len(content["obligated_extensions"]), 1) self.assertEqual(len(content["blocked_extensions"]), 0)