Extra validation of the uploaded ZIP #73
@ -1,6 +1,6 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from files.utils import find_path_by_name, find_full_path, filter_paths_by_ext
|
||||
from files.utils import find_path_by_name, find_exact_path, filter_paths_by_ext
|
||||
|
||||
|
||||
class UtilsTest(TestCase):
|
||||
@ -50,7 +50,7 @@ class UtilsTest(TestCase):
|
||||
manifest_file = find_path_by_name(name_list, self.manifest)
|
||||
self.assertEqual(manifest_file, None)
|
||||
|
||||
def test_find_full_path_found(self):
|
||||
def test_find_exact_path_found(self):
|
||||
name_list = [
|
||||
'foobar-1.0.3/theme.xml',
|
||||
'foobar-1.0.3/theme1.xml',
|
||||
@ -60,10 +60,10 @@ class UtilsTest(TestCase):
|
||||
'foobar-1.0.3/foobar-1.0.3/__init__.py',
|
||||
'blender_manifest.toml',
|
||||
]
|
||||
path = find_full_path(name_list, 'foobar-1.0.3', '__init__.py')
|
||||
path = find_exact_path(name_list, 'foobar-1.0.3/__init__.py')
|
||||
self.assertEqual(path, 'foobar-1.0.3/__init__.py')
|
||||
|
||||
def test_find_full_path_nothing_found(self):
|
||||
def test_find_exact_path_nothing_found(self):
|
||||
name_list = [
|
||||
'foobar-1.0.3/theme.xml',
|
||||
'foobar-1.0.3/theme1.xml',
|
||||
@ -72,7 +72,7 @@ class UtilsTest(TestCase):
|
||||
'foobar-1.0.3/foobar-1.0.3/__init__.py',
|
||||
'blender_manifest.toml',
|
||||
]
|
||||
path = find_full_path(name_list, 'foobar-1.0.3', '__init__.py')
|
||||
path = find_exact_path(name_list, 'foobar-1.0.3/__init__.py')
|
||||
self.assertIsNone(path)
|
||||
|
||||
def test_filter_paths_by_ext_found(self):
|
||||
|
@ -61,11 +61,9 @@ def find_path_by_name(paths: typing.List[str], name: str) -> typing.Optional[str
|
||||
return None
|
||||
|
||||
|
||||
def find_full_path(
|
||||
paths: typing.List[str], *full_path_components: typing.List[str]
|
||||
) -> typing.Optional[str]:
|
||||
"""Return a path equal given path components if it exists in a given list of paths."""
|
||||
matching_paths = (path for path in paths if path == os.path.join(*full_path_components))
|
||||
def find_exact_path(paths: typing.List[str], exact_path: str) -> typing.Optional[str]:
|
||||
"""Return a first path equal to a given one if it exists in a given list of paths."""
|
||||
matching_paths = (path for path in paths if path == exact_path)
|
||||
return next(matching_paths, None)
|
||||
|
||||
|
||||
@ -128,8 +126,8 @@ def read_manifest_from_zip(archive_path):
|
||||
error_codes.append('invalid_theme_multiple_xmls')
|
||||
elif type_slug == 'add-on':
|
||||
# __init__.py is expected to be next to the manifest
|
||||
init_directory = os.path.dirname(manifest_filepath)
|
||||
init_filepath = find_full_path(file_list, init_directory, '__init__.py')
|
||||
expected_init_path = os.path.join(os.path.dirname(manifest_filepath), '__init__.py')
|
||||
init_filepath = find_exact_path(file_list, expected_init_path)
|
||||
if not init_filepath:
|
||||
error_codes.append('invalid_missing_init')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user