def test_validate_libs_in_compat_mode(): xpi = "tests/resources/libraryblacklist/addon_with_mootools.xpi" with open(xpi) as data: package = XPIManager(data, mode="r", name="addon_with_mootools.xpi") err = ErrorBundle(for_appversions=FX9_DEFINITION) test_content.test_packed_packages(err, package) assert err.get_resource("scripts"), "expected mootools scripts to be marked for proessing" eq_(err.get_resource("scripts")[0]["scripts"], set(["content/mootools.js"]))
def test_doctype(): "Asserts that install.rdf files with doctypes break validation" err = ErrorBundle() xpi = MockXPIManager( {"install.rdf": "tests/resources/installrdf/doctype.rdf"}) submain._load_install_rdf(err, xpi, None) assert err.failed() assert not err.get_resource("has_install_rdf") assert not err.get_resource("install_rdf")
def test_validate_libs_in_compat_mode(): xpi = "tests/resources/libraryblacklist/addon_with_mootools.xpi" with open(xpi) as data: package = XPIManager(data, mode="r", name="addon_with_mootools.xpi") err = ErrorBundle(for_appversions=FX9_DEFINITION) test_content.test_packed_packages(err, package) assert err.get_resource("scripts"), ( "expected mootools scripts to be marked for proessing") eq_( err.get_resource("scripts")[0]["scripts"], set(["content/mootools.js"]))
def test_validate_libs_in_compat_mode(): xpi = 'tests/resources/libraryblacklist/addon_with_mootools.xpi' with open(xpi) as data: package = XPIManager(data, mode='r', name='addon_with_mootools.xpi') appversions = {FIREFOX_GUID: version_range('firefox', '39.0a1', '39.*')} err = ErrorBundle(for_appversions=appversions) test_content.test_packed_packages(err, package) assert err.get_resource('scripts'), ( 'expected mootools scripts to be marked for proessing') assert err.get_resource('scripts')[0]['scripts'] == set(['content/mootools.js'])
def test_validate_libs_in_compat_mode(): xpi = 'tests/resources/libraryblacklist/addon_with_mootools.xpi' with open(xpi) as data: package = XPIManager(data, mode='r', name='addon_with_mootools.xpi') appversions = { FIREFOX_GUID: version_range('firefox', '39.0a1', '39.*') } err = ErrorBundle(for_appversions=appversions) test_content.test_packed_packages(err, package) assert err.get_resource('scripts'), ( 'expected mootools scripts to be marked for proessing') assert err.get_resource('scripts')[0]['scripts'] == set( ['content/mootools.js'])
def test_pushable_resources(): """ Test that normal resources are preserved but pushable ones are pushed. """ e = ErrorBundle() e.save_resource('nopush', True) e.save_resource('push', True, pushable=True) assert e.get_resource('nopush') assert e.get_resource('push') e.push_state() assert e.get_resource('nopush') assert not e.get_resource('push') e.save_resource('pushed', True, pushable=True) assert e.get_resource('pushed') e.pop_state() assert e.get_resource('nopush') assert e.get_resource('push') assert not e.get_resource('pushed')
def test_pushable_resources(): """ Test that normal resources are preserved but pushable ones are pushed. """ e = ErrorBundle() e.save_resource("nopush", True) e.save_resource("push", True, pushable=True) assert e.get_resource("nopush") assert e.get_resource("push") e.push_state() assert e.get_resource("nopush") assert not e.get_resource("push") e.save_resource("pushed", True, pushable=True) assert e.get_resource("pushed") e.pop_state() assert e.get_resource("nopush") assert e.get_resource("push") assert not e.get_resource("pushed")
def test_initializer(): """Test that the __init__ paramaters are doing their jobs.""" e = ErrorBundle() assert e.determined assert e.get_resource("listed") e = ErrorBundle(determined=False) assert not e.determined assert e.get_resource("listed") e = ErrorBundle(listed=False) assert e.determined assert not e.get_resource("listed")
def test_initializer(): """Test that the __init__ paramaters are doing their jobs.""" e = ErrorBundle() assert e.determined assert e.get_resource('listed') e = ErrorBundle(determined=False) assert not e.determined assert e.get_resource('listed') e = ErrorBundle(listed=False) assert e.determined assert not e.get_resource('listed')
def test_marking_overlays_subdir(): """ Mark an overlay in a subdirectory, then test that it marks the scripts within the overlay. Make sure it properly figures out relative URLs. """ err = ErrorBundle() err.supported_versions = {} c = ChromeManifest(""" content ns1 foo/ overlay chrome://foo chrome://ns1/content/subdir/main.xul """, 'chrome.manifest') err.save_resource('chrome.manifest', c) err.save_resource('chrome.manifest_nopush', c) xpi = MockXPI({'foo/subdir/main.xul': 'tests/resources/content/script_list.xul'}) content.test_packed_packages(err, xpi) assert not err.failed() marked_scripts = err.get_resource('marked_scripts') print marked_scripts assert marked_scripts eq_(marked_scripts, set(['chrome://ns1/subdir/foo.js', 'chrome://ns1/bar.js', 'chrome://asdf/foo.js']))
def test_proper_linked_manifest_relative(): """ Test that linked manifests are imported relatively when using relative paths. """ err = ErrorBundle() package = MockXPI({ 'chrome.manifest': 'tests/resources/submain/linkman/subdir.manifest', 'dir/level2.manifest': 'tests/resources/submain/linkman/foosub.manifest', 'dir/foo.manifest': 'tests/resources/submain/linkman/base2.manifest' }) submain.populate_chrome_manifest(err, package) chrome = err.get_resource('chrome.manifest') assert chrome assert not err.failed() or err.notices # From the linked manifest: zaps = list(chrome.get_triples(subject='zap')) assert zaps assert zaps[0]['filename'] == 'dir/foo.manifest' assert zaps[0]['context'].data == ['zap baz', '']
def test_version_forappversions_accepted(): """ Test that for_appversions targets application versions properly. """ err = ErrorBundle() err.supported_versions = {'firefox': ['1.2.3']} tests = decorator.TEST_TIERS decorator.TEST_TIERS = {} @decorator.register_test(tier=5, versions={'firefox': ['1.0.0', '1.2.3']}) def version_test(err, xpi): print 'Ran test' err.save_resource('executed', True) print decorator.TEST_TIERS validator.submain.test_inner_package(err, MockXPI(), for_appversions={'firefox': ['1.2.3']}) assert err.get_resource('executed') decorator.TEST_TIERS = tests
def test_marking_overlays(): """ Mark an overlay, then test that it marks the scripts within the overlay. """ err = ErrorBundle() err.supported_versions = {} c = chrome_manifest(""" content ns1 foo/ overlay chrome://foo chrome://ns1/content/main.xul """) err.save_resource('chrome.manifest', c) err.save_resource('chrome.manifest_nopush', c) xpi = MockXPI({'foo/main.xul': 'tests/resources/content/script_list.xul'}) content.test_packed_packages(err, xpi) assert not err.failed() marked_scripts = err.get_resource('marked_scripts') eq_( marked_scripts, set([ 'chrome://ns1/foo.js', 'chrome://ns1/bar.js', 'chrome://asdf/foo.js' ]))
def test_marking_overlays_root_package(): """ Tests that '/' resolves correctly as a chrome content package. """ err = ErrorBundle() err.supported_versions = {} manifest = chrome_manifest(""" content ns1 / overlay chrome://foo chrome://ns1/content/main.xul """) err.save_resource('chrome.manifest', manifest) err.save_resource('chrome.manifest_nopush', manifest) xpi = MockXPI({'main.xul': 'tests/resources/content/script_list.xul'}) content.test_packed_packages(err, xpi) assert not err.failed() marked_scripts = err.get_resource('marked_scripts') eq_( marked_scripts, set([ 'chrome://ns1/foo.js', 'chrome://ns1/bar.js', 'chrome://asdf/foo.js' ]))
def test_marking_overlays(): """ Mark an overlay, then test that it marks the scripts within the overlay. """ err = ErrorBundle() err.supported_versions = {} c = ChromeManifest(""" content ns1 foo/ overlay chrome://foo chrome://ns1/content/main.xul """, "chrome.manifest") err.save_resource("chrome.manifest", c) err.save_resource("chrome.manifest_nopush", c) xpi = MockXPI({"foo/main.xul": "tests/resources/content/script_list.xul"}) content.test_packed_packages(err, xpi) assert not err.failed() marked_scripts = err.get_resource("marked_scripts") print marked_scripts assert marked_scripts eq_(marked_scripts, set(["chrome://ns1/foo.js", "chrome://ns1/bar.js", "chrome://asdf/foo.js"]))
def test_proper_linked_manifest_relative(): """ Test that linked manifests are imported relatively when using relative paths. """ err = ErrorBundle() package = MockXPI( { "chrome.manifest": "tests/resources/submain/linkman/subdir.manifest", "dir/level2.manifest": "tests/resources/submain/linkman/foosub.manifest", "dir/foo.manifest": "tests/resources/submain/linkman/base2.manifest", } ) submain.populate_chrome_manifest(err, package) chrome = err.get_resource("chrome.manifest") assert chrome assert not err.failed() or err.notices # From the linked manifest: zaps = list(chrome.get_entries("zap")) assert zaps eq_(zaps[0]["filename"], "dir/foo.manifest") eq_(zaps[0]["context"].data, ["zap baz", ""])
def test_package_pass(test_inner_package): 'Tests the test_package function with simple data' err = ErrorBundle() with open('tests/resources/submain/install_rdf.xpi') as pkg: submain.test_package(err, pkg, pkg.name) assert not err.failed() assert err.get_resource('has_install_rdf') assert submain.test_inner_package.called
def test_package_extension_expectation(test_inner_package): 'Tests the test_package function with an odd extension' err = ErrorBundle() with open('tests/resources/submain/install_rdf.jar') as pkg: submain.test_package(err, pkg, pkg.name, PACKAGE_ANY) assert submain.test_inner_package.called assert not err.failed() assert err.get_resource('has_install_rdf')
def test_package_extension_expectation(): "Tests the test_package function with an odd extension" tip = submain.test_inner_package submain.test_inner_package = lambda x, z, for_appversions: "success" name = "tests/resources/submain/install_rdf.jar" err = ErrorBundle() result = submain.test_package(err, name, name, PACKAGE_ANY) submain.test_inner_package = tip assert not err.failed() assert err.get_resource("has_install_rdf") assert result == "success"
def _run_test(filename, expectation, should_fail=True): name = "tests/resources/submain/%s" % filename pack = open(name) xpi = XPIManager(pack, mode="r", name=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_missing_manifest_link(): """Test that missing linked manifests are properly flagged.""" err = ErrorBundle() package = MockXPI({"chrome.manifest": "tests/resources/submain/linkman/base1.manifest"}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource("chrome.manifest") assert chrome assert not err.failed() assert err.notices # From the base file: assert list(chrome.get_entries("foo")) # From the linked manifest: assert not list(chrome.get_entries("zap"))
def test_missing_manifest_link(): """Test that missing linked manifests are properly flagged.""" err = ErrorBundle() package = MockXPI( {'chrome.manifest': 'tests/resources/submain/linkman/base1.manifest'}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource('chrome.manifest') assert chrome assert not err.failed() assert err.notices # From the base file: assert list(chrome.get_triples(subject='foo')) # From the linked manifest: assert not list(chrome.get_triples(subject='zap'))
def test_missing_manifest_link(): """Test that missing linked manifests are properly flagged.""" err = ErrorBundle() package = MockXPI({ 'chrome.manifest': 'tests/resources/submain/linkman/base1.manifest'}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource('chrome.manifest') assert chrome assert not err.failed() assert err.notices # From the base file: assert list(chrome.get_triples(subject='foo')) # From the linked manifest: assert not list(chrome.get_triples(subject='zap'))
def test_package_pass(): "Tests the test_package function with simple data" tip = submain.test_inner_package submain.test_inner_package = lambda x, z, for_appversions: "success" name = "tests/resources/submain/install_rdf.xpi" pack = open(name) err = ErrorBundle() result = submain.test_package(err, pack, name) pack.close() submain.test_inner_package = tip assert not err.failed() assert err.get_resource("has_install_rdf") assert result == "success"
def test_proper_linked_manifest(): """Test that linked manifests are imported properly.""" err = ErrorBundle() package = MockXPI({ "chrome.manifest": "tests/resources/submain/linkman/base1.manifest", "submanifest.manifest": "tests/resources/submain/linkman/base2.manifest"}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource("chrome.manifest") assert chrome assert not err.failed() or err.notices # From the base file: assert list(chrome.get_triples(subject="foo")) # From the linked manifest: assert list(chrome.get_triples(subject="zap"))
def test_script_scraping(): """Test that scripts are gathered up during the validation process.""" err = ErrorBundle() err.supported_versions = {} xpi = MockXPI({'foo.js': 'tests/resources/junk.xpi', 'dir/bar.jsm': 'tests/resources/junk.xpi'}) content.test_packed_packages(err, xpi) assert not err.failed() scripts = err.get_resource('scripts') print scripts assert scripts for bundle in scripts: assert 'foo.js' in bundle['scripts'] assert 'dir/bar.jsm' in bundle['scripts'] eq_(bundle['package'], xpi) eq_(bundle['state'], [])
def test_script_scraping(): """Test that scripts are gathered up during the validation process.""" err = ErrorBundle() err.supported_versions = {} xpi = MockXPI({"foo.js": "tests/resources/junk.xpi", "dir/bar.jsm": "tests/resources/junk.xpi"}) content.test_packed_packages(err, xpi) assert not err.failed() scripts = err.get_resource("scripts") print scripts assert scripts for bundle in scripts: assert "foo.js" in bundle["scripts"] assert "dir/bar.jsm" in bundle["scripts"] eq_(bundle["package"], xpi) eq_(bundle["state"], [])
def test_linked_manifest_recursion(): """Test that recursive linked manifests are flagged properly.""" err = ErrorBundle() package = MockXPI({ "chrome.manifest": "tests/resources/submain/linkman/base1.manifest", "submanifest.manifest": "tests/resources/submain/linkman/recurse.manifest"}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource("chrome.manifest") assert chrome print err.print_summary(verbose=True) assert err.failed() assert not err.notices # From the base file: assert list(chrome.get_triples(subject="foo")) # From the linked manifest: assert not list(chrome.get_triples(subject="zap"))
def test_linked_manifest_recursion(): """Test that recursive linked manifests are flagged properly.""" err = ErrorBundle() package = MockXPI({ 'chrome.manifest': 'tests/resources/submain/linkman/base1.manifest', 'submanifest.manifest': 'tests/resources/submain/linkman/recurse.manifest'}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource('chrome.manifest') assert chrome print err.print_summary(verbose=True) assert err.failed() assert not err.notices # From the base file: assert list(chrome.get_triples(subject='foo')) # From the linked manifest: assert not list(chrome.get_triples(subject='zap'))
def test_proper_linked_manifest(): """Test that linked manifests are imported properly.""" err = ErrorBundle() package = MockXPI({ 'chrome.manifest': 'tests/resources/submain/linkman/base1.manifest', 'submanifest.manifest': 'tests/resources/submain/linkman/base2.manifest'}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource('chrome.manifest') assert chrome assert not err.failed() or err.notices # From the base file: assert list(chrome.get_triples(subject='foo')) # From the linked manifest: zaps = list(chrome.get_triples(subject='zap')) assert zaps assert zaps[0]['filename'] == 'submanifest.manifest' assert zaps[0]['context'].data == ['zap baz', '']
def test_version_forappversions_denied(): """ Test that for_appversions denies target application versions properly. """ err = ErrorBundle() err.supported_versions = {'firefox': ['1.2.3']} tests = decorator.TEST_TIERS decorator.TEST_TIERS = {} @decorator.register_test(tier=5, versions={'firefox': ['1.0.0', '1.2.3']}) def version_test(err, xpi): raise Exception('Should not have run!') print decorator.TEST_TIERS validator.submain.test_inner_package( err, MockXPI(), for_appversions={'thunderbird': ['1.2.3']}) assert not err.get_resource('executed') decorator.TEST_TIERS = tests
def test_proper_linked_manifest(): """Test that linked manifests are imported properly.""" err = ErrorBundle() package = MockXPI({ "chrome.manifest": "tests/resources/submain/linkman/base1.manifest", "submanifest.manifest": "tests/resources/submain/linkman/base2.manifest"}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource("chrome.manifest") assert chrome assert not err.failed() or err.notices # From the base file: assert list(chrome.get_triples(subject="foo")) # From the linked manifest: zaps = list(chrome.get_triples(subject="zap")) assert zaps eq_(zaps[0]["filename"], "submanifest.manifest") eq_(zaps[0]["context"].data, ["zap baz", ""])
def test_version_forappversions_accepted(): """ Test that for_appversions targets application versions properly. """ err = ErrorBundle() err.supported_versions = {'firefox': ['1.2.3']} tests = decorator.TEST_TIERS decorator.TEST_TIERS = {} @decorator.register_test(tier=5, versions={'firefox': ['1.0.0', '1.2.3']}) def version_test(err, xpi): print 'Ran test' err.save_resource('executed', True) print decorator.TEST_TIERS validator.submain.test_inner_package( err, MockXPI(), for_appversions={'firefox': ['1.2.3']}) assert err.get_resource('executed') decorator.TEST_TIERS = tests
def test_version_decorators_accepted(): """ Test that decorators that specify versions to target accept the proper add-ons for testing. """ err = ErrorBundle() err.supported_versions = {'firefox': ['1.2.3']} tests = decorator.TEST_TIERS decorator.TEST_TIERS = {} @decorator.register_test(tier=5, versions={'firefox': ['1.0.0', '1.2.3']}) def version_test(err, xpi): print 'Ran test' err.save_resource('executed', True) print decorator.TEST_TIERS validator.submain.test_inner_package(err, MockXPI()) assert err.get_resource('executed') decorator.TEST_TIERS = tests
def test_marking_overlays_no_overlay(): """ Test that unmarked overlays don't mark scripts as being potentially pollutable. """ err = ErrorBundle() err.supported_versions = {} c = ChromeManifest(""" content ns1 foo/ #overlay chrome://foo chrome://ns1/main.xul """, "chrome.manifest") err.save_resource("chrome.manifest", c) err.save_resource("chrome.manifest_nopush", c) xpi = MockXPI({"foo/main.xul": "tests/resources/content/script_list.xul"}) content.test_packed_packages(err, xpi) assert not err.failed() marked_scripts = err.get_resource("marked_scripts") print marked_scripts assert not marked_scripts
def test_proper_linked_manifest_relative(): """ Test that linked manifests are imported relatively when using relative paths. """ err = ErrorBundle() package = MockXPI({ "chrome.manifest": "tests/resources/submain/linkman/subdir.manifest", "dir/level2.manifest": "tests/resources/submain/linkman/foosub.manifest", "dir/foo.manifest": "tests/resources/submain/linkman/base2.manifest"}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource("chrome.manifest") assert chrome assert not err.failed() or err.notices # From the linked manifest: zaps = list(chrome.get_triples(subject="zap")) assert zaps eq_(zaps[0]["filename"], "dir/foo.manifest") eq_(zaps[0]["context"].data, ["zap baz", ""])
def test_version_forappversions_denied(): """ Test that for_appversions denies target application versions properly. """ err = ErrorBundle() err.supported_versions = {'firefox': ['1.2.3']} tests = decorator.TEST_TIERS decorator.TEST_TIERS = {} @decorator.register_test(tier=5, versions={'firefox': ['1.0.0', '1.2.3']}) def version_test(err, xpi): raise Exception('Should not have run!') print decorator.TEST_TIERS validator.submain.test_inner_package(err, MockXPI(), for_appversions={'thunderbird': ['1.2.3']}) assert not err.get_resource('executed') decorator.TEST_TIERS = tests
def test_proper_linked_manifest_relative(): """ Test that linked manifests are imported relatively when using relative paths. """ err = ErrorBundle() package = MockXPI({ 'chrome.manifest': 'tests/resources/submain/linkman/subdir.manifest', 'dir/level2.manifest': 'tests/resources/submain/linkman/foosub.manifest', 'dir/foo.manifest': 'tests/resources/submain/linkman/base2.manifest'}) submain.populate_chrome_manifest(err, package) chrome = err.get_resource('chrome.manifest') assert chrome assert not err.failed() or err.notices # From the linked manifest: zaps = list(chrome.get_triples(subject='zap')) assert zaps assert zaps[0]['filename'] == 'dir/foo.manifest' assert zaps[0]['context'].data == ['zap baz', '']
def test_proper_linked_manifest(): """Test that linked manifests are imported properly.""" err = ErrorBundle() package = MockXPI({ 'chrome.manifest': 'tests/resources/submain/linkman/base1.manifest', 'submanifest.manifest': 'tests/resources/submain/linkman/base2.manifest' }) submain.populate_chrome_manifest(err, package) chrome = err.get_resource('chrome.manifest') assert chrome assert not err.failed() or err.notices # From the base file: assert list(chrome.get_triples(subject='foo')) # From the linked manifest: zaps = list(chrome.get_triples(subject='zap')) assert zaps assert zaps[0]['filename'] == 'submanifest.manifest' assert zaps[0]['context'].data == ['zap baz', '']
def test_proper_linked_manifest(): """Test that linked manifests are imported properly.""" err = ErrorBundle() package = MockXPI( { "chrome.manifest": "tests/resources/submain/linkman/base1.manifest", "submanifest.manifest": "tests/resources/submain/linkman/base2.manifest", } ) submain.populate_chrome_manifest(err, package) chrome = err.get_resource("chrome.manifest") assert chrome assert not err.failed() or err.notices # From the base file: assert list(chrome.get_entries("foo")) # From the linked manifest: zaps = list(chrome.get_entries("zap")) assert zaps eq_(zaps[0]["filename"], "submanifest.manifest") eq_(zaps[0]["context"].data, ["zap baz", ""])
def test_linked_manifest_recursion(): """Test that recursive linked manifests are flagged properly.""" err = ErrorBundle() package = MockXPI({ 'chrome.manifest': 'tests/resources/submain/linkman/base1.manifest', 'submanifest.manifest': 'tests/resources/submain/linkman/recurse.manifest' }) submain.populate_chrome_manifest(err, package) chrome = err.get_resource('chrome.manifest') assert chrome print err.print_summary(verbose=True) assert not err.failed() assert not err.notices # From the base file: assert list(chrome.get_entries('foo')) # From the linked manifest: assert not list(chrome.get_entries('zap'))
def test_marking_overlays_root_package(): """ Tests that '/' resolves correctly as a chrome content package. """ err = ErrorBundle() err.supported_versions = {} manifest = ChromeManifest(""" content ns1 / overlay chrome://foo chrome://ns1/content/main.xul """, 'chrome.manifest') err.save_resource('chrome.manifest', manifest) err.save_resource('chrome.manifest_nopush', manifest) xpi = MockXPI({'main.xul': 'tests/resources/content/script_list.xul'}) content.test_packed_packages(err, xpi) assert not err.failed() marked_scripts = err.get_resource('marked_scripts') eq_(marked_scripts, set(['chrome://ns1/foo.js', 'chrome://ns1/bar.js', 'chrome://asdf/foo.js']))
def test_linked_manifest_recursion(): """Test that recursive linked manifests are flagged properly.""" err = ErrorBundle() package = MockXPI( { "chrome.manifest": "tests/resources/submain/linkman/base1.manifest", "submanifest.manifest": "tests/resources/submain/linkman/recurse.manifest", } ) submain.populate_chrome_manifest(err, package) chrome = err.get_resource("chrome.manifest") assert chrome print err.print_summary(verbose=True) assert not err.failed() assert not err.notices # From the base file: assert list(chrome.get_entries("foo")) # From the linked manifest: assert not list(chrome.get_entries("zap"))
def test_states(): """Test that detected type is preserved, even in subpackages.""" # Use the StringIO as an output buffer. bundle = ErrorBundle() # Populate the bundle with some test data. bundle.detected_type = 4 bundle.error((), "error") bundle.warning((), "warning") bundle.notice((), "notice") bundle.save_resource("test", True) # Push a state bundle.push_state("test.xpi") bundle.detected_type = 2 bundle.error((), "nested error") bundle.warning((), "nested warning") bundle.notice((), "nested notice") # Push another state bundle.push_state("test2.xpi") bundle.detected_type = 3 bundle.error((), "super nested error") bundle.warning((), "super nested warning") bundle.notice((), "super nested notice") # Test that nested compatibility messages retain various # properties. bundle.notice("comp", "Compat Test notice", compatibility_type="error", editors_only=True, signing_severity="high") bundle.pop_state() bundle.pop_state() # Load the JSON output as an object. output = json.loads(bundle.render_json()) # Run some basic tests assert output["detected_type"] == "langpack" assert len(output["messages"]) == 10 messages = [ "error", "warning", "notice", "nested error", "nested warning", "nested notice", "super nested error", "super nested warning", "super nested notice", "Compat Test notice", ] for message in output["messages"]: assert message["message"] in messages messages.remove(message["message"]) assert message["message"].endswith(message["type"]) if message["id"] == "comp": assert message["compatibility_type"] == "error" assert message["editors_only"] == True assert message["signing_severity"] == "high" assert not messages assert bundle.get_resource("test")
def test_states(): """Test that detected type is preserved, even in subpackages.""" # Use the StringIO as an output buffer. bundle = ErrorBundle() # Populate the bundle with some test data. bundle.detected_type = 4 bundle.error((), 'error') bundle.warning((), 'warning') bundle.notice((), 'notice') bundle.save_resource('test', True) # Push a state bundle.push_state('test.xpi') bundle.detected_type = 2 bundle.error((), 'nested error') bundle.warning((), 'nested warning') bundle.notice((), 'nested notice') # Push another state bundle.push_state('test2.xpi') bundle.detected_type = 3 bundle.error((), 'super nested error') bundle.warning((), 'super nested warning') bundle.notice((), 'super nested notice') # Test that nested compatibility messages retain various # properties. bundle.notice('comp', 'Compat Test notice', compatibility_type='error', editors_only=True, signing_severity='high') bundle.pop_state() bundle.pop_state() # Load the JSON output as an object. output = json.loads(bundle.render_json()) # Run some basic tests assert output['detected_type'] == 'langpack' assert len(output['messages']) == 10 messages = [ 'error', 'warning', 'notice', 'nested error', 'nested warning', 'nested notice', 'super nested error', 'super nested warning', 'super nested notice', 'Compat Test notice' ] for message in output['messages']: assert message['message'] in messages messages.remove(message['message']) assert message['message'].endswith(message['type']) if message['id'] == 'comp': assert message['compatibility_type'] == 'error' assert message['editors_only'] == True assert message['signing_severity'] == 'high' assert not messages assert bundle.get_resource('test')
def test_states(): """Test that detected type is preserved, even in subpackages.""" # Use the StringIO as an output buffer. bundle = ErrorBundle() # Populate the bundle with some test data. bundle.detected_type = 4 bundle.error((), 'error') bundle.warning((), 'warning') bundle.notice((), 'notice') bundle.save_resource('test', True) # Push a state bundle.push_state('test.xpi') bundle.detected_type = 2 bundle.error((), 'nested error') bundle.warning((), 'nested warning') bundle.notice((), 'nested notice') # Push another state bundle.push_state('test2.xpi') bundle.detected_type = 3 bundle.error((), 'super nested error') bundle.warning((), 'super nested warning') bundle.notice((), 'super nested notice') # Test that nested compatibility messages retain various # properties. bundle.notice('comp', 'Compat Test notice', compatibility_type='error', editors_only=True, signing_severity='high') bundle.pop_state() bundle.pop_state() # Load the JSON output as an object. output = json.loads(bundle.render_json()) # Run some basic tests assert output['detected_type'] == 'langpack' assert len(output['messages']) == 10 messages = ['error', 'warning', 'notice', 'nested error', 'nested warning', 'nested notice', 'super nested error', 'super nested warning', 'super nested notice', 'Compat Test notice'] for message in output['messages']: assert message['message'] in messages messages.remove(message['message']) assert message['message'].endswith(message['type']) if message['id'] == 'comp': assert message['compatibility_type'] == 'error' assert message['editors_only'] is True assert message['signing_severity'] == 'high' assert not messages assert bundle.get_resource('test')
def test_states(): """Test that detected type is preserved, even in subpackages.""" # Use the StringIO as an output buffer. bundle = ErrorBundle() # Populate the bundle with some test data. bundle.detected_type = 4 bundle.error((), "error") bundle.warning((), "warning") bundle.notice((), "notice") bundle.save_resource("test", True) # Push a state bundle.push_state("test.xpi") bundle.detected_type = 2 bundle.error((), "nested error") bundle.warning((), "nested warning") bundle.notice((), "nested notice") # Push another state bundle.push_state("test2.xpi") bundle.detected_type = 3 bundle.error((), "super nested error") bundle.warning((), "super nested warning") bundle.notice((), "super nested notice") # Test that nested compatibility messages retain their value bundle.notice("comp", "Compat Test notice", compatibility_type="error") bundle.pop_state() bundle.pop_state() # Load the JSON output as an object. output = json.loads(bundle.render_json()) # Run some basic tests assert output["detected_type"] == "langpack" assert len(output["messages"]) == 10 print output messages = [ "error", "warning", "notice", "nested error", "nested warning", "nested notice", "super nested error", "super nested warning", "super nested notice", "Compat Test notice" ] for message in output["messages"]: print message assert message["message"] in messages messages.remove(message["message"]) assert message["message"].endswith(message["type"]) if message["id"] == "comp": assert message["compatibility_type"] == "error" assert not messages assert bundle.get_resource("test")