Permalink
Browse files

Merge pull request #20 from mattbasta/opensearch.

Bug 634052 - Fix to ensure that OpenSearch providers show all errors
  • Loading branch information...
2 parents 346df70 + fc89fe5 commit 6cc99e08adb32fcab39775db4296dfdf75593b21 @mattbasta committed May 2, 2011
Showing with 319 additions and 249 deletions.
  1. +61 −59 tests/test_opensearch.py
  2. +23 −23 tests/test_submain_install_rdf.py
  3. +230 −0 validator/opensearch.py
  4. +5 −26 validator/submain.py
  5. +0 −141 validator/typedetection.py
View
@@ -2,32 +2,34 @@
from StringIO import StringIO
-import validator.typedetection as typedetection
+from validator.opensearch import detect_opensearch
import validator.submain as submain
from validator.errorbundler import ErrorBundle
from validator.constants import *
def _do_test(url, failure=True, listed=False):
-
+
xml_file = open(url)
data = xml_file.read()
wrapper = StringIO(data)
-
- results = typedetection.detect_opensearch(wrapper, listed=listed)
-
- if results["error"]:
- print results["error"]
-
+
+ err = ErrorBundle()
+
+ results = detect_opensearch(err, wrapper, listed=listed)
+
+ if results.failed():
+ print results.print_summary()
+
if failure:
- assert results["failure"]
+ assert err.failed()
else:
- assert not results["failure"]
-
+ assert not err.failed()
+
def test_opensearch():
"Tests that the OpenSearch detection is working."
-
+
_do_test("tests/resources/searchprovider/pass.xml", False)
-
+
def test_missing_xmlns():
"Tests that an xmlns attribute is present."
@@ -40,35 +42,36 @@ def test_bad_xmlns():
def test_nonparsing_xml():
"""Tests that a failure is generated for bad XML on OpenSearch"""
-
- output = typedetection.detect_opensearch("foo/bar/_asdf")
- assert output["failure"]
-
+
+ err = ErrorBundle()
+ detect_opensearch(err, "foo/bar/_asdf")
+ assert err.failed()
+
def test_broken_updateURL():
"Tests that there isn't an updateURL element in the provider."
-
+
_do_test("tests/resources/searchprovider/sp_updateurl.xml")
-
+
def test_broken_notos():
"Tests that the provider is indeed OpenSearch."
-
+
_do_test("tests/resources/searchprovider/sp_notos.xml")
-
+
def test_broken_shortname():
"Tests that the provider has a <ShortName> element."
-
+
_do_test("tests/resources/searchprovider/sp_no_shortname.xml")
_do_test("tests/resources/searchprovider/sp_dup_shortname.xml")
_do_test("tests/resources/searchprovider/sp_long_shortname.xml")
-
+
def test_broken_description():
"Tests that the provider has a <Description> element."
-
+
_do_test("tests/resources/searchprovider/sp_no_description.xml")
-
+
def test_broken_url():
"Tests that the provider has a <Url> element."
-
+
_do_test("tests/resources/searchprovider/sp_no_url.xml")
def test_rel_self_url():
@@ -79,66 +82,65 @@ def test_rel_self_url():
def test_broken_url_attributes():
"Tests that the provider is passing the proper attributes for its urls."
-
+
_do_test("tests/resources/searchprovider/sp_bad_url_atts.xml")
-
+
def test_broken_url_searchterms():
"Tests that a search term field is provided for the <Url> element."
-
+
_do_test("tests/resources/searchprovider/sp_no_url_template.xml")
-
+
def test_broken_url_searchterms_inline():
"Tests that a valid inline search term field is provided."
-
+
_do_test("tests/resources/searchprovider/sp_inline_template.xml", False)
-
+
def test_broken_url_searchterms_param():
"Tests that a valid search term field is provided in a <Param />"
-
+
_do_test("tests/resources/searchprovider/sp_param_template.xml", False)
-
+
def test_broken_url_searchterms_param_atts():
"Tests that necessary attributes are provided in a <Param />"
-
+
_do_test("tests/resources/searchprovider/sp_bad_param_atts.xml")
-
+
def test_search_pass():
"Tests the submain test_search function with passing data."
-
- err = ErrorBundle(None, True)
- submain.detect_opensearch = lambda x, listed: {"failure":False}
+
+ err = ErrorBundle()
+ submain.detect_opensearch = lambda err, x, listed: err
submain.test_search(err, None, PACKAGE_ANY)
-
+
assert not err.failed()
-
+
def test_search_bad_type():
"Tests the submain test_search function with a bad package type."
-
- err = ErrorBundle(None, True)
- submain.detect_opensearch = lambda x, listed: {"failure":False}
+
+ err = ErrorBundle()
+ submain.detect_opensearch = lambda err, x, listed: err
submain.test_search(err, None, PACKAGE_THEME)
-
+
assert err.failed()
-
+
def test_search_failure():
"Tests the submain test_search function with a failure"
-
- err = ErrorBundle(None, True)
- submain.detect_opensearch = lambda x, listed: {"failure":True,
- "error":""}
+
+ err = ErrorBundle()
+ submain.detect_opensearch = lambda err, x, listed: err.error(("foo", ),
+ "Test")
submain.test_search(err, None, PACKAGE_ANY)
-
+
assert err.failed()
-
+
def test_search_failure_undecided():
"Tests the submain test_search function with an unrejected fail case"
-
- err = ErrorBundle(None, True)
- submain.detect_opensearch = lambda x, listed: {"failure":True,
- "error":"",
- "decided":False}
+
+ err = ErrorBundle()
+ submain.detect_opensearch = lambda err, x, listed: err.error(("foo", ),
+ "Test")
submain.test_search(err, None, PACKAGE_ANY)
-
+
assert err.failed()
-
+
@@ -6,66 +6,66 @@
from validator.constants import *
def _run_test(filename, expectation, should_fail=True):
-
+
name = "tests/resources/submain/%s" % filename
pack = open(name)
xpi = XPIManager(pack, name)
err = ErrorBundle(None, True)
-
+
submain._load_install_rdf(err, xpi, expectation)
-
+
if should_fail:
assert err.failed()
else:
assert not err.failed()
assert err.get_resource("install_rdf")
-
+
return err
def test_load_irdf_pass():
"Test that the loader works with a normal install.rdf file"
-
- dt = submain.typedetection.detect_type
- submain.typedetection.detect_type = lambda x, y, z: PACKAGE_ANY
+
+ dt = submain.detect_type
+ submain.detect_type = lambda x, y, z: PACKAGE_ANY
_run_test("install_rdf.xpi", PACKAGE_ANY, False)
- submain.typedetection.detect_type = dt
+ submain.detect_type = dt
def test_load_irdf_unparsable():
"Tests that the loader fails when the install.rdf is corrupt."
-
+
_run_test("install_rdf_unparsable.xpi", None)
def test_load_irdf_no_type():
"Tests that the loader fails when the type detection fails."
-
- dt = submain.typedetection.detect_type
- submain.typedetection.detect_type = lambda x, y, z: None
+
+ dt = submain.detect_type
+ submain.detect_type = lambda x, y, z: None
_run_test("install_rdf.xpi", PACKAGE_ANY)
- submain.typedetection.detect_type = dt
+ submain.detect_type = dt
def test_load_irdf_correct_type():
"Tests that the loader passes with valid type detection."
-
- dt = submain.typedetection.detect_type
- submain.typedetection.detect_type = lambda x, y, z: PACKAGE_THEME
+
+ dt = submain.detect_type
+ submain.detect_type = lambda x, y, z: PACKAGE_THEME
err = _run_test("install_rdf.xpi", PACKAGE_ANY, False)
- submain.typedetection.detect_type = dt
-
+ submain.detect_type = dt
+
assert err.detected_type == PACKAGE_THEME
def test_load_irdf_expectation():
"Tests that the loader fails with an invalid expectation."
-
- dt = submain.typedetection.detect_type
- submain.typedetection.detect_type = lambda x, y, z: PACKAGE_THEME
+
+ dt = submain.detect_type
+ submain.detect_type = lambda x, y, z: PACKAGE_THEME
_run_test("install_rdf.xpi", PACKAGE_EXTENSION, True)
- submain.typedetection.detect_type = dt
-
+ submain.detect_type = dt
+
def test_doctype():
"Asserts that install.rdf files with doctypes break validation"
Oops, something went wrong.

0 comments on commit 6cc99e0

Please sign in to comment.