def test_main_buries_errors(capfd): """Any Exception thrown in download_package should be handled.""" buck = mock.Mock() settings = mock.Mock() settings.items = ["faked"] mock_s = mock.patch.object(download, "get_settings", return_value=settings) mock_b = mock.patch.object(download, "get_bucket_conn", return_value=buck) d_io = mock.patch.object(download, "download_package", side_effect=IOError) mock_parse = mock.patch.object(download, "parse_package") with mock_s as settings_patch: with mock_b as get_bucket_patch: with d_io as download_patch: with mock_parse as parse_patch: download.main() settings_patch.assert_called_once_with(download=True) get_bucket_patch.assert_called_once_with(settings.s3) parse_patch.assert_called_once_with("faked") download_patch.assert_called_once_with(buck, parse_patch()) out, err = capfd.readouterr() assert not out assert "Error downloading faked: " in err
def test_main(): """Mocks everything to ensure the main entry point program flow.""" buck = mock.Mock() settings = mock.Mock() settings.items = ["faked"] mock_s = mock.patch.object(download, "get_settings", return_value=settings) mock_b = mock.patch.object(download, "get_bucket_conn", return_value=buck) mock_download = mock.patch.object(download, "download_package") mock_parse = mock.patch.object(download, "parse_package") with mock_s as settings_patch: with mock_b as get_bucket_patch: with mock_download as download_patch: with mock_parse as parse_patch: download.main() settings_patch.assert_called_once_with(download=True) get_bucket_patch.assert_called_once_with(settings.s3) parse_patch.assert_called_once_with("faked") download_patch.assert_called_once_with(buck, parse_patch())