diff --git a/extensions/tests/test_manifest.py b/extensions/tests/test_manifest.py index 4e38ce21..22f24d96 100644 --- a/extensions/tests/test_manifest.py +++ b/extensions/tests/test_manifest.py @@ -47,7 +47,7 @@ class CreateFileTest(TestCase): "id": "blender_kitsu", "version": "0.1.5", } - self.file = self._create_file_from_data("blender_kitsu_1.5.0.zip", file_data, self.user) + self.file = self._create_file_from_data("blender_kitsu_1.5.0.zip", file_data) def tearDown(self): super().tearDown() @@ -61,15 +61,19 @@ class CreateFileTest(TestCase): status=File.STATUSES.APPROVED, ) - def _create_file_from_data(self, filename, file_data, user): + def _create_file_from_data(self, filename, file_data, use_meta_data=True): output_path = os.path.join(self.temp_directory, filename) manifest_path = os.path.join(self.temp_directory, "blender_manifest.toml") - combined_meta_data = META_DATA.copy() - combined_meta_data.update(file_data) + + if use_meta_data: + combined_meta_data = META_DATA.copy() + combined_meta_data.update(file_data) + else: + combined_meta_data = file_data version = combined_meta_data.get("version", "0.1.0") extension_id = combined_meta_data.get("id", "foobar").strip() - type_slug = combined_meta_data['type'] + type_slug = combined_meta_data.get('type') init_path = None if type_slug == 'add-on': @@ -105,7 +109,7 @@ class ValidateManifestTest(CreateFileTest): "id": "id-with-hyphens", } - bad_file = self._create_file_from_data("theme.zip", file_data, self.user) + bad_file = self._create_file_from_data("theme.zip", file_data) with open(bad_file, 'rb') as fp: response = self.client.post(self.submit_url, {'source': fp, 'agreed_with_terms': True}) @@ -123,7 +127,7 @@ class ValidateManifestTest(CreateFileTest): "id": "id with spaces", } - bad_file = self._create_file_from_data("theme.zip", file_data, self.user) + bad_file = self._create_file_from_data("theme.zip", file_data) with open(bad_file, 'rb') as fp: response = self.client.post(self.submit_url, {'source': fp, 'agreed_with_terms': True}) @@ -146,7 +150,7 @@ class ValidateManifestTest(CreateFileTest): "version": "0.1.5", } - extension_file = self._create_file_from_data("theme.zip", kitsu_1_5, self.user) + extension_file = self._create_file_from_data("theme.zip", kitsu_1_5) with open(extension_file, 'rb') as fp: response = self.client.post(self.submit_url, {'source': fp, 'agreed_with_terms': True}) @@ -170,7 +174,7 @@ class ValidateManifestTest(CreateFileTest): "version": "0.1.5", } - extension_file = self._create_file_from_data("theme.zip", kitsu_1_5, self.user) + extension_file = self._create_file_from_data("theme.zip", kitsu_1_5) with open(extension_file, 'rb') as fp: response = self.client.post(self.submit_url, {'source': fp, 'agreed_with_terms': True}) @@ -194,7 +198,7 @@ class ValidateManifestTest(CreateFileTest): "version": "0.1.6", } - extension_file = self._create_file_from_data("theme.zip", non_kitsu_1_6, self.user) + extension_file = self._create_file_from_data("theme.zip", non_kitsu_1_6) with open(extension_file, 'rb') as fp: response = self.client.post( version.extension.get_new_version_url(), {'source': fp, 'agreed_with_terms': True} @@ -221,9 +225,7 @@ class ValidateManifestTest(CreateFileTest): "version": version.version, } - extension_file = self._create_file_from_data( - "kitsu_clash.zip", kitsu_version_clash, self.user - ) + extension_file = self._create_file_from_data("kitsu_clash.zip", kitsu_version_clash) with open(extension_file, 'rb') as fp: response = self.client.post( version.extension.get_new_version_url(), {'source': fp, 'agreed_with_terms': True} @@ -262,7 +264,7 @@ class ValidateManifestTest(CreateFileTest): "version": '0.1.6', } - extension_file = self._create_file_from_data("updated_kitsu.zip", updated_kitsu, self.user) + extension_file = self._create_file_from_data("updated_kitsu.zip", updated_kitsu) with open(extension_file, 'rb') as fp: response = self.client.post( version.extension.get_new_version_url(), {'source': fp, 'agreed_with_terms': True} @@ -284,7 +286,7 @@ class ValidateManifestTest(CreateFileTest): "id": "id-with-hyphens", } - bad_file = self._create_file_from_data("theme.zip", file_data, self.user) + bad_file = self._create_file_from_data("theme.zip", file_data) with open(bad_file, 'rb') as fp: response = self.client.post(self.submit_url, {'source': fp, 'agreed_with_terms': True}) @@ -303,7 +305,7 @@ class ValidateManifestTest(CreateFileTest): "name": "Name. - With Extra spaces and other characters Ж", } - extension_file = self._create_file_from_data("theme.zip", file_data, self.user) + extension_file = self._create_file_from_data("theme.zip", file_data) with open(extension_file, 'rb') as fp: response = self.client.post(self.submit_url, {'source': fp, 'agreed_with_terms': True}) @@ -314,10 +316,12 @@ class ValidateManifestTest(CreateFileTest): self.assertEqual(extension.name, 'Name. - With Extra spaces and other characters Ж') -class ValidateManifestFields(TestCase): +class ValidateManifestFields(CreateFileTest): fixtures = ['licenses', 'version_permissions'] def setUp(self): + super().setUp() + self.mandatory_fields = { key: item.example for (key, item) in ManifestValidator.mandatory_fields.items() } @@ -725,6 +729,27 @@ class ValidateManifestFields(TestCase): ManifestValidator(data) self.assertEqual(1, len(e.exception.messages)) + def test_type_missing(self): + user = UserFactory() + self.client.force_login(user) + + file_data = { + **self.mandatory_fields, + **self.optional_fields, + } + del file_data['type'] + del file_data['build'] + del file_data['wheels'] + + bad_file = self._create_file_from_data("extension.zip", file_data, use_meta_data=False) + with open(bad_file, 'rb') as fp: + response = self.client.post(self.submit_url, {'source': fp, 'agreed_with_terms': True}) + + self.assertEqual(response.status_code, 200) + error = response.context['form'].errors.get('source')[0] + self.assertIn("missing", error) + self.assertIn("type", error) + def test_schema_version(self): data = { **self.mandatory_fields, @@ -782,7 +807,7 @@ class VersionPermissionsTest(CreateFileTest): } # Step 1: submit the file - extension_file = self._create_file_from_data("kitsu-0.1.6.zip", new_kitsu, self.user) + extension_file = self._create_file_from_data("kitsu-0.1.6.zip", new_kitsu) with open(extension_file, 'rb') as fp: response = self.client.post( extension.get_new_version_url(), {'source': fp, 'agreed_with_terms': True} diff --git a/files/utils.py b/files/utils.py index 318cfe55..60a57459 100644 --- a/files/utils.py +++ b/files/utils.py @@ -21,7 +21,13 @@ import clamd import magic import requests -from constants.base import THUMBNAIL_FORMAT, THUMBNAIL_SIZES, THUMBNAIL_QUALITY +from constants.base import ( + EXTENSION_TYPE_CHOICES, + EXTENSION_TYPE_SLUGS_SINGULAR, + THUMBNAIL_FORMAT, + THUMBNAIL_SIZES, + THUMBNAIL_QUALITY, +) logger = logging.getLogger(__name__) FORBIDDEN_FILEPATHS = [ @@ -200,14 +206,14 @@ def validate_file_list(toml_content, manifest_filepath, file_list): 'params': {'paths': ', '.join(found_forbidden_filepaths)}, } ) - type_slug = toml_content['type'] - if type_slug == 'theme': + type_slug = toml_content.get('type') + if type_slug == EXTENSION_TYPE_SLUGS_SINGULAR[EXTENSION_TYPE_CHOICES.THEME]: theme_xmls = filter_paths_by_ext(file_list, '.xml') # Special treatment for Mac, so the same problem (__MACOSX folders) # doesn't lead to two errors showing. if len(list(theme_xmls)) != 1 and '__MACOSX/' not in found_forbidden_filepaths: error_codes.append('missing_or_multiple_theme_xml') - elif type_slug == 'add-on': + elif type_slug == EXTENSION_TYPE_SLUGS_SINGULAR[EXTENSION_TYPE_CHOICES.BPY]: # __init__.py is expected to be next to the manifest expected_init_path = _canonical_path('__init__.py', manifest_filepath) init_filepath = find_exact_path(file_list, expected_init_path)