Permalink
Browse files

Fixed error bundler param passing

There are still a lot of messages that get passed without keywords. This
adds support back in for those messages. All messages that pass more
recently added parameters (e.g.: tier, for_appversions, etc.) use
keywords to pass their values.
  • Loading branch information...
1 parent 4bd94e1 commit 82f3177cf3f9f0bba1327e6d7fc653b023166ccf @mattbasta committed Nov 14, 2012
Showing with 38 additions and 4 deletions.
  1. +27 −0 tests/test_errorbundler.py
  2. +11 −4 validator/errorbundler.py
View
@@ -1,13 +1,40 @@
import json
import nose
import sys
+from nose.tools import eq_
from StringIO import StringIO
import validator.errorbundler as errorbundler
from validator.errorbundler import ErrorBundle
from validator.contextgenerator import ContextGenerator
+def test_message_completeness():
+ """Test we're fully expecting all of the values for a message."""
+
+ bundle = ErrorBundle()
+
+ bundle.error(
+ ("id", ),
+ "error",
+ "description",
+ "file",
+ 123, # line
+ 456 # column
+ )
+
+ results = json.loads(bundle.render_json())
+ eq_(len(results["messages"]), 1, "Unexpected number of messages.")
+
+ message = results["messages"][0]
+ eq_(message["id"], ["id"])
+ eq_(message["message"], "error")
+ eq_(message["description"], "description")
+ eq_(message["file"], "file")
+ eq_(message["line"], 123)
+ eq_(message["column"], 456)
+
+
def test_json():
"""Test the JSON output capability of the error bundler."""
View
@@ -77,12 +77,19 @@ def __init__(self, determined=True, listed=True, instant=False,
def _message(type_, message_type):
def wrap(self, *args, **kwargs):
message = {
- "id": kwargs.get('err_id') or args[0],
+ "id": kwargs.get("err_id") or args[0],
"message": kwargs.get(message_type) or args[1],
- "file": kwargs.get("filename", "") # Filename is never None.
+ "description": kwargs.get("description",
+ args[2] if len(args) > 2 else None),
+ # Filename is never None.
+ "file": kwargs.get("filename",
+ args[3] if len(args) > 3 else ""),
+ "line": kwargs.get("line",
+ args[4] if len(args) > 4 else None),
+ "column": kwargs.get("column",
+ args[5] if len(args) > 5 else None),
}
- for field in ("description", "line", "column", "tier",
- "for_appversions", "compatibility_type"):
+ for field in ("tier", "for_appversions", "compatibility_type", ):
message[field] = kwargs.get(field)
self._save_message(getattr(self, type_), type_, message,

0 comments on commit 82f3177

Please sign in to comment.