Commit 3a6efd3f authored by Derek Homeier's avatar Derek Homeier
Browse files

First tests for search() (exceptions)

parent 63439fe8
import urllib.request
from urllib.error import HTTPError, URLError
import pytest
from sunpy.net import attrs as a
import client as kisclient
_BASE_URL = "http://dockertest:8083/sdc/"
try:
res = urllib.request.urlopen(_BASE_URL)
HAS_DOCKERTEST = True
except(HTTPError, URLError):
HAS_DOCKERTEST = False
@pytest.fixture
def client():
return kisclient.KISClient()
def test_search(client):
"""Test conversion of Attrs to query string."""
with pytest.raises(AttributeError, match=r"Query not possible: "
r"No 'Instrument' found in Attributes"):
client.search(a.Time("2019/01/01", "2021/01/01"))
with pytest.raises(AttributeError, match=r"Query not possible: "
r"Instrument UVES not in registered list"):
client.search(a.Instrument("UVES") & a.Time("2019/01/01", "2021/01/01"))
# TODO: Verify the actual return from the RESTHeart server.
if HAS_DOCKERTEST:
res = client.search(a.Time("2019/01/01", "2021/01/01") & a.Instrument("GRIS"))
else:
with pytest.raises(URLError, match=r"Unable to execute search "
r".http://dockertest:8083/sdc/gris_observations.filter="
r"{'.and':.{'description.INSTRUMENT':'gris'},"
r"{'description.DATE.BEG':{'.le':{'2021-01-01T00:00:00.000'}}},"
r"{'description.DATE_END':{'.ge':{'2019-01-01T00:00:00.000'}}}.}"
rf".*Confirm that RESTHeart is running on {_BASE_URL} and connected"):
client.search(a.Instrument("GRIS") & a.Time("2019/01/01", "2021/01/01"))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment