Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 changelog/192.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix test due to update in sunpy ``Fido.search`` where error are no longer raised but stored in ``.errors`` attribute.
41 changes: 41 additions & 0 deletions sunpy_soar/tests/test_sunpy_soar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from sunpy_soar.client import SOARClient

SUNPY_VERSION = (sunpy.version.major, sunpy.version.minor)

def test_search() -> None:
instrument = a.Instrument("EUI")
Expand Down Expand Up @@ -336,6 +337,8 @@ def test_distance_time_search():
assert res.file_num == 48


# Remove this test and the mark from below once min sunpy dep >=7.1
@pytest.mark.skipif(SUNPY_VERSION >= (7, 1), reason="Skip post sunpy 7.1")
def test_distance_out_of_bounds_warning(recwarn):
instrument = a.Instrument("EUI")
time = a.Time("2023-04-27", "2023-04-28")
Expand All @@ -354,6 +357,21 @@ def test_distance_out_of_bounds_warning(recwarn):
)


@pytest.mark.skipif(SUNPY_VERSION < (7, 1), reason="Skip pre sunpy 7.1")
def test_distance_out_of_bounds_warning_post71():
instrument = a.Instrument("EUI")
time = a.Time("2023-04-27", "2023-04-28")
level = a.Level(2)
product = a.soar.Product("eui-fsi174-image")
distance = a.soar.Distance(0.45 * u.AU, 1.2 * u.AU)
# Run the search and ensure it raises an HTTPError
query = Fido.search(distance & instrument & product & level & time)
# Check if the warning was raised
assert "Distance values must be within the range 0.28 AU to 1.0 AU." in str(query['soar'].errors)


# Remove this test and the mark from below once min sunpy dep >=7.1
@pytest.mark.skipif(SUNPY_VERSION >= (7, 1), reason="Skip post sunpy 7.1")
@responses.activate
def test_soar_server_down() -> None:
# As the SOAR server is expected to be down in this test, a JSONDecodeError is expected
Expand All @@ -375,3 +393,26 @@ def test_soar_server_down() -> None:
match=r"The SOAR server returned an invalid JSON response. It may be down or not functioning correctly.",
):
Fido.search(time, level, product)


@pytest.mark.skipif(SUNPY_VERSION < (7, 1), reason="Skip pre sunpy 7.1")
@responses.activate
def test_soar_server_down_post71() -> None:
# As the SOAR server is expected to be down in this test, a JSONDecodeError is expected
# to be raised due to the absence of a valid JSON response.
tap_endpoint = (
"http://soar.esac.esa.int/soar-sl-tap/tap/sync?REQUEST=doQuery&LANG=ADQL&FORMAT=json&QUERY=SELECT"
" * FROM v_ll_data_item WHERE begin_time%3E='2020-11-13 00:00:00' AND "
"begin_time%3C='2020-11-14 00:00:00' AND level='LL02' AND descriptor='mag'"
)
# We do not give any json data similar to the condition when the server is down.
responses.add(responses.GET, tap_endpoint, body="Invalid JSON response", status=200)

time = a.Time("2020-11-13", "2020-11-14")
level = a.Level("LL02")
product = a.soar.Product("mag")

query = Fido.search(time, level, product)
assert isinstance(query['soar'].errors, RuntimeError)
assert ("The SOAR server returned an invalid JSON response. It may be down or not functioning correctly."
== str(query['soar'].errors))
Loading