Skip to content
10 changes: 10 additions & 0 deletions docs/dev_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ will run checks on the code style using precommit hooks.
``pytest``
==========

.. note::

We run the test suite with the beta version of the Helioviewer API.
So if you run **pytest** without it, the tests will fail.
This is set automatically when you use **tox**.

There are two ways to change this.
1. Set the environment variable ``HELIOVIEWER_API_URL`` to ``https://api.beta.helioviewer.org/v2/``.
2. Add ``HELIOVIEWER_API_URL="https://api.beta.helioviewer.org/v2/"`` to the command line when you run **pytest**.

The test suite can also be run directly from the native ``pytest`` command, which is generally faster than using tox for iterative development.
In this case, it is important for developers to be aware that they must manually rebuild any extensions by running::

Expand Down
6 changes: 3 additions & 3 deletions hvpy/api_groups/jpeg2000/tests/test_get_jp2_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@


def test_getJP2HeaderInputParameters():
response = getJP2Header(id=9838343)
response = getJP2Header(id=7654321)
assert isinstance(response, str)
assert response.startswith("<?xml")
assert response.endswith("</meta>")

response = getJP2Header(id=9838343, callback="my_callback")
response = getJP2Header(id=7654321, callback="my_callback")
assert isinstance(response, str)
assert response.startswith("my_callback(")

Expand All @@ -22,4 +22,4 @@ def test_error_handling():

def test_url_property():
params = getJP2HeaderInputParameters(id=9838343)
assert params.url == "https://api.helioviewer.org/v2/getJP2Header/"
assert params.url == "https://api.beta.helioviewer.org/v2/getJP2Header/"
28 changes: 13 additions & 15 deletions hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
from datetime import datetime

import pytest

from hvpy import getJP2Image
from hvpy.api_groups.jpeg2000.get_jp2_image import getJP2ImageInputParameters


def test_str_response():
response = getJP2Image(date=datetime(2022, 1, 1, 23, 59, 59), sourceId=14, jpip=True, json=False)
def test_str_response(date):
response = getJP2Image(date=date, sourceId=14, jpip=True, json=False)
assert isinstance(response, str)
assert response.startswith("jpip://")


def test_json_response():
response = getJP2Image(date=datetime(2022, 1, 1, 23, 59, 59), sourceId=14, jpip=True, json=True)
def test_json_response(date):
response = getJP2Image(date=date, sourceId=14, jpip=True, json=True)
assert isinstance(response, dict)
assert "uri" in response
assert response["uri"].startswith("jpip://")


def test_raw_response():
response = getJP2Image(date=datetime(2022, 1, 1, 23, 59, 59), sourceId=14, jpip=False, json=False)
def test_raw_response(date):
response = getJP2Image(date=date, sourceId=14, jpip=False, json=False)
assert isinstance(response, bytes)


def test_raw_response_with_json():
response = getJP2Image(date=datetime(2022, 1, 1, 23, 59, 59), sourceId=14, jpip=False, json=True)
def test_raw_response_with_json(date):
response = getJP2Image(date=date, sourceId=14, jpip=False, json=True)
assert isinstance(response, bytes)


def test_default_response():
response = getJP2Image(date=datetime(2022, 1, 1, 23, 59, 59), sourceId=14)
def test_default_response(date):
response = getJP2Image(date=date, sourceId=14)
assert isinstance(response, bytes)


Expand All @@ -39,7 +37,7 @@ def test_error_handling():
getJP2Image(sourceId=14, jpip=True, json=True)


def test_url_property():
params = {"date": datetime(2022, 1, 1, 23, 59, 59), "sourceId": 14, "jpip": True, "json": True}
def test_url_property(date):
params = {"date": date, "sourceId": 14, "jpip": True, "json": True}
params = getJP2ImageInputParameters(**params)
assert params.url == "https://api.helioviewer.org/v2/getJP2Image/"
assert params.url == "https://api.beta.helioviewer.org/v2/getJP2Image/"
48 changes: 24 additions & 24 deletions hvpy/api_groups/jpeg2000/tests/test_get_jpx.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
from datetime import datetime

import pytest

from hvpy import getJPX
from hvpy.api_groups.jpeg2000.get_jpx import getJPXInputParameters


def test_raw_response():
def test_raw_response(start_time, end_time):
response = getJPX(
startTime=datetime(2014, 1, 1, 0, 0, 0),
endTime=datetime(2014, 1, 1, 0, 45, 0),
startTime=start_time,
endTime=end_time,
sourceId=14,
linked=False,
verbose=False,
jpip=False,
cadence=None,
cadence=60,
)
assert isinstance(response, bytes)


def test_str_response():
def test_str_response(start_time, end_time):
response = getJPX(
startTime=datetime(2014, 1, 1, 0, 0, 0),
endTime=datetime(2014, 1, 1, 0, 45, 0),
startTime=start_time,
endTime=end_time,
sourceId=14,
linked=False,
verbose=False,
jpip=True,
cadence=None,
cadence=60,
)
assert isinstance(response, str)
assert response.startswith("jpip://")


def test_json_response():
def test_json_response(start_time, end_time):
response = getJPX(
startTime=datetime(2014, 1, 1, 0, 0, 0),
endTime=datetime(2014, 1, 1, 0, 45, 0),
startTime=start_time,
endTime=end_time,
sourceId=14,
linked=False,
verbose=True,
jpip=True,
cadence=None,
cadence=60,
)
assert isinstance(response, dict)
assert response["uri"].startswith("jpip://")

response = getJPX(
startTime=datetime(2014, 1, 1, 0, 0, 0),
endTime=datetime(2014, 1, 1, 0, 45, 0),
startTime=start_time,
endTime=end_time,
sourceId=14,
linked=False,
verbose=True,
jpip=False,
cadence=None,
cadence=60,
)
assert isinstance(response, dict)
assert response["uri"].startswith("https://")


def test_error_handling():
def test_error_handling(start_time, end_time):
with pytest.raises(TypeError, match="missing 1 required positional argument: 'startTime'"):
getJPX(endTime=datetime(2014, 1, 1, 0, 45, 0), sourceId=14)
getJPX(endTime=end_time, sourceId=14)
with pytest.raises(TypeError, match="missing 1 required positional argument: 'endTime'"):
getJPX(startTime=datetime(2014, 1, 1, 0, 0, 0), sourceId=14)
getJPX(startTime=start_time, sourceId=14)
with pytest.raises(TypeError, match="missing 1 required positional argument: 'sourceId'"):
getJPX(startTime=datetime(2014, 1, 1, 0, 0, 0), endTime=datetime(2014, 1, 1, 0, 45, 0))
getJPX(startTime=start_time, endTime=end_time)


def test_url_property():
def test_url_property(start_time, end_time):
params = getJPXInputParameters(
startTime=datetime(2014, 1, 1, 0, 0, 0), endTime=datetime(2014, 1, 1, 0, 45, 0), sourceId=14
startTime=start_time,
endTime=end_time,
sourceId=14,
)
assert params.url == "https://api.helioviewer.org/v2/getJPX/"
assert params.url == "https://api.beta.helioviewer.org/v2/getJPX/"
33 changes: 14 additions & 19 deletions hvpy/api_groups/jpeg2000/tests/test_get_jpx_closest_to_mid_point.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
from datetime import datetime

import pytest

from hvpy import getJPXClosestToMidPoint
from hvpy.api_groups.jpeg2000.get_jpx_closest_to_mid_point import getJPXClosestToMidPointInputParameters

startTimes = [datetime(2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 2, 3, 3), datetime(2014, 1, 1, 4, 5, 5)]
endTimes = [datetime(2014, 1, 1, 0, 45, 0), datetime(2014, 1, 1, 2, 33, 3), datetime(2014, 1, 1, 4, 54, 5)]


def test_raw_response():
def test_raw_response(start_times, end_times):
response = getJPXClosestToMidPoint(
startTimes=startTimes, endTimes=endTimes, sourceId=14, linked=False, verbose=False, jpip=False
startTimes=start_times, endTimes=end_times, sourceId=14, linked=False, verbose=False, jpip=False
)
assert isinstance(response, bytes)


def test_str_response():
def test_str_response(start_times, end_times):
response = getJPXClosestToMidPoint(
startTimes=startTimes, endTimes=endTimes, sourceId=14, linked=False, verbose=False, jpip=True
startTimes=start_times, endTimes=end_times, sourceId=14, linked=False, verbose=False, jpip=True
)
assert isinstance(response, str)
assert response.startswith("jpip://")


def test_json_response():
def test_json_response(start_times, end_times):
response = getJPXClosestToMidPoint(
startTimes=startTimes, endTimes=endTimes, sourceId=14, linked=False, verbose=True, jpip=True
startTimes=start_times, endTimes=end_times, sourceId=14, linked=False, verbose=True, jpip=True
)
assert isinstance(response, dict)
assert response["uri"].startswith("jpip://")

response = getJPXClosestToMidPoint(
startTimes=startTimes, endTimes=endTimes, sourceId=14, linked=False, verbose=True, jpip=False
startTimes=start_times, endTimes=end_times, sourceId=14, linked=False, verbose=True, jpip=False
)
assert isinstance(response, dict)
assert response["uri"].startswith("https://")


def test_error_handling():
def test_error_handling(start_times, end_times):
with pytest.raises(TypeError, match="missing 1 required positional argument: 'startTimes'"):
getJPXClosestToMidPoint(endTimes=endTimes, sourceId=14)
getJPXClosestToMidPoint(endTimes=end_times, sourceId=14)
with pytest.raises(TypeError, match="missing 1 required positional argument: 'endTimes'"):
getJPXClosestToMidPoint(startTimes=startTimes, sourceId=14)
getJPXClosestToMidPoint(startTimes=start_times, sourceId=14)
with pytest.raises(TypeError, match="missing 1 required positional argument: 'sourceId'"):
getJPXClosestToMidPoint(startTimes=startTimes, endTimes=endTimes)
getJPXClosestToMidPoint(startTimes=start_times, endTimes=end_times)


def test_url_property():
params = getJPXClosestToMidPointInputParameters(startTimes=startTimes, endTimes=endTimes, sourceId=14)
assert params.url == "https://api.helioviewer.org/v2/getJPXClosestToMidPoint/"
def test_url_property(start_times, end_times):
params = getJPXClosestToMidPointInputParameters(startTimes=start_times, endTimes=end_times, sourceId=14)
assert params.url == "https://api.beta.helioviewer.org/v2/getJPXClosestToMidPoint/"
2 changes: 1 addition & 1 deletion hvpy/api_groups/jpeg2000/tests/test_get_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def test_getStatusInputParameters():

def test_url_property():
params = getStatusInputParameters()
assert params.url == "https://api.helioviewer.org/v2/getStatus/"
assert params.url == "https://api.beta.helioviewer.org/v2/getStatus/"
6 changes: 3 additions & 3 deletions hvpy/api_groups/movies/tests/test_get_movie_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def test_json_response():
response = getMovieStatus(
id="VXvX5",
id="h2n6n",
format="mp4",
)
assert response["url"] is not None
Expand All @@ -15,7 +15,7 @@ def test_json_response():

def test_str_response():
response = getMovieStatus(
id="VXvX5",
id="h2n6n",
format="mp4",
callback="myCallback",
)
Expand Down Expand Up @@ -45,4 +45,4 @@ def test_url_property():
id="VXvX5",
format="mp4",
)
assert params.url == "https://api.helioviewer.org/v2/getMovieStatus/"
assert params.url == "https://api.beta.helioviewer.org/v2/getMovieStatus/"
22 changes: 10 additions & 12 deletions hvpy/api_groups/movies/tests/test_queue_movie.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from datetime import datetime

import pytest

from hvpy import queueMovie
from hvpy.api_groups.movies.queue_movie import queueMovieInputParameters


def test_json_response():
def test_json_response(start_time, end_time):
response = queueMovie(
startTime=datetime(2022, 7, 20, 12, 12, 12),
endTime=datetime(2022, 7, 21, 12, 12, 12),
startTime=start_time,
endTime=end_time,
layers="[12,7,22],[13,7,22]",
events="[AR,HMI_HARP;SPoCA,1],[CH,all,1]",
eventsLabels=False,
Expand All @@ -21,24 +19,24 @@ def test_json_response():
assert response["token"] is not None


def test_error_handling():
def test_error_handling(start_time, end_time):
with pytest.raises(TypeError, match="missing 1 required positional argument: 'imageScale'"):
queueMovie(
startTime=datetime(2022, 7, 20, 12, 12, 12),
endTime=datetime(2022, 7, 21, 12, 12, 12),
startTime=start_time,
endTime=end_time,
layers="[12,7,22],[13,7,22]",
events="[AR,HMI_HARP;SPoCA,1],[CH,all,1]",
eventsLabels=False,
)


def test_url_property():
def test_url_property(start_time, end_time):
params = queueMovieInputParameters(
startTime=datetime(2022, 7, 20, 12, 12, 12),
endTime=datetime(2022, 7, 21, 12, 12, 12),
startTime=start_time,
endTime=end_time,
layers="[12,7,22],[13,7,22]",
events="[AR,HMI_HARP;SPoCA,1],[CH,all,1]",
eventsLabels=False,
imageScale=1,
)
assert params.url == "https://api.helioviewer.org/v2/queueMovie/"
assert params.url == "https://api.beta.helioviewer.org/v2/queueMovie/"
2 changes: 1 addition & 1 deletion hvpy/api_groups/movies/tests/test_re_queue_movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def test_error_handling():

def test_url_property():
params = reQueueMovieInputParameters(id="gxRN5")
assert params.url == "https://api.helioviewer.org/v2/reQueueMovie/"
assert params.url == "https://api.beta.helioviewer.org/v2/reQueueMovie/"
20 changes: 9 additions & 11 deletions hvpy/api_groups/official_clients/tests/test_get_closest_image.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
from datetime import datetime

import pytest

from hvpy import getClosestImage
from hvpy.api_groups.official_clients.get_closest_image import getClosestImageInputParameters


def test_json_res():
response = getClosestImage(date=datetime(2014, 1, 1, 23, 59, 59), sourceId=14)
def test_json_res(date):
response = getClosestImage(date=date, sourceId=14)
assert isinstance(response, dict)


def test_str_res():
response = getClosestImage(date=datetime(2014, 1, 1, 23, 59, 59), sourceId=14, callback="callback")
def test_str_res(date):
response = getClosestImage(date=date, sourceId=14, callback="callback")
assert isinstance(response, str)
assert response.startswith("callback")


def test_error_handling():
def test_error_handling(date):
with pytest.raises(TypeError, match="missing 1 required positional argument: 'date'"):
getClosestImage(sourceId=14)
with pytest.raises(TypeError, match="missing 1 required positional argument: 'sourceId'"):
getClosestImage(date=datetime(2014, 1, 1, 23, 59, 59))
getClosestImage(date=date)


def test_url_property():
params = getClosestImageInputParameters(date=datetime(2014, 1, 1, 23, 59, 59), sourceId=14)
assert params.url == "https://api.helioviewer.org/v2/getClosestImage/"
def test_url_property(date):
params = getClosestImageInputParameters(date=date, sourceId=14)
assert params.url == "https://api.beta.helioviewer.org/v2/getClosestImage/"
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_raw_response():

def test_url_property():
params = downloadScreenshotInputParameters(id=3240748)
assert params.url == "https://api.helioviewer.org/v2/downloadScreenshot/"
assert params.url == "https://api.beta.helioviewer.org/v2/downloadScreenshot/"


def test_error_handling():
Expand Down
Loading