Example #1
0
def _do_test(url, failure=True):
    
    xml_file = open(url)
    data = xml_file.read()
    wrapper = StringIO(data)
    
    results = typedetection.detect_opensearch(wrapper)
    
    if results["error"]:
        print results["error"]
    
    if failure:
        assert results["failure"]
    else:
        assert not results["failure"]
Example #2
0
def test_search(err, package, expectation=0):
    "Tests the package to see if it is a search provider."

    expected_search_provider = expectation in (PACKAGE_ANY,
                                               PACKAGE_SEARCHPROV)

    # If we're not expecting a search provider, warn the user and stop
    # testing it like a search provider.
    if not expected_search_provider:
        err.reject = True
        return err.warning(("main",
                            "test_search",
                            "extension"),
                           "Unexpected file extension.")
                           
    # Is this a search provider?
    opensearch_results = detect_opensearch(package)
    
    if opensearch_results["failure"]:
        # Failed OpenSearch validation
        error_mesg = "OpenSearch: %s" % opensearch_results["error"]
        err.error(("main",
                   "test_search",
                   "general_failure"),
                  error_mesg)

        # We want this to flow back into the rest of the program if
        # the error indicates that we're not sure whether it's an
        # OpenSearch document or not.

        if not "decided" in opensearch_results or \
           opensearch_results["decided"]:
            err.reject = True
            return err

    elif expected_search_provider:
        err.set_type(PACKAGE_SEARCHPROV)
        err.info(("main",
                  "test_search",
                  "confirmed"),
                 "OpenSearch provider confirmed.")

    return err
Example #3
0
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"]