1111
1212from sunpy_soar .client import SOARClient
1313
14+ SUNPY_VERSION = (sunpy .version .major , sunpy .version .minor )
1415
1516def test_search () -> None :
1617 instrument = a .Instrument ("EUI" )
@@ -336,6 +337,8 @@ def test_distance_time_search():
336337 assert res .file_num == 48
337338
338339
340+ # Remove this test and the mark from below once min sunpy dep >=7.1
341+ @pytest .mark .skipif (SUNPY_VERSION >= (7 , 1 ), reason = "Skip post sunpy 7.1" )
339342def test_distance_out_of_bounds_warning (recwarn ):
340343 instrument = a .Instrument ("EUI" )
341344 time = a .Time ("2023-04-27" , "2023-04-28" )
@@ -354,6 +357,21 @@ def test_distance_out_of_bounds_warning(recwarn):
354357 )
355358
356359
360+ @pytest .mark .skipif (SUNPY_VERSION < (7 , 1 ), reason = "Skip pre sunpy 7.1" )
361+ def test_distance_out_of_bounds_warning_post71 ():
362+ instrument = a .Instrument ("EUI" )
363+ time = a .Time ("2023-04-27" , "2023-04-28" )
364+ level = a .Level (2 )
365+ product = a .soar .Product ("eui-fsi174-image" )
366+ distance = a .soar .Distance (0.45 * u .AU , 1.2 * u .AU )
367+ # Run the search and ensure it raises an HTTPError
368+ query = Fido .search (distance & instrument & product & level & time )
369+ # Check if the warning was raised
370+ assert "Distance values must be within the range 0.28 AU to 1.0 AU." in str (query ['soar' ].errors )
371+
372+
373+ # Remove this test and the mark from below once min sunpy dep >=7.1
374+ @pytest .mark .skipif (SUNPY_VERSION >= (7 , 1 ), reason = "Skip post sunpy 7.1" )
357375@responses .activate
358376def test_soar_server_down () -> None :
359377 # As the SOAR server is expected to be down in this test, a JSONDecodeError is expected
@@ -375,3 +393,26 @@ def test_soar_server_down() -> None:
375393 match = r"The SOAR server returned an invalid JSON response. It may be down or not functioning correctly." ,
376394 ):
377395 Fido .search (time , level , product )
396+
397+
398+ @pytest .mark .skipif (SUNPY_VERSION < (7 , 1 ), reason = "Skip pre sunpy 7.1" )
399+ @responses .activate
400+ def test_soar_server_down_post71 () -> None :
401+ # As the SOAR server is expected to be down in this test, a JSONDecodeError is expected
402+ # to be raised due to the absence of a valid JSON response.
403+ tap_endpoint = (
404+ "http://soar.esac.esa.int/soar-sl-tap/tap/sync?REQUEST=doQuery&LANG=ADQL&FORMAT=json&QUERY=SELECT"
405+ " * FROM v_ll_data_item WHERE begin_time%3E='2020-11-13 00:00:00' AND "
406+ "begin_time%3C='2020-11-14 00:00:00' AND level='LL02' AND descriptor='mag'"
407+ )
408+ # We do not give any json data similar to the condition when the server is down.
409+ responses .add (responses .GET , tap_endpoint , body = "Invalid JSON response" , status = 200 )
410+
411+ time = a .Time ("2020-11-13" , "2020-11-14" )
412+ level = a .Level ("LL02" )
413+ product = a .soar .Product ("mag" )
414+
415+ query = Fido .search (time , level , product )
416+ assert isinstance (query ['soar' ].errors , RuntimeError )
417+ assert ("The SOAR server returned an invalid JSON response. It may be down or not functioning correctly."
418+ == str (query ['soar' ].errors ))
0 commit comments