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")
Example #3
0
def test_subpackage():
    "Test a package with localization that should pass validation."

    err = ErrorBundle()
    err.set_type(PACKAGE_DICTIONARY)
    assert l10n.test_xpi(err, None) is None
    err.set_type(PACKAGE_EXTENSION)
    err.push_state()
    assert l10n.test_xpi(err, None) is None
Example #4
0
def test_subpackage():
    'Test a package with localization that should pass validation.'

    err = ErrorBundle()
    err.detected_type = PACKAGE_DICTIONARY
    assert l10n.test_xpi(err, None) is None
    err.detected_type = PACKAGE_EXTENSION
    err.push_state()
    assert l10n.test_xpi(err, None) is None
def test_unsigned_inner_xpi():
    """Test that inner XPIs need to be signed even if not multi-package."""
    xpi = MockXPI(subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('inner.xpi')
    err.save_resource('is_multipackage', False)

    content.test_signed_xpi(err, xpi)

    assert err.failed()
Example #6
0
def test_unsigned_inner_xpi():
    """Test that inner XPIs need to be signed even if not multi-package."""
    xpi = MockXPI(subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('inner.xpi')
    err.save_resource('is_multipackage', False)

    content.test_signed_xpi(err, xpi)

    assert err.failed()
Example #7
0
def test_unsigned_inner_jar():
    """Test that inner packages don't need to be signed if not multipackage."""
    xpi = MockXPI(subpackage=True)
    xpi.filename = 'mock_jar.jar'

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('inner.jar')
    err.save_resource('is_multipackage', False)

    content.test_signed_xpi(err, xpi)

    assert not err.failed()
def test_unsigned_inner_jar():
    """Test that inner packages don't need to be signed if not multipackage."""
    xpi = MockXPI(subpackage=True)
    xpi.filename = 'mock_jar.jar'

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('inner.jar')
    err.save_resource('is_multipackage', False)

    content.test_signed_xpi(err, xpi)

    assert not err.failed()
Example #9
0
def test_unsigned_multi_xpi():
    """Test that unsigned inner packages raise an error."""
    xpi = MockXPI(subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('sub.xpi')
    err.save_resource('is_multipackage', True)

    content.test_signed_xpi(err, xpi)

    assert err.failed()
    assert not err.warnings
    assert err.errors
    assert err.errors[0]['id'] == ('testcases_content', 'unsigned_sub_xpi')
def test_unsigned_multi_xpi():
    """Test that unsigned inner packages raise an error."""
    xpi = MockXPI(subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('sub.xpi')
    err.save_resource('is_multipackage', True)

    content.test_signed_xpi(err, xpi)

    assert err.failed()
    assert not err.warnings
    assert err.errors
    assert err.errors[0]['id'] == ('testcases_content', 'unsigned_sub_xpi')
def test_mozilla_signed_multi_xpi():
    """Test that mozilla signed inner packages don't raise an error."""
    xpi = MockXPI({
        'META-INF/manifest.mf': 'tests/resources/main/foo.bar',
        'META-INF/mozilla.rsa': 'tests/resources/main/foo.bar',
        'META-INF/mozilla.sf': 'tests/resources/main/foo.bar',
    }, subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('sub.xpi')
    err.save_resource('is_multipackage', True)

    content.test_signed_xpi(err, xpi)

    assert not err.failed()
Example #12
0
def test_mozilla_signed_multi_xpi():
    """Test that mozilla signed inner packages don't raise an error."""
    xpi = MockXPI(
        {
            'META-INF/manifest.mf': 'tests/resources/main/foo.bar',
            'META-INF/mozilla.rsa': 'tests/resources/main/foo.bar',
            'META-INF/mozilla.sf': 'tests/resources/main/foo.bar',
        },
        subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('sub.xpi')
    err.save_resource('is_multipackage', True)

    content.test_signed_xpi(err, xpi)

    assert not err.failed()
def test_other_signed_multi_xpi():
    """Test that other signed inner packages raise an error."""
    xpi = MockXPI({
        'META-INF/manifest.mf': 'tests/resources/main/foo.bar',
        'META-INF/zigbert.rsa': 'tests/resources/main/foo.bar',
        'META-INF/zigbert.sf': 'tests/resources/main/foo.bar',
    }, subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('sub.xpi')
    err.save_resource('is_multipackage', True)

    content.test_signed_xpi(err, xpi)

    assert err.failed()
    assert not err.warnings
    assert err.errors
    assert err.errors[0]['id'] == ('testcases_content', 'unsigned_sub_xpi')
Example #14
0
def test_other_signed_multi_xpi():
    """Test that other signed inner packages raise an error."""
    xpi = MockXPI(
        {
            'META-INF/manifest.mf': 'tests/resources/main/foo.bar',
            'META-INF/zigbert.rsa': 'tests/resources/main/foo.bar',
            'META-INF/zigbert.sf': 'tests/resources/main/foo.bar',
        },
        subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('sub.xpi')
    err.save_resource('is_multipackage', True)

    content.test_signed_xpi(err, xpi)

    assert err.failed()
    assert not err.warnings
    assert err.errors
    assert err.errors[0]['id'] == ('testcases_content', 'unsigned_sub_xpi')
def test_file_structure():
    """
    Test the means by which file names and line numbers are stored in errors,
    warnings, and messages.
    """

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle(True)  # No color since no output

    # Populate the bundle with some test data.
    bundle.error((), "error", description="", filename="file1", column=123)
    bundle.error((), "error", description="", filename="file2")
    bundle.error((), "error")

    # Push a state
    bundle.push_state("foo")

    bundle.warning((), "warning", description="", filename="file4", column=123)
    bundle.warning((), "warning", description="", filename="file5")
    bundle.warning((), "warning")

    bundle.pop_state()

    # Load the JSON output as an object.
    output = json.loads(bundle.render_json())

    # Do the same for friendly output
    output2 = bundle.print_summary(verbose=False)

    # Do the same for verbose friendly output
    output3 = bundle.print_summary(verbose=True)

    # Run some basic tests
    assert len(output["messages"]) == 6
    assert len(output2) < len(output3)

    print output
    print "*" * 50
    print output2
    print "*" * 50
    print output3
    print "*" * 50

    messages = [
        "file1", "file2", "", ["foo", "file4"], ["foo", "file5"], ["foo", ""]
    ]

    for message in output["messages"]:
        print message

        assert message["file"] in messages
        messages.remove(message["file"])

        if isinstance(message["file"], list):
            pattern = message["file"][:]
            pattern.pop()
            pattern.append("")
            file_merge = " > ".join(pattern)
            print file_merge
            assert output3.count(file_merge)
        else:
            assert output3.count(message["file"])

    assert not messages
Example #16
0
def test_states():
    """Tests 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.set_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.set_type(2)
    bundle.error((), "nested error")
    bundle.warning((), "nested warning")
    bundle.notice((), "nested notice")
    
    # Push another state
    bundle.push_state("test2.xpi")
    
    bundle.set_type(3)
    bundle.error((), "super nested error")
    bundle.warning((), "super nested warning")
    bundle.notice((), "super nested notice")
    
    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"]) == 9
    
    print output
    
    messages = ["error",
                "warning",
                "notice",
                "nested error",
                "nested warning",
                "nested notice",
                "super nested error",
                "super nested warning",
                "super nested notice"]
    
    for message in output["messages"]:
        print message
        
        assert message["message"] in messages
        messages.remove(message["message"])
        
        assert message["message"].endswith(message["type"])
    
    assert not messages
    
    assert bundle.get_resource("test")
def test_file_structure():
    """
    Test the means by which file names and line numbers are stored in errors,
    warnings, and messages.
    """

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle(True)  # No color since no output

    # Populate the bundle with some test data.
    bundle.error((), 'error', description='',
                 filename='file1', column=123)
    bundle.error((), 'error', description='',
                 filename='file2')
    bundle.error((), 'error')

    # Push a state
    bundle.push_state('foo')

    bundle.warning((), 'warning', description='',
                   filename='file4', column=123)
    bundle.warning((), 'warning', description='',
                   filename='file5')
    bundle.warning((), 'warning')

    bundle.pop_state()

    # Load the JSON output as an object.
    output = json.loads(bundle.render_json())

    # Do the same for friendly output
    output2 = bundle.print_summary(verbose=False)

    # Do the same for verbose friendly output
    output3 = bundle.print_summary(verbose=True)

    # Run some basic tests
    assert len(output['messages']) == 6
    assert len(output2) < len(output3)

    print output
    print '*' * 50
    print output2
    print '*' * 50
    print output3
    print '*' * 50

    messages = ['file1', 'file2', '',
                ['foo', 'file4'], ['foo', 'file5'], ['foo', '']]

    for message in output['messages']:
        print message

        assert message['file'] in messages
        messages.remove(message['file'])

        if isinstance(message['file'], list):
            pattern = message['file'][:]
            pattern.pop()
            pattern.append('')
            file_merge = ' > '.join(pattern)
            print file_merge
            assert output3.count(file_merge)
        else:
            assert output3.count(message['file'])

    assert not messages
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 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_file_structure():
    """
    Test the means by which file names and line numbers are stored in errors,
    warnings, and messages.
    """

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle(True)  # No color since no output

    # Populate the bundle with some test data.
    bundle.error((), 'error', description='', filename='file1', column=123)
    bundle.error((), 'error', description='', filename='file2')
    bundle.error((), 'error')

    # Push a state
    bundle.push_state('foo')

    bundle.warning((), 'warning', description='', filename='file4', column=123)
    bundle.warning((), 'warning', description='', filename='file5')
    bundle.warning((), 'warning')

    bundle.pop_state()

    # Load the JSON output as an object.
    output = json.loads(bundle.render_json())

    # Do the same for friendly output
    output2 = bundle.print_summary(verbose=False)

    # Do the same for verbose friendly output
    output3 = bundle.print_summary(verbose=True)

    # Run some basic tests
    assert len(output['messages']) == 6
    assert len(output2) < len(output3)

    print output
    print '*' * 50
    print output2
    print '*' * 50
    print output3
    print '*' * 50

    messages = [
        'file1', 'file2', '', ['foo', 'file4'], ['foo', 'file5'], ['foo', '']
    ]

    for message in output['messages']:
        print message

        assert message['file'] in messages
        messages.remove(message['file'])

        if isinstance(message['file'], list):
            pattern = message['file'][:]
            pattern.pop()
            pattern.append('')
            file_merge = ' > '.join(pattern)
            print file_merge
            assert output3.count(file_merge)
        else:
            assert output3.count(message['file'])

    assert not messages
def test_file_structure():
    """
    Test the means by which file names and line numbers are stored in errors,
    warnings, and messages.
    """

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle(determined=True)

    # Populate the bundle with some test data.
    bundle.error((), "error", description="", filename="file1", column=123)
    bundle.error((), "error", description="", filename="file2")
    bundle.error((), "error")

    # Push a state
    bundle.push_state("foo")

    bundle.warning((), "warning", description="", filename="file4", column=123)
    bundle.warning((), "warning", description="", filename="file5")
    bundle.warning((), "warning")

    bundle.pop_state()

    # Load the JSON output as an object.
    output = json.loads(bundle.render_json())

    # Do the same for friendly output
    output2 = bundle.print_summary(verbose=False)

    # Do the same for verbose friendly output
    output3 = bundle.print_summary(verbose=True)

    # Run some basic tests
    assert len(output["messages"]) == 6
    assert len(output2) < len(output3)

    print output
    print "*" * 50
    print output2
    print "*" * 50
    print output3
    print "*" * 50

    messages = ["file1", "file2", "", ["foo", "file4"], ["foo", "file5"], ["foo", ""]]

    for message in output["messages"]:
        print message

        assert message["file"] in messages
        messages.remove(message["file"])

        if isinstance(message["file"], list):
            pattern = message["file"][:]
            pattern.pop()
            pattern.append("")
            file_merge = " > ".join(pattern)
            print file_merge
            assert output3.count(file_merge)
        else:
            assert output3.count(message["file"])

    assert not messages
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")
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')