예제 #1
0
def test_main_buries_errors(capfd):
    """Any Exception thrown in list_package should be handled."""

    bucket = mock.Mock()
    settings = mock.Mock()
    settings.items = ["faked"]

    mock_s = mock.patch.object(lister, "get_settings", return_value=settings)
    mock_b = mock.patch.object(lister, "get_bucket_conn", return_value=bucket)
    mock_l = mock.patch.object(lister, "list_package", side_effect=IOError)

    with mock_s as settings_patch:
        with mock_b as get_bucket_patch:
            with mock_l as lister_patch:
                with mock.patch.object(lister, "parse_package") as parse_patch:
                    lister.main()

    settings_patch.assert_called_once_with(listing=True)
    get_bucket_patch.assert_called_once_with(settings.s3)
    parse_patch.assert_called_once_with("faked")
    lister_patch.assert_called_once_with(bucket, parse_patch())

    out, err = capfd.readouterr()
    assert not out
    assert "Error listing faked: " in err
예제 #2
0
def test_main():
    """Mock all calls and verify the main lister application flow."""

    bucket = mock.Mock()
    settings = mock.Mock()
    settings.items = ["faked"]

    mock_s = mock.patch.object(lister, "get_settings", return_value=settings)
    mock_b = mock.patch.object(lister, "get_bucket_conn", return_value=bucket)

    with mock_s as settings_patch:
        with mock_b as get_bucket_patch:
            with mock.patch.object(lister, "list_package") as lister_patch:
                with mock.patch.object(lister, "parse_package") as parse_patch:
                    lister.main()

    settings_patch.assert_called_once_with(listing=True)
    get_bucket_patch.assert_called_once_with(settings.s3)
    parse_patch.assert_called_once_with("faked")
    lister_patch.assert_called_once_with(bucket, parse_patch())