[extensions-web] extensions: Error out for a missing metadata.json
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] extensions: Error out for a missing metadata.json
- Date: Sat, 3 Mar 2012 11:16:45 +0000 (UTC)
commit d61b5ebf5dec94117bf12d5de36b12c0dd30017c
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sat Mar 3 05:33:39 2012 -0500
extensions: Error out for a missing metadata.json
sweettooth/extensions/models.py | 4 ++--
.../extensions/testdata/NoMetadata/NoMetadata.zip | Bin 0 -> 203 bytes
sweettooth/extensions/testdata/NoMetadata/bogus | 1 +
sweettooth/extensions/tests.py | 5 +++++
4 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index d107134..4d8cad1 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -254,8 +254,8 @@ def parse_zipfile_metadata(uploaded_file):
try:
metadata = json.load(zipfile.open('metadata.json', 'r'))
except KeyError:
- # no metadata.json in archive, return nothing
- metadata = {}
+ # no metadata.json in archive, raise error
+ raise InvalidExtensionData("Missing metadata.json")
except ValueError:
# invalid JSON file, raise error
raise InvalidExtensionData("Invalid JSON data")
diff --git a/sweettooth/extensions/testdata/NoMetadata/NoMetadata.zip b/sweettooth/extensions/testdata/NoMetadata/NoMetadata.zip
new file mode 100644
index 0000000..ee88d98
Binary files /dev/null and b/sweettooth/extensions/testdata/NoMetadata/NoMetadata.zip differ
diff --git a/sweettooth/extensions/testdata/NoMetadata/bogus b/sweettooth/extensions/testdata/NoMetadata/bogus
new file mode 100644
index 0000000..8d70d9b
--- /dev/null
+++ b/sweettooth/extensions/testdata/NoMetadata/bogus
@@ -0,0 +1 @@
+Other junk that's not a metadata.json file.
\ No newline at end of file
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index 2091598..76b1083 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -79,6 +79,11 @@ class ParseZipfileTest(BasicUserTestCase, TestCase):
models.parse_zipfile_metadata(f)
self.assertEquals(cm.exception.message, "Zip file is too large")
+ with get_test_zipfile('NoMetadata') as f:
+ with self.assertRaises(models.InvalidExtensionData) as cm:
+ models.parse_zipfile_metadata(f)
+ self.assertEquals(cm.exception.message, "Missing metadata.json")
+
class ReplaceMetadataTest(BasicUserTestCase, TestCase):
@expectedFailure
def test_replace_metadata(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]