Permalink
Browse files

Put the manifest in the validator output.

  • Loading branch information...
mattbasta committed Nov 21, 2012
1 parent 7864e86 commit 81f7bd56118f439f293f1152499867a448fc486a
@@ -1,8 +1,9 @@
from basebundle import BaseErrorBundle
+from manifestmixin import ManifestMixin
from metadatamixin import MetadataMixin
-class ErrorBundle(MetadataMixin, BaseErrorBundle):
+class ErrorBundle(MetadataMixin, ManifestMixin, BaseErrorBundle):
def __init__(self, listed=True, spidermonkey=None, *args, **kwargs):
super(ErrorBundle, self).__init__(*args, **kwargs)
@@ -1,9 +1,10 @@
-import json
import sys
import types
import uuid
from StringIO import StringIO
+import simplejson as json

This comment has been minimized.

Show comment Hide comment
@cvan

cvan Nov 22, 2012

Contributor

why?

@cvan

cvan Nov 22, 2012

Contributor

why?

+
from .outputhandlers.shellcolors import OutputHandler
from .. import unicodehelper
@@ -132,7 +133,11 @@ def render_json(self):
output.update(self._extend_json())
# Output the JSON.
- return json.dumps(output)
+ return json.dumps(output, ensure_ascii=True)
+
+ def _extend_json(self):
+ """Override this method to extend the JSON produced by the bundle."""
+ pass
def print_summary(self, verbose=False, no_color=False):
"Prints a summary of the validation process so far."
@@ -0,0 +1,12 @@
+
+class ManifestMixin(object):
+ """This mixin adds the manifest to the final JSON output. The manifest
+ should be stored in the resources under the name "manifest" as a dict.
+
+ """
+
+ def _extend_json(self):
+ """Output the manifest as part of the main JSON blob."""
+ extension = super(ManifestMixin, self)._extend_json() or {}
+ extension.update(manifest=self.get_resource("manifest"))
+ return extension
@@ -36,4 +36,6 @@ def save_resource(self, name, resource, pushable=False):
def _extend_json(self):
"""Output the metadata as part of the main JSON blob."""
- return {"metadata": self.metadata}
+ extension = super(MetadataMixin, self)._extend_json() or {}
+ extension.update(metadata=self.metadata)
+ return extension
View
@@ -1,6 +1,6 @@
import simplejson as json
-from unicodehelper import decode
+import unicodehelper
from .specs.webapps import WebappSpec
@@ -13,12 +13,13 @@ def detect_webapp(err, package):
def detect_webapp_string(err, data):
- """
- Parse and validate a webapp based on the string version of the provided
+ """Parse and validate a webapp based on the string version of the provided
manifest.
+
"""
+
try:
- u_data = decode(data)
+ u_data = unicodehelper.decode(data)
webapp = json.loads(u_data)
except ValueError:
return err.error(
@@ -32,19 +33,23 @@ def detect_webapp_string(err, data):
def detect_webapp_raw(err, webapp):
- """
- Parse and validate a webapp based on the dict version of the manifest.
+ """Parse and validate a webapp based on the dict version of the manifest.
+
"""
- from .specs.webapps import WebappSpec
ws = WebappSpec(webapp, err)
ws.validate()
# This magic number brought to you by @cvan (see bug 770755)
- if "name" in webapp and len(webapp["name"]) > 9:
+ # Updated 11/21/12: Bumped to 12 because Gaia is different.

This comment has been minimized.

Show comment Hide comment
@cvan

cvan Nov 22, 2012

Contributor

"is different"? or has changed?

@cvan

cvan Nov 22, 2012

Contributor

"is different"? or has changed?

This comment has been minimized.

Show comment Hide comment
@mattbasta

mattbasta Nov 22, 2012

Owner

Changed

+ if "name" in webapp and len(webapp["name"]) > 12:
err.warning(
- err_id=("webapp", "b2g", "name_truncated"),
- warning="App name may be truncated on Firefox OS devices.",
- description="Your app's name is long enough to possibly be "
- "truncated on Firefox OS devices. Consider using "
- "a shorter name for your app.")
+ err_id=("webapp", "b2g", "name_truncated"),
+ warning="App name may be truncated on Firefox OS devices.",
+ description="Your app's name is long enough to possibly be "
+ "truncated on Firefox OS devices. Consider using a "
+ "shorter name for your app.")

This comment has been minimized.

Show comment Hide comment
@cvan

cvan Nov 22, 2012

Contributor

we should probably just tell them how long it should be.

@cvan

cvan Nov 22, 2012

Contributor

we should probably just tell them how long it should be.

+
+ # If the manifest is still good, save it

This comment has been minimized.

Show comment Hide comment
@cvan

cvan Nov 22, 2012

Contributor

period.

@cvan

cvan Nov 22, 2012

Contributor

period.

+ if not err.failed(fail_on_warnings=False):
+ err.save_resource("manifest", webapp)
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+from nose.tools import eq_
+
+from test_errorbundler import ErrorBundleTestCase
+
+
+class TestManifestMixin(ErrorBundleTestCase):
+
+ def test_manifest(self):
+ self.err.save_resource("manifest", {"foo": "bar"})
+
+ results = self.get_json_results()
+ assert "manifest" in results, results.keys()

This comment has been minimized.

Show comment Hide comment
@cvan

cvan Nov 22, 2012

Contributor

could you remove this, since you're checking it below?

@cvan

cvan Nov 22, 2012

Contributor

could you remove this, since you're checking it below?

+ eq_(results["manifest"]["foo"], "bar")
+
+ def test_manifest_unicode(self):

This comment has been minimized.

Show comment Hide comment
@cvan

cvan Nov 22, 2012

Contributor

that's the only unicode test?

@cvan

cvan Nov 22, 2012

Contributor

that's the only unicode test?

+ self.err.save_resource("manifest", {"foo": u"bär"})
+
+ results = self.get_json_results()
+ assert "manifest" in results, results.keys()
+ eq_(results["manifest"]["foo"], u"bär")
View
@@ -7,19 +7,22 @@
from helper import TestCase
-from appvalidator.errorbundle import ErrorBundle
from appvalidator.contextgenerator import ContextGenerator
+from appvalidator.errorbundle import ErrorBundle
-class TestErrorBundle(TestCase):
+class ErrorBundleTestCase(TestCase):
def setUp(self):
- super(TestErrorBundle, self).setUp()
+ super(ErrorBundleTestCase, self).setUp()
self.setup_err()
def get_json_results(self):
return json.loads(self.err.render_json())
+
+class TestErrorBundle(ErrorBundleTestCase):
+
def test_message_completeness(self):
"""Test we're fully expecting all of the values for a message."""
@@ -65,8 +68,6 @@ def test_boring(self):
self.err.error((), "<<BLUE>><<GREEN>><<YELLOW>>")
self.err.print_summary(no_color=True)
-
- sys.stdout.seek(0)
eq_(sys.stdout.getvalue().count("<<GREEN>>"), 0)
def test_file_structure(self):
@@ -3,7 +3,7 @@
import appvalidator.unicodehelper as unicodehelper
-COMPARISON = "täst".decode("utf-8")
+COMPARISON = u"täst"
def _do_test(path):
"Performs a test on a JS file"
View
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-import json
import os
import tempfile
import types
+import simplejson as json
from nose.tools import eq_
from helper import TestCase
@@ -111,6 +111,9 @@ def test_pass(self):
self.analyze()
self.assert_silent()
+ output = json.loads(self.err.render_json())
+ assert "manifest" in output and output["manifest"]

This comment has been minimized.

Show comment Hide comment
@cvan

cvan Nov 22, 2012

Contributor

why all the verbosity?

@cvan

cvan Nov 22, 2012

Contributor

why all the verbosity?

+
def test_bom(self):
"""Test that a plain webapp with a BOM won't throw errors."""
self.setup_err()

0 comments on commit 81f7bd5

Please sign in to comment.