Fix #241: 500 Error when submitting extension without "type" #242
@ -61,15 +61,19 @@ class CreateFileTest(TestCase):
|
||||
status=File.STATUSES.APPROVED,
|
||||
)
|
||||
|
||||
def _create_file_from_data(self, filename, file_data):
|
||||
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")
|
||||
|
||||
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':
|
||||
@ -312,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()
|
||||
}
|
||||
@ -723,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,
|
||||
|
@ -206,7 +206,7 @@ def validate_file_list(toml_content, manifest_filepath, file_list):
|
||||
'params': {'paths': ', '.join(found_forbidden_filepaths)},
|
||||
}
|
||||
)
|
||||
type_slug = toml_content['type']
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user