Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrew Leonard
kisfido
Commits
3a6efd3f
Commit
3a6efd3f
authored
Oct 17, 2021
by
Derek Homeier
Browse files
First tests for search() (exceptions)
parent
63439fe8
Changes
1
Hide whitespace changes
Inline
Side-by-side
python-user-api/tests/test_client.py
0 → 100644
View file @
3a6efd3f
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"
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment