Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions imap_processing/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ def upload_products(self, products: list[Path]) -> None:
continue
else:
logger.error(f"Upload failed with error: {message}")
raise
except Exception as e:
logger.error(f"Upload failed unknown error: {e}")

Expand Down
52 changes: 52 additions & 0 deletions imap_processing/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,3 +937,55 @@ def test_post_processing(
"naif0012.tls",
"imap_sclk_0001.tsc",
]


@mock.patch("imap_processing.cli.filter_day_boundary_data")
@mock.patch("imap_processing.cli.swe_l1a")
def test_post_processing_upload_503_error(
mock_swe_l1a,
mock_filter,
mock_instrument_dependencies,
):
"""Test coverage for post processing when the upload fails with 503 error"""

mocks = mock_instrument_dependencies
mocks["mock_download"].return_value = "dependency0"
mocks["mock_write_cdf"].side_effect = [
"/path/to/imap_swe_l1a_test_20100105_v001.cdf"
]
mocks[
"mock_write_cdf"
].return_value = "/path/to/imap_swe_l1a_test_20100105_v001.cdf"
mocks["mock_query"].return_value = []

# Mocks a 503 error received from the upload API
mocks["mock_upload"].side_effect = imap_data_access.io.IMAPDataAccessError(
'503 Service Unavailable: {"error": "ServiceUnavailable", '
'"message": "The API is too busy."}'
)

test_ds = xr.Dataset()
mock_swe_l1a.return_value = [test_ds]
mock_filter.side_effect = lambda ds, _: ds
input_collection = ProcessingInputCollection(
ScienceInput("imap_swe_l0_raw_20100105_v001.pkts"),
SPICEInput("naif0012.tls", "imap_sclk_0001.tsc"),
)
mocks["mock_pre_processing"].return_value = input_collection

dependency_str = (
'[{"type": "science","files": ["imap_swe_l0_raw_20100105_v001.pkts"]}, '
'{"type": "spice", "files": ["naif0012.tls", "imap_sclk_0001.tsc"]}]'
)
instrument = Swe("l1a", "raw", dependency_str, "20100105", None, "v001", True)

# Checks that the upload failed and logs an error and raises an exception
with mock.patch("logging.Logger.error") as mock_error:
with pytest.raises(imap_data_access.io.IMAPDataAccessError):
instrument.process()

# Checks the upload failure was logged
assert any(
"Upload failed with error" in str(call)
for call in mock_error.call_args_list
)
Loading