From e2aa6c9c7ccd1eb1315bee539909d970ca281202 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Mon, 6 Jun 2022 23:10:38 +0530 Subject: [PATCH 01/51] getjp2header image endpoint --- .gitignore | 1 + hvpy/api.py | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c6ac0ca..7fa4cbf 100644 --- a/.gitignore +++ b/.gitignore @@ -89,6 +89,7 @@ ipython_config.py # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. +Pipfile #Pipfile.lock # PEP 582; used by e.g. github.com/David-OConnor/pyflow diff --git a/hvpy/api.py b/hvpy/api.py index 8388e3d..541ccd8 100644 --- a/hvpy/api.py +++ b/hvpy/api.py @@ -1,13 +1,95 @@ __all__ = ["fake_api_call"] +from datetime import datetime +from typing import Optional +import requests +from pydantic import BaseModel -def fake_api_call(): + +Json = "json" + + +class InputParameters(BaseModel): + date: datetime + sourceId: int + jpip: Optional[bool] = False + Json: Optional[bool] = False + + +def binary(response: requests.Response): + return response.content + + +def url(response: requests.Response): + return response.url + + +def json(response: requests.Response): + return response.json() + + +def parse_response(response, output_parameters: str): + """ + _summary_ + + Parameters + ---------- + response: ? + _description_ + output_parameters: ? + _description_ + + Returns + ------- + _type_ + _description_ + """ + switch = { + "binary": binary(response), + "json": json(response), + "url": url(response), + } + return switch.get(output_parameters, response)() + + +def execute_api_call(url: str, input_parameters: dict, output_parameters): """ _summary_ + Parameters + ---------- + url: str + _description_ + input_parameters: dict + _description_ + output_parameters: ? + _description_ + Returns ------- _type_ _description_ """ - return {} + params = InputParameters(**input_parameters) + response = requests.get(url, params=params) + print(response.url) + # check if we have a valid response + if response.status_code != 200: + raise Exception(f"API call failed with status code {response.status_code}") + + # return parse_response(response, output_parameters) + + +if __name__ == "__main__": + + URL = "https://api.helioviewer.org/v2/getJP2Image/" + DATE = datetime(2003, 10, 6, 0, 0, 0, 0).isoformat() + "Z" + SOURCE_ID = "14" + data = {"date": DATE, "sourceId": SOURCE_ID} + + r = requests.get(url, params=data) + print(r.url) + # input_parameters = {"date": datetime(2014, 1, 1, 0, 0, 0).isoformat() + "Z", "sourceId": 14} + + # r = execute_api_call(url=URL, input_parameters=input_parameters, output_parameters="url") + # print(r) From b018b05fc533e8d77624ebfb5a7821b55fae54bd Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 7 Jun 2022 12:11:18 +0530 Subject: [PATCH 02/51] use pydantic for i/o parameters --- hvpy/api.py | 57 ++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/hvpy/api.py b/hvpy/api.py index 541ccd8..e35be07 100644 --- a/hvpy/api.py +++ b/hvpy/api.py @@ -3,32 +3,17 @@ from datetime import datetime from typing import Optional import requests -from pydantic import BaseModel - - -Json = "json" +from pydantic import BaseModel, Field class InputParameters(BaseModel): date: datetime sourceId: int - jpip: Optional[bool] = False - Json: Optional[bool] = False - - -def binary(response: requests.Response): - return response.content - + jpip: Optional[bool] = Field(False, alias="jpip") + Json: Optional[bool] = Field(False, alias="json") -def url(response: requests.Response): - return response.url - -def json(response: requests.Response): - return response.json() - - -def parse_response(response, output_parameters: str): +def parse_response(response: requests.Response, output_parameters: str): """ _summary_ @@ -44,15 +29,15 @@ def parse_response(response, output_parameters: str): _type_ _description_ """ - switch = { - "binary": binary(response), - "json": json(response), - "url": url(response), - } - return switch.get(output_parameters, response)() + if output_parameters == "binary": + return response.content + elif output_parameters == "url": + return response.url + elif output_parameters == "json": + return response.json() -def execute_api_call(url: str, input_parameters: dict, output_parameters): +def execute_api_call(url: str, input_parameters: dict, output_parameters: str): """ _summary_ @@ -71,25 +56,25 @@ def execute_api_call(url: str, input_parameters: dict, output_parameters): _description_ """ params = InputParameters(**input_parameters) + params.date = params.date.isoformat() + "Z" + response = requests.get(url, params=params) - print(response.url) # check if we have a valid response if response.status_code != 200: raise Exception(f"API call failed with status code {response.status_code}") - # return parse_response(response, output_parameters) + return parse_response(response, output_parameters) if __name__ == "__main__": URL = "https://api.helioviewer.org/v2/getJP2Image/" - DATE = datetime(2003, 10, 6, 0, 0, 0, 0).isoformat() + "Z" - SOURCE_ID = "14" - data = {"date": DATE, "sourceId": SOURCE_ID} + DATE = datetime(2022, 1, 1, 23, 59, 59) + + input_parameters = {"date": DATE, "sourceId": 14} - r = requests.get(url, params=data) - print(r.url) - # input_parameters = {"date": datetime(2014, 1, 1, 0, 0, 0).isoformat() + "Z", "sourceId": 14} + r = execute_api_call(url=URL, input_parameters=input_parameters, output_parameters="binary") - # r = execute_api_call(url=URL, input_parameters=input_parameters, output_parameters="url") - # print(r) + # Save the image to a file + with open("test.jp2", "wb") as f: + f.write(r) From d4946d99a4a71a67dab82a973ebdc5c7feaa04e3 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> Date: Tue, 7 Jun 2022 13:13:51 -0400 Subject: [PATCH 03/51] Add dict function that renames Json to json --- hvpy/api.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/hvpy/api.py b/hvpy/api.py index e35be07..b4d5869 100644 --- a/hvpy/api.py +++ b/hvpy/api.py @@ -9,8 +9,17 @@ class InputParameters(BaseModel): date: datetime sourceId: int - jpip: Optional[bool] = Field(False, alias="jpip") - Json: Optional[bool] = Field(False, alias="json") + jpip: Optional[bool] = Field(False) + Json: Optional[bool] = Field(False, alias='json') + + def dict(self): + d = super().dict() + # Pydantic doesn't allow using lower case 'json' as a field, + # so override it here. + if 'Json' in d: + d['json'] = d['Json'] + del d['Json'] + return d def parse_response(response: requests.Response, output_parameters: str): @@ -58,7 +67,7 @@ def execute_api_call(url: str, input_parameters: dict, output_parameters: str): params = InputParameters(**input_parameters) params.date = params.date.isoformat() + "Z" - response = requests.get(url, params=params) + response = requests.get(url, params=params.dict()) # check if we have a valid response if response.status_code != 200: raise Exception(f"API call failed with status code {response.status_code}") @@ -71,7 +80,7 @@ def execute_api_call(url: str, input_parameters: dict, output_parameters: str): URL = "https://api.helioviewer.org/v2/getJP2Image/" DATE = datetime(2022, 1, 1, 23, 59, 59) - input_parameters = {"date": DATE, "sourceId": 14} + input_parameters = {"date": DATE, "sourceId": 14, 'json': True, 'jpip': True} r = execute_api_call(url=URL, input_parameters=input_parameters, output_parameters="binary") From d228d5cc37f7b00ea6a7cf3dc0838ba26854f799 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 7 Jun 2022 23:50:52 +0530 Subject: [PATCH 04/51] Remove print statement --- hvpy/api.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/hvpy/api.py b/hvpy/api.py index e35be07..89cb1ee 100644 --- a/hvpy/api.py +++ b/hvpy/api.py @@ -9,7 +9,7 @@ class InputParameters(BaseModel): date: datetime sourceId: int - jpip: Optional[bool] = Field(False, alias="jpip") + jpip: Optional[bool] = False Json: Optional[bool] = Field(False, alias="json") @@ -71,10 +71,6 @@ def execute_api_call(url: str, input_parameters: dict, output_parameters: str): URL = "https://api.helioviewer.org/v2/getJP2Image/" DATE = datetime(2022, 1, 1, 23, 59, 59) - input_parameters = {"date": DATE, "sourceId": 14} + input_parameters = {"date": DATE, "sourceId": 14, "jpip": True} - r = execute_api_call(url=URL, input_parameters=input_parameters, output_parameters="binary") - - # Save the image to a file - with open("test.jp2", "wb") as f: - f.write(r) + r = execute_api_call(url=URL, input_parameters=input_parameters, output_parameters="url") From cf48785d901ba7a9feaf95fbcd236bc3e2d78965 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Fri, 10 Jun 2022 15:18:00 +0530 Subject: [PATCH 05/51] initial setup --- hvpy/api.py | 65 +++---------------------- hvpy/api_groups/jpeg2000/getJp2Image.py | 20 ++++++++ hvpy/core.py | 1 + hvpy/io.py | 18 +++++++ hvpy/tests/test_fake.py | 9 ---- setup.cfg | 1 + 6 files changed, 48 insertions(+), 66 deletions(-) create mode 100644 hvpy/api_groups/jpeg2000/getJp2Image.py create mode 100644 hvpy/core.py create mode 100644 hvpy/io.py delete mode 100644 hvpy/tests/test_fake.py diff --git a/hvpy/api.py b/hvpy/api.py index d577528..de59f24 100644 --- a/hvpy/api.py +++ b/hvpy/api.py @@ -1,44 +1,12 @@ -__all__ = ["fake_api_call"] - from datetime import datetime -from typing import Optional +from api_groups.jpeg2000.getJp2Image import getJP2ImageInputParameters as InputParameters import requests -from pydantic import BaseModel, Field - - -class InputParameters(BaseModel): - date: datetime - sourceId: int - jpip: Optional[bool] = Field(False) - Json: Optional[bool] = Field(False, alias='json') - - def dict(self): - d = super().dict() - # Pydantic doesn't allow using lower case 'json' as a field, - # so override it here. - if 'Json' in d: - d['json'] = d['Json'] - del d['Json'] - return d - +# create `io.py` and add an enum class OutputType to handle the different output_parameters def parse_response(response: requests.Response, output_parameters: str): - """ - _summary_ - - Parameters - ---------- - response: ? - _description_ - output_parameters: ? - _description_ - Returns - ------- - _type_ - _description_ - """ + # Once you have the OutputType class, let's change these to OutputType.Raw, OutputType.String, and OutputType.Json if output_parameters == "binary": return response.content elif output_parameters == "url": @@ -48,27 +16,8 @@ def parse_response(response: requests.Response, output_parameters: str): def execute_api_call(url: str, input_parameters: dict, output_parameters: str): - """ - _summary_ - - Parameters - ---------- - url: str - _description_ - input_parameters: dict - _description_ - output_parameters: ? - _description_ - - Returns - ------- - _type_ - _description_ - """ - params = InputParameters(**input_parameters) - params.date = params.date.isoformat() + "Z" - response = requests.get(url, params=params.dict()) + response = requests.get(url, params=input_parameters()) # check if we have a valid response if response.status_code != 200: raise Exception(f"API call failed with status code {response.status_code}") @@ -76,11 +25,13 @@ def execute_api_call(url: str, input_parameters: dict, output_parameters: str): return parse_response(response, output_parameters) +# This should be in unit tests if __name__ == "__main__": URL = "https://api.helioviewer.org/v2/getJP2Image/" DATE = datetime(2022, 1, 1, 23, 59, 59) - input_parameters = {"date": DATE, "sourceId": 14, 'json': True, 'jpip': True} + input_parameters = InputParameters(date=DATE, sourceId=1) + input_parameters.date = input_parameters.date.isoformat() + "Z" - r = execute_api_call(url=URL, input_parameters=input_parameters, output_parameters="url") + r = execute_api_call(url=URL, input_parameters=input_parameters.dict(), output_parameters="url") diff --git a/hvpy/api_groups/jpeg2000/getJp2Image.py b/hvpy/api_groups/jpeg2000/getJp2Image.py new file mode 100644 index 0000000..265b724 --- /dev/null +++ b/hvpy/api_groups/jpeg2000/getJp2Image.py @@ -0,0 +1,20 @@ +# Contains I/O parameters for getJp2Image +from datetime import datetime +from typing import Optional +from pydantic import BaseModel + + +class getJP2ImageInputParameters(BaseModel): + date: datetime + sourceId: int + jpip: Optional[bool] = False + Json: Optional[bool] = False + + def dict(self): + d = super().dict() + # Pydantic doesn't allow using lower case 'json' as a field, + # so override it here. + if "Json" in d: + d["json"] = d["Json"] + del d["Json"] + return d diff --git a/hvpy/core.py b/hvpy/core.py new file mode 100644 index 0000000..61e3c1d --- /dev/null +++ b/hvpy/core.py @@ -0,0 +1 @@ +# Contains the API Requester which handles all HTTP I/O diff --git a/hvpy/io.py b/hvpy/io.py new file mode 100644 index 0000000..f04ee49 --- /dev/null +++ b/hvpy/io.py @@ -0,0 +1,18 @@ +# Add an enum class to handle different output_parameters +# OutputType.Raw, OutputType.String, and OutputType.Json +# Add a function to handle output_parameters +from pydantic import BaseModel + + +class HvpyParameters(BaseModel): + def dict(self): + d = super().dict() + # Pydantic doesn't allow using lower case 'json' as a field, + # so override it here. + if "Json" in d: + d["json"] = d["Json"] + del d["Json"] + return d + + def get_output_type(self): + return OutputType.Raw diff --git a/hvpy/tests/test_fake.py b/hvpy/tests/test_fake.py deleted file mode 100644 index c815117..0000000 --- a/hvpy/tests/test_fake.py +++ /dev/null @@ -1,9 +0,0 @@ -from hvpy import fake_api_call - - -def test_test_fake(): - assert True - - -def test_fake_api_call(): - assert fake_api_call() == {} diff --git a/setup.cfg b/setup.cfg index 8711e67..030fb93 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,6 +33,7 @@ setup_requires = setuptools_scm install_requires = requests>=2.27.0 + pydantic>=1.9.1 [options.extras_require] tests = From ef72ef4cc2dd357d60ddf2ec4ad7b76aa2b6007f Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 14 Jun 2022 21:45:44 +0530 Subject: [PATCH 06/51] Initialize the Base io --- hvpy/io.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hvpy/io.py b/hvpy/io.py index f04ee49..1655997 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -1,6 +1,4 @@ -# Add an enum class to handle different output_parameters -# OutputType.Raw, OutputType.String, and OutputType.Json -# Add a function to handle output_parameters +from enum import Enum from pydantic import BaseModel @@ -15,4 +13,12 @@ def dict(self): return d def get_output_type(self): + # For now just return the raw output return OutputType.Raw + + +class OutputType(Enum): + # temporary strings, untill meeting with the team + Raw = "binary" + String = "string" + Json = "json" From d3595e3d5db3663feea4ed43250e27556a08f3b6 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 14 Jun 2022 22:09:02 +0530 Subject: [PATCH 07/51] Initialize the Base core --- hvpy/__init__.py | 2 +- hvpy/api.py | 37 ------------------------------------- hvpy/core.py | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 39 deletions(-) delete mode 100644 hvpy/api.py diff --git a/hvpy/__init__.py b/hvpy/__init__.py index 327412a..f163d16 100644 --- a/hvpy/__init__.py +++ b/hvpy/__init__.py @@ -1,2 +1,2 @@ -from .api import * # NOQA from .version import __version__ +from .io import HvpyParameters, OutputType diff --git a/hvpy/api.py b/hvpy/api.py deleted file mode 100644 index de59f24..0000000 --- a/hvpy/api.py +++ /dev/null @@ -1,37 +0,0 @@ -from datetime import datetime -from api_groups.jpeg2000.getJp2Image import getJP2ImageInputParameters as InputParameters -import requests - - -# create `io.py` and add an enum class OutputType to handle the different output_parameters -def parse_response(response: requests.Response, output_parameters: str): - - # Once you have the OutputType class, let's change these to OutputType.Raw, OutputType.String, and OutputType.Json - if output_parameters == "binary": - return response.content - elif output_parameters == "url": - return response.url - elif output_parameters == "json": - return response.json() - - -def execute_api_call(url: str, input_parameters: dict, output_parameters: str): - - response = requests.get(url, params=input_parameters()) - # check if we have a valid response - if response.status_code != 200: - raise Exception(f"API call failed with status code {response.status_code}") - - return parse_response(response, output_parameters) - - -# This should be in unit tests -if __name__ == "__main__": - - URL = "https://api.helioviewer.org/v2/getJP2Image/" - DATE = datetime(2022, 1, 1, 23, 59, 59) - - input_parameters = InputParameters(date=DATE, sourceId=1) - input_parameters.date = input_parameters.date.isoformat() + "Z" - - r = execute_api_call(url=URL, input_parameters=input_parameters.dict(), output_parameters="url") diff --git a/hvpy/core.py b/hvpy/core.py index 61e3c1d..19c8fca 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -1 +1,20 @@ -# Contains the API Requester which handles all HTTP I/O +import requests + + +def parse_response(response: requests.Response, output_parameters: str): + # TODO: replace with OutputType class + if output_parameters == "binary": + return response.content + elif output_parameters == "url": + return response.url + elif output_parameters == "json": + return response.json() + + +def execute_api_call(url: str, input_parameters: dict, output_parameters: str): + response = requests.get(url, params=input_parameters()) + # check if we have a valid response + if response.status_code != 200: + raise Exception(f"API call failed with status code {response.status_code}") + + return parse_response(response, output_parameters) From a8e73ff275962568276df9a94fc5593a2f4e4e2a Mon Sep 17 00:00:00 2001 From: akash5100 Date: Wed, 15 Jun 2022 15:57:30 +0530 Subject: [PATCH 08/51] Replace string with OutputType --- hvpy/__init__.py | 1 - hvpy/api_groups/__init__.py | 0 hvpy/api_groups/jpeg2000/__init__.py | 0 hvpy/api_groups/jpeg2000/getJp2Image.py | 20 -------------------- hvpy/api_groups/jpeg2000/get_jp2_image.py | 10 ++++++++++ hvpy/core.py | 16 +++++++++------- hvpy/io.py | 9 +++++---- hvpy/tests/test_get_jp2_image.py | 19 +++++++++++++++++++ 8 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 hvpy/api_groups/__init__.py create mode 100644 hvpy/api_groups/jpeg2000/__init__.py delete mode 100644 hvpy/api_groups/jpeg2000/getJp2Image.py create mode 100644 hvpy/api_groups/jpeg2000/get_jp2_image.py create mode 100644 hvpy/tests/test_get_jp2_image.py diff --git a/hvpy/__init__.py b/hvpy/__init__.py index f163d16..58f3ace 100644 --- a/hvpy/__init__.py +++ b/hvpy/__init__.py @@ -1,2 +1 @@ from .version import __version__ -from .io import HvpyParameters, OutputType diff --git a/hvpy/api_groups/__init__.py b/hvpy/api_groups/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hvpy/api_groups/jpeg2000/__init__.py b/hvpy/api_groups/jpeg2000/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hvpy/api_groups/jpeg2000/getJp2Image.py b/hvpy/api_groups/jpeg2000/getJp2Image.py deleted file mode 100644 index 265b724..0000000 --- a/hvpy/api_groups/jpeg2000/getJp2Image.py +++ /dev/null @@ -1,20 +0,0 @@ -# Contains I/O parameters for getJp2Image -from datetime import datetime -from typing import Optional -from pydantic import BaseModel - - -class getJP2ImageInputParameters(BaseModel): - date: datetime - sourceId: int - jpip: Optional[bool] = False - Json: Optional[bool] = False - - def dict(self): - d = super().dict() - # Pydantic doesn't allow using lower case 'json' as a field, - # so override it here. - if "Json" in d: - d["json"] = d["Json"] - del d["Json"] - return d diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py new file mode 100644 index 0000000..34e36b8 --- /dev/null +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -0,0 +1,10 @@ +from datetime import datetime +from typing import Optional +from hvpy.io import HvpyParameters + + +class getJP2ImageInputParameters(HvpyParameters): + date: datetime + sourceId: int + jpip: Optional[bool] = False + Json: Optional[bool] = False diff --git a/hvpy/core.py b/hvpy/core.py index 19c8fca..4278397 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -1,17 +1,19 @@ import requests +from hvpy.io import OutputType -def parse_response(response: requests.Response, output_parameters: str): - # TODO: replace with OutputType class - if output_parameters == "binary": +def parse_response(response: requests.Response, output_parameters: OutputType): + + if output_parameters == OutputType.Raw: return response.content - elif output_parameters == "url": - return response.url - elif output_parameters == "json": + elif output_parameters == OutputType.String: + return str(response.content) + elif output_parameters == OutputType.Json: return response.json() -def execute_api_call(url: str, input_parameters: dict, output_parameters: str): +def execute_api_call(url: str, input_parameters: dict, output_parameters: OutputType): + response = requests.get(url, params=input_parameters()) # check if we have a valid response if response.status_code != 200: diff --git a/hvpy/io.py b/hvpy/io.py index 1655997..ea8e9fc 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -1,6 +1,8 @@ from enum import Enum from pydantic import BaseModel +BASE_URL = "https://api.helioviewer.org/v2/" + class HvpyParameters(BaseModel): def dict(self): @@ -18,7 +20,6 @@ def get_output_type(self): class OutputType(Enum): - # temporary strings, untill meeting with the team - Raw = "binary" - String = "string" - Json = "json" + Raw = 1 + String = 2 + Json = 3 diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py new file mode 100644 index 0000000..a25f2ad --- /dev/null +++ b/hvpy/tests/test_get_jp2_image.py @@ -0,0 +1,19 @@ +from hvpy.io import BASE_URL +from datetime import datetime +from hvpy.api_groups.jpeg2000.get_jp2_image import getJP2ImageInputParameters +from hvpy.io import OutputType, execute_api_call + +URL = BASE_URL + "getJP2Image/" + + +def test_get_jp2_image(): + + DATE = datetime(2022, 1, 1, 23, 59, 59) + + input = {"date": DATE, "sourceId": 14} + input = getJP2ImageInputParameters(input) + + output = OutputType.String + r = execute_api_call(url=URL, input_parameters=input.dict(), output_type=output) + + assert isinstance(r, str) From 8151856ffde18428a35e3f6e460dd2438b29ad73 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 15 Jun 2022 20:51:16 +0530 Subject: [PATCH 09/51] Update hvpy/tests/test_get_jp2_image.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/tests/test_get_jp2_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index a25f2ad..edb87d2 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -11,7 +11,7 @@ def test_get_jp2_image(): DATE = datetime(2022, 1, 1, 23, 59, 59) input = {"date": DATE, "sourceId": 14} - input = getJP2ImageInputParameters(input) + input = getJP2ImageInputParameters(**input) output = OutputType.String r = execute_api_call(url=URL, input_parameters=input.dict(), output_type=output) From 6e3b9920e16444d80d5f599ee3f6647da9baa46d Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 15 Jun 2022 20:52:02 +0530 Subject: [PATCH 10/51] Update hvpy/tests/test_get_jp2_image.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/tests/test_get_jp2_image.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index edb87d2..11cb9c7 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -1,7 +1,8 @@ from hvpy.io import BASE_URL from datetime import datetime from hvpy.api_groups.jpeg2000.get_jp2_image import getJP2ImageInputParameters -from hvpy.io import OutputType, execute_api_call +from hvpy.io import OutputType +from hvpy.core import execute_api_call URL = BASE_URL + "getJP2Image/" From e3d33fdab1d6efc9986d44ea532334ddab805c03 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 15 Jun 2022 20:52:33 +0530 Subject: [PATCH 11/51] Update hvpy/core.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/core.py b/hvpy/core.py index 4278397..e0c82c9 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -19,4 +19,4 @@ def execute_api_call(url: str, input_parameters: dict, output_parameters: Output if response.status_code != 200: raise Exception(f"API call failed with status code {response.status_code}") - return parse_response(response, output_parameters) + return parse_response(response, input_parameters.get_output_type()) From 0c6842dffeb97e448af056ffe64566f01b3d9396 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 15 Jun 2022 21:20:02 +0530 Subject: [PATCH 12/51] Update hvpy/core.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/core.py b/hvpy/core.py index e0c82c9..44407d4 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -12,7 +12,7 @@ def parse_response(response: requests.Response, output_parameters: OutputType): return response.json() -def execute_api_call(url: str, input_parameters: dict, output_parameters: OutputType): +def execute_api_call(url: str, input_parameters: HvpyParameters, output_parameters: OutputType): response = requests.get(url, params=input_parameters()) # check if we have a valid response From fe0dcb2361d79afe83082887e8baf1c9461dfe10 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 15 Jun 2022 21:20:26 +0530 Subject: [PATCH 13/51] Update hvpy/core.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/core.py b/hvpy/core.py index 44407d4..42bbc91 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -14,7 +14,7 @@ def parse_response(response: requests.Response, output_parameters: OutputType): def execute_api_call(url: str, input_parameters: HvpyParameters, output_parameters: OutputType): - response = requests.get(url, params=input_parameters()) + response = requests.get(url, params=input_parameters) # check if we have a valid response if response.status_code != 200: raise Exception(f"API call failed with status code {response.status_code}") From b39b3b49e2f2e1f2720dd4d33abfc6db958cc5b1 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Wed, 15 Jun 2022 21:22:48 +0530 Subject: [PATCH 14/51] Adds missing import --- hvpy/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/core.py b/hvpy/core.py index 42bbc91..a00a360 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -1,5 +1,5 @@ import requests -from hvpy.io import OutputType +from hvpy.io import HvpyParameters, OutputType def parse_response(response: requests.Response, output_parameters: OutputType): From 33768200a707e93d7f620c716bf93cc65e75d1ff Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Thu, 16 Jun 2022 00:53:44 +0530 Subject: [PATCH 15/51] Update hvpy/io.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/io.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hvpy/io.py b/hvpy/io.py index ea8e9fc..2f2e8c5 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -20,6 +20,6 @@ def get_output_type(self): class OutputType(Enum): - Raw = 1 - String = 2 - Json = 3 + Raw = auto() + String = auto() + Json = auto() From 20ec51f8cb2b6892225467d648ed16f5937d7ac4 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Thu, 16 Jun 2022 00:53:51 +0530 Subject: [PATCH 16/51] Update hvpy/io.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/io.py b/hvpy/io.py index 2f2e8c5..aa6f7ba 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -1,4 +1,4 @@ -from enum import Enum +from enum import Enum, auto from pydantic import BaseModel BASE_URL = "https://api.helioviewer.org/v2/" From 388390f38318c9d90cf39aa8834b68b0fc07791a Mon Sep 17 00:00:00 2001 From: akash5100 Date: Thu, 16 Jun 2022 01:43:05 +0530 Subject: [PATCH 17/51] isort fix --- hvpy/core.py | 5 +++-- hvpy/io.py | 5 +++-- hvpy/tests/test_get_jp2_image.py | 7 +++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hvpy/core.py b/hvpy/core.py index a00a360..33f0c4d 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -1,4 +1,5 @@ import requests + from hvpy.io import HvpyParameters, OutputType @@ -12,9 +13,9 @@ def parse_response(response: requests.Response, output_parameters: OutputType): return response.json() -def execute_api_call(url: str, input_parameters: HvpyParameters, output_parameters: OutputType): +def execute_api_call(url: str, input_parameters: HvpyParameters): - response = requests.get(url, params=input_parameters) + response = requests.get(url, params=input_parameters.dict()) # check if we have a valid response if response.status_code != 200: raise Exception(f"API call failed with status code {response.status_code}") diff --git a/hvpy/io.py b/hvpy/io.py index aa6f7ba..5df46ec 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -1,4 +1,5 @@ from enum import Enum, auto + from pydantic import BaseModel BASE_URL = "https://api.helioviewer.org/v2/" @@ -15,8 +16,8 @@ def dict(self): return d def get_output_type(self): - # For now just return the raw output - return OutputType.Raw + # For now just return the String output + return OutputType.String class OutputType(Enum): diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index 11cb9c7..778f333 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -1,8 +1,8 @@ -from hvpy.io import BASE_URL from datetime import datetime + from hvpy.api_groups.jpeg2000.get_jp2_image import getJP2ImageInputParameters -from hvpy.io import OutputType from hvpy.core import execute_api_call +from hvpy.io import BASE_URL URL = BASE_URL + "getJP2Image/" @@ -14,7 +14,6 @@ def test_get_jp2_image(): input = {"date": DATE, "sourceId": 14} input = getJP2ImageInputParameters(**input) - output = OutputType.String - r = execute_api_call(url=URL, input_parameters=input.dict(), output_type=output) + r = execute_api_call(url=URL, input_parameters=input) assert isinstance(r, str) From 7292e0cc05a9affe374184595046ea2bf6767f8b Mon Sep 17 00:00:00 2001 From: akash5100 Date: Thu, 16 Jun 2022 01:48:27 +0530 Subject: [PATCH 18/51] isort fix --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 34e36b8..fd4bafb 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -1,5 +1,6 @@ -from datetime import datetime from typing import Optional +from datetime import datetime + from hvpy.io import HvpyParameters From d92def48cc36b1ca7a1770189a20f432a3d75b6e Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Wed, 15 Jun 2022 13:42:01 -0700 Subject: [PATCH 19/51] Update setup.cfg --- setup.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 030fb93..6fe75b7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,9 +50,6 @@ norecursedirs = ".tox" "build" "docs[\/]_build" "docs[\/]generated" "*.egg-info" doctest_plus = enabled doctest_optionflags = NORMALIZE_WHITESPACE FLOAT_CMP ELLIPSIS addopts = --doctest-rst --doctest-ignore-import-errors -p no:unraisableexception -p no:threadexception -markers = - remote_data: marks this test function as needing remote data. -remote_data_strict = True filterwarnings = error # Do not fail on pytest config issues (i.e. missing plugins) but do show them From 3138b3f5f64a5d604451eb04c185a805c33bc99a Mon Sep 17 00:00:00 2001 From: akash5100 Date: Fri, 17 Jun 2022 11:48:06 +0530 Subject: [PATCH 20/51] fix precommit failure --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 7 +++++++ hvpy/core.py | 10 ++++------ hvpy/io.py | 3 +++ hvpy/tests/test_get_jp2_image.py | 21 +++++++++++---------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index fd4bafb..238a8ca 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -1,6 +1,8 @@ from typing import Optional from datetime import datetime +from pydantic import validator + from hvpy.io import HvpyParameters @@ -9,3 +11,8 @@ class getJP2ImageInputParameters(HvpyParameters): sourceId: int jpip: Optional[bool] = False Json: Optional[bool] = False + + # Use validator to convert date to isoformat with suffix 'Z' + @validator("date") + def convert_date_to_isoformat(cls, v): + return v.isoformat() + "Z" diff --git a/hvpy/core.py b/hvpy/core.py index 33f0c4d..ccb6124 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -13,11 +13,9 @@ def parse_response(response: requests.Response, output_parameters: OutputType): return response.json() -def execute_api_call(url: str, input_parameters: HvpyParameters): +def execute_api_call(input_parameters: HvpyParameters): + url = input_parameters.url() response = requests.get(url, params=input_parameters.dict()) - # check if we have a valid response - if response.status_code != 200: - raise Exception(f"API call failed with status code {response.status_code}") - - return parse_response(response, input_parameters.get_output_type()) + if response.raise_for_status() == None: + return parse_response(response, input_parameters.get_output_type()) diff --git a/hvpy/io.py b/hvpy/io.py index 5df46ec..24baa8a 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -19,6 +19,9 @@ def get_output_type(self): # For now just return the String output return OutputType.String + def url(self): + return BASE_URL + self.__class__.__name__[:-15] + "/" + class OutputType(Enum): Raw = auto() diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index 778f333..3baee7e 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -2,18 +2,19 @@ from hvpy.api_groups.jpeg2000.get_jp2_image import getJP2ImageInputParameters from hvpy.core import execute_api_call -from hvpy.io import BASE_URL -URL = BASE_URL + "getJP2Image/" - -def test_get_jp2_image(): - - DATE = datetime(2022, 1, 1, 23, 59, 59) - - input = {"date": DATE, "sourceId": 14} +def test_get_jp2_image_str(): + date = datetime(2022, 1, 1, 23, 59, 59) + input = {"date": date, "sourceId": 14} input = getJP2ImageInputParameters(**input) + response = execute_api_call(input_parameters=input) + assert isinstance(response, str) - r = execute_api_call(url=URL, input_parameters=input) - assert isinstance(r, str) +def test_get_jp2_image_json(): + date = datetime(2022, 1, 1, 23, 59, 59) + input = {"date": date, "sourceId": 14} + input = getJP2ImageInputParameters(**input) + response = execute_api_call(input_parameters=input) + assert isinstance(response, dict) From 9d105f2537ff9f5475c7f3f06b1055136497176e Mon Sep 17 00:00:00 2001 From: akash5100 Date: Fri, 17 Jun 2022 12:27:10 +0530 Subject: [PATCH 21/51] Fix failing test --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 10 +++++++++- hvpy/io.py | 4 ++-- hvpy/tests/test_get_jp2_image.py | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 238a8ca..81cf726 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -3,7 +3,7 @@ from pydantic import validator -from hvpy.io import HvpyParameters +from hvpy.io import HvpyParameters, OutputType class getJP2ImageInputParameters(HvpyParameters): @@ -16,3 +16,11 @@ class getJP2ImageInputParameters(HvpyParameters): @validator("date") def convert_date_to_isoformat(cls, v): return v.isoformat() + "Z" + + def get_output_type(self): + if self.Json == False and self.jpip == False: + return OutputType.Raw + elif self.Json == True and self.jpip == True: + return OutputType.Json + elif self.Json == False and self.jpip == True: + return OutputType.String diff --git a/hvpy/io.py b/hvpy/io.py index 24baa8a..a8c3d25 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -16,8 +16,8 @@ def dict(self): return d def get_output_type(self): - # For now just return the String output - return OutputType.String + # Default output type is raw. + return OutputType.Raw def url(self): return BASE_URL + self.__class__.__name__[:-15] + "/" diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index 3baee7e..9a72903 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -6,7 +6,7 @@ def test_get_jp2_image_str(): date = datetime(2022, 1, 1, 23, 59, 59) - input = {"date": date, "sourceId": 14} + input = {"date": date, "sourceId": 14, "jpip": True, "Json": False} input = getJP2ImageInputParameters(**input) response = execute_api_call(input_parameters=input) assert isinstance(response, str) @@ -14,7 +14,7 @@ def test_get_jp2_image_str(): def test_get_jp2_image_json(): date = datetime(2022, 1, 1, 23, 59, 59) - input = {"date": date, "sourceId": 14} + input = {"date": date, "sourceId": 14, "jpip": True, "Json": True} input = getJP2ImageInputParameters(**input) response = execute_api_call(input_parameters=input) assert isinstance(response, dict) From 739609a32ecef712cc0a2e27dfda210418d423cb Mon Sep 17 00:00:00 2001 From: akash5100 Date: Fri, 17 Jun 2022 16:09:44 +0530 Subject: [PATCH 22/51] Test raw and default response --- hvpy/tests/test_get_jp2_image.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index 9a72903..030f8f3 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -4,7 +4,7 @@ from hvpy.core import execute_api_call -def test_get_jp2_image_str(): +def test_str_response(): date = datetime(2022, 1, 1, 23, 59, 59) input = {"date": date, "sourceId": 14, "jpip": True, "Json": False} input = getJP2ImageInputParameters(**input) @@ -12,9 +12,25 @@ def test_get_jp2_image_str(): assert isinstance(response, str) -def test_get_jp2_image_json(): +def test_json_response(): date = datetime(2022, 1, 1, 23, 59, 59) input = {"date": date, "sourceId": 14, "jpip": True, "Json": True} input = getJP2ImageInputParameters(**input) response = execute_api_call(input_parameters=input) assert isinstance(response, dict) + + +def test_raw_response(): + date = datetime(2022, 1, 1, 23, 59, 59) + input = {"date": date, "sourceId": 14, "jpip": False, "Json": False} + input = getJP2ImageInputParameters(**input) + response = execute_api_call(input_parameters=input) + assert isinstance(response, bytes) + + +def test_default_response(): + date = datetime(2022, 1, 1, 23, 59, 59) + input = {"date": date, "sourceId": 14} + input = getJP2ImageInputParameters(**input) + response = execute_api_call(input_parameters=input) + assert isinstance(response, bytes) From 1e385f8335bccac10272d52bc0864cf05b0bc43e Mon Sep 17 00:00:00 2001 From: akash5100 Date: Sat, 18 Jun 2022 12:12:19 +0530 Subject: [PATCH 23/51] Precommit fixed --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 6 +++--- hvpy/tests/test_get_jp2_image.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 81cf726..2d5f9fa 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -18,9 +18,9 @@ def convert_date_to_isoformat(cls, v): return v.isoformat() + "Z" def get_output_type(self): - if self.Json == False and self.jpip == False: - return OutputType.Raw - elif self.Json == True and self.jpip == True: + if self.Json == True and self.jpip == True: return OutputType.Json elif self.Json == False and self.jpip == True: return OutputType.String + else: + return OutputType.Raw diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index 030f8f3..a914210 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -28,6 +28,14 @@ def test_raw_response(): assert isinstance(response, bytes) +def test_raw_response_with_json(): + date = datetime(2022, 1, 1, 23, 59, 59) + input = {"date": date, "sourceId": 14, "jpip": False, "Json": True} + input = getJP2ImageInputParameters(**input) + response = execute_api_call(input_parameters=input) + assert isinstance(response, bytes) + + def test_default_response(): date = datetime(2022, 1, 1, 23, 59, 59) input = {"date": date, "sourceId": 14} From 0b23be19d258add0d25f62907c5826b0ca901a21 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Sat, 18 Jun 2022 12:14:17 +0530 Subject: [PATCH 24/51] Update hvpy/core.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/core.py b/hvpy/core.py index ccb6124..65f1b6c 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -8,7 +8,7 @@ def parse_response(response: requests.Response, output_parameters: OutputType): if output_parameters == OutputType.Raw: return response.content elif output_parameters == OutputType.String: - return str(response.content) + return response.content.decode('utf-8') elif output_parameters == OutputType.Json: return response.json() From e261c3b72a0d0a7f192629abf2c6f5fe2110e2d1 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Sat, 18 Jun 2022 12:14:37 +0530 Subject: [PATCH 25/51] Update hvpy/tests/test_get_jp2_image.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/tests/test_get_jp2_image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index 030f8f3..ba11b5f 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -10,6 +10,7 @@ def test_str_response(): input = getJP2ImageInputParameters(**input) response = execute_api_call(input_parameters=input) assert isinstance(response, str) + assert response.startswith('jpip://') def test_json_response(): From 7727fab35e90ee2060c011b6e2244b14b4caea6b Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Sat, 18 Jun 2022 12:15:02 +0530 Subject: [PATCH 26/51] Update hvpy/tests/test_get_jp2_image.py Co-authored-by: Daniel Garcia Briseno <94071409+dgarciabriseno@users.noreply.github.com> --- hvpy/tests/test_get_jp2_image.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index ba11b5f..948fcb6 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -19,6 +19,8 @@ def test_json_response(): input = getJP2ImageInputParameters(**input) response = execute_api_call(input_parameters=input) assert isinstance(response, dict) + assert 'uri' in response + assert response['uri'].startswith('jpip://') def test_raw_response(): From 2d2f1b106ad68ecf51ba1db3bc1c1afaf2c7d278 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Sat, 18 Jun 2022 12:15:54 +0530 Subject: [PATCH 27/51] Update hvpy/io.py Co-authored-by: Nabil Freij --- hvpy/io.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hvpy/io.py b/hvpy/io.py index a8c3d25..3217e13 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -19,6 +19,7 @@ def get_output_type(self): # Default output type is raw. return OutputType.Raw + @property def url(self): return BASE_URL + self.__class__.__name__[:-15] + "/" From 14903058fae198bfbf79f675c800896beaf901f3 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Sat, 18 Jun 2022 13:16:20 +0530 Subject: [PATCH 28/51] Update hvpy/core.py Co-authored-by: Nabil Freij --- hvpy/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hvpy/core.py b/hvpy/core.py index 65f1b6c..faaab2b 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -15,7 +15,6 @@ def parse_response(response: requests.Response, output_parameters: OutputType): def execute_api_call(input_parameters: HvpyParameters): - url = input_parameters.url() - response = requests.get(url, params=input_parameters.dict()) + response = requests.get(input_parameters.url, params=input_parameters.dict()) if response.raise_for_status() == None: return parse_response(response, input_parameters.get_output_type()) From 51bc5aa62a0ebd5178f02932f18ed09ee0b74e9f Mon Sep 17 00:00:00 2001 From: akash5100 Date: Sat, 18 Jun 2022 21:14:03 +0530 Subject: [PATCH 29/51] Add test and template docstring --- hvpy/core.py | 20 +++++++++++++++++--- hvpy/io.py | 1 - hvpy/tests/test_get_jp2_image.py | 6 +++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/hvpy/core.py b/hvpy/core.py index 65f1b6c..ea361d1 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -4,18 +4,32 @@ def parse_response(response: requests.Response, output_parameters: OutputType): + """ + _summary_ + + Returns + ------- + _type_ + _description_ + """ if output_parameters == OutputType.Raw: return response.content elif output_parameters == OutputType.String: - return response.content.decode('utf-8') + return response.content.decode("utf-8") elif output_parameters == OutputType.Json: return response.json() def execute_api_call(input_parameters: HvpyParameters): + """ + _summary_ - url = input_parameters.url() - response = requests.get(url, params=input_parameters.dict()) + Returns + ------- + _type_ + _description_ + """ + response = requests.get(input_parameters.url(), params=input_parameters.dict()) if response.raise_for_status() == None: return parse_response(response, input_parameters.get_output_type()) diff --git a/hvpy/io.py b/hvpy/io.py index 3217e13..a8c3d25 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -19,7 +19,6 @@ def get_output_type(self): # Default output type is raw. return OutputType.Raw - @property def url(self): return BASE_URL + self.__class__.__name__[:-15] + "/" diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/tests/test_get_jp2_image.py index dc4a863..1939fcb 100644 --- a/hvpy/tests/test_get_jp2_image.py +++ b/hvpy/tests/test_get_jp2_image.py @@ -10,7 +10,7 @@ def test_str_response(): input = getJP2ImageInputParameters(**input) response = execute_api_call(input_parameters=input) assert isinstance(response, str) - assert response.startswith('jpip://') + assert response.startswith("jpip://") def test_json_response(): @@ -19,8 +19,8 @@ def test_json_response(): input = getJP2ImageInputParameters(**input) response = execute_api_call(input_parameters=input) assert isinstance(response, dict) - assert 'uri' in response - assert response['uri'].startswith('jpip://') + assert "uri" in response + assert response["uri"].startswith("jpip://") def test_raw_response(): From 60a734930df4fd64ff527fbd8bea2067c9a1e2e1 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Sun, 19 Jun 2022 21:00:59 +0530 Subject: [PATCH 30/51] Update io.py and core.py --- hvpy/core.py | 21 ++++++--------------- hvpy/io.py | 1 + 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/hvpy/core.py b/hvpy/core.py index 1a95d46..ae85c78 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -5,12 +5,8 @@ def parse_response(response: requests.Response, output_parameters: OutputType): """ - _summary_ - - Returns - ------- - _type_ - _description_ + This function parses the response from the API call based on the output + type. """ if output_parameters == OutputType.Raw: @@ -23,14 +19,9 @@ def parse_response(response: requests.Response, output_parameters: OutputType): def execute_api_call(input_parameters: HvpyParameters): """ - _summary_ - - Returns - ------- - _type_ - _description_ + This function executes the API call and returns a parsed response. """ - response = requests.get(input_parameters.url(), params=input_parameters.dict()) - if response.raise_for_status() == None: - return parse_response(response, input_parameters.get_output_type()) + response = requests.get(input_parameters.url, params=input_parameters.dict()) + response.raise_for_status() + return parse_response(response, input_parameters.get_output_type()) diff --git a/hvpy/io.py b/hvpy/io.py index a8c3d25..3217e13 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -19,6 +19,7 @@ def get_output_type(self): # Default output type is raw. return OutputType.Raw + @property def url(self): return BASE_URL + self.__class__.__name__[:-15] + "/" From 009d5da0e57e2c2a2e51397706a653b3c6edd0e0 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Mon, 20 Jun 2022 13:30:35 +0530 Subject: [PATCH 31/51] Update docstring --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 1 - hvpy/core.py | 26 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 2d5f9fa..bd232c6 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -12,7 +12,6 @@ class getJP2ImageInputParameters(HvpyParameters): jpip: Optional[bool] = False Json: Optional[bool] = False - # Use validator to convert date to isoformat with suffix 'Z' @validator("date") def convert_date_to_isoformat(cls, v): return v.isoformat() + "Z" diff --git a/hvpy/core.py b/hvpy/core.py index ae85c78..9f11897 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -5,8 +5,19 @@ def parse_response(response: requests.Response, output_parameters: OutputType): """ - This function parses the response from the API call based on the output - type. + Parses the response from the API call based on the output type. + + Parameters + ---------- + response : requests.Response + The response from the API call. + output_parameters : OutputType + The output type. + + Returns + ------- + parsed_response : binary, str or json + The parsed response. """ if output_parameters == OutputType.Raw: @@ -19,7 +30,16 @@ def parse_response(response: requests.Response, output_parameters: OutputType): def execute_api_call(input_parameters: HvpyParameters): """ - This function executes the API call and returns a parsed response. + Executes the API call and returns a parsed response. + + Parameters + ---------- + input_parameters : HvpyParameters + The input parameters. + + Returns + ------- + parsed response returned by parse_response """ response = requests.get(input_parameters.url, params=input_parameters.dict()) From 15009d44ead24c26b9be675c553d1e7ad56f6868 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 21 Jun 2022 23:02:49 +0530 Subject: [PATCH 32/51] Update docstring --- hvpy/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hvpy/core.py b/hvpy/core.py index 9f11897..6e9a840 100644 --- a/hvpy/core.py +++ b/hvpy/core.py @@ -16,7 +16,7 @@ def parse_response(response: requests.Response, output_parameters: OutputType): Returns ------- - parsed_response : binary, str or json + binary | str | json The parsed response. """ @@ -39,7 +39,7 @@ def execute_api_call(input_parameters: HvpyParameters): Returns ------- - parsed response returned by parse_response + Parsed response from the API. """ response = requests.get(input_parameters.url, params=input_parameters.dict()) From dd239c0d50bb029e05fbab322f969db77a3990d5 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Wed, 22 Jun 2022 11:35:35 +0530 Subject: [PATCH 33/51] Update docstring --- hvpy/io.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hvpy/io.py b/hvpy/io.py index 3217e13..9362e4a 100644 --- a/hvpy/io.py +++ b/hvpy/io.py @@ -7,16 +7,17 @@ class HvpyParameters(BaseModel): def dict(self): + """ + Pydantic doesn't allow using lowercase 'json' as a field, so we + override it. + """ d = super().dict() - # Pydantic doesn't allow using lower case 'json' as a field, - # so override it here. if "Json" in d: d["json"] = d["Json"] del d["Json"] return d def get_output_type(self): - # Default output type is raw. return OutputType.Raw @property From 21a7e0b84438010f4c1dd5af6ed87b3a4b37bf9a Mon Sep 17 00:00:00 2001 From: akash5100 Date: Wed, 22 Jun 2022 11:35:47 +0530 Subject: [PATCH 34/51] Update docstring --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index bd232c6..67efc25 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -7,6 +7,34 @@ class getJP2ImageInputParameters(HvpyParameters): + """ + A class for the input parameters of the getJP2Image API call. + ref: https://api.helioviewer.org/docs/v2/api/api_groups/jpeg2000.html#getjp2image + + + ... + + Attributes + ---------- + date : datetime + Desired date/time of the JP2 image. + sourceId : int + Unique image datasource identifier. + jpip : bool + Optionally return a JPIP URI instead of the binary data of the image itself. + Json : bool + Optionally return a JSON object. + + + Methods + ------- + convert_date_to_isoformat + Converts the date from a datetime object to a string in the ISO format. + + get_output_type + Returns the output type of the API call. + """ + date: datetime sourceId: int jpip: Optional[bool] = False From d5f2c9bae23e1927518973cf53bc541d70ae97b6 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 22 Jun 2022 12:17:46 +0530 Subject: [PATCH 35/51] Update hvpy/api_groups/jpeg2000/get_jp2_image.py Co-authored-by: Nabil Freij --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 67efc25..3b7df82 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -8,11 +8,7 @@ class getJP2ImageInputParameters(HvpyParameters): """ - A class for the input parameters of the getJP2Image API call. - ref: https://api.helioviewer.org/docs/v2/api/api_groups/jpeg2000.html#getjp2image - - - ... + Handles the input parameters of the `getJP2Image API `__. Attributes ---------- From b6146db2492420a4d3a3ad9f225bbeaa31b287f1 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 22 Jun 2022 12:18:02 +0530 Subject: [PATCH 36/51] Update hvpy/api_groups/jpeg2000/get_jp2_image.py Co-authored-by: Nabil Freij --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 3b7df82..60728c9 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -16,7 +16,7 @@ class getJP2ImageInputParameters(HvpyParameters): Desired date/time of the JP2 image. sourceId : int Unique image datasource identifier. - jpip : bool + jpip : bool, optional Optionally return a JPIP URI instead of the binary data of the image itself. Json : bool Optionally return a JSON object. From 742ced17b9696b6c0707bc914bc8776b561c3c58 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 22 Jun 2022 12:18:17 +0530 Subject: [PATCH 37/51] Update hvpy/api_groups/jpeg2000/get_jp2_image.py Co-authored-by: Nabil Freij --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 60728c9..113fa31 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -19,7 +19,7 @@ class getJP2ImageInputParameters(HvpyParameters): jpip : bool, optional Optionally return a JPIP URI instead of the binary data of the image itself. Json : bool - Optionally return a JSON object. + Returns the JSON if set to `True`, defaults to `False`. Methods From 765b043c0a8252076434494cba1661619e287a8c Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 22 Jun 2022 12:18:29 +0530 Subject: [PATCH 38/51] Update hvpy/api_groups/jpeg2000/get_jp2_image.py Co-authored-by: Nabil Freij --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 113fa31..c2c8db5 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -18,7 +18,7 @@ class getJP2ImageInputParameters(HvpyParameters): Unique image datasource identifier. jpip : bool, optional Optionally return a JPIP URI instead of the binary data of the image itself. - Json : bool + Json : bool, optional Returns the JSON if set to `True`, defaults to `False`. From ea006534eeb593eafb3e69145d4cacb9f67bdd4e Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 22 Jun 2022 12:18:38 +0530 Subject: [PATCH 39/51] Update hvpy/api_groups/jpeg2000/get_jp2_image.py Co-authored-by: Nabil Freij --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index c2c8db5..91b6921 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -17,7 +17,7 @@ class getJP2ImageInputParameters(HvpyParameters): sourceId : int Unique image datasource identifier. jpip : bool, optional - Optionally return a JPIP URI instead of the binary data of the image itself. + Returns a JPIP URI instead of the binary data of the image if set to `True`, defaults to `False`. Json : bool, optional Returns the JSON if set to `True`, defaults to `False`. From 46dd707ed16919a9772b57eeda643f184f8d4f9c Mon Sep 17 00:00:00 2001 From: akash5100 Date: Wed, 22 Jun 2022 12:27:02 +0530 Subject: [PATCH 40/51] Fix codestyle --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 91b6921..7ef6dce 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -8,7 +8,9 @@ class getJP2ImageInputParameters(HvpyParameters): """ - Handles the input parameters of the `getJP2Image API `__. + Handles the input parameters of the `getJP2Image API. + + `__. Attributes ---------- From 9f348d8d9140c0a9d36dcfb204795a4426fd790c Mon Sep 17 00:00:00 2001 From: akash5100 Date: Thu, 23 Jun 2022 14:10:15 +0530 Subject: [PATCH 41/51] tests refactor --- hvpy/{ => api_groups/jpeg2000}/tests/__init__.py | 0 hvpy/{ => api_groups/jpeg2000}/tests/test_get_jp2_image.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename hvpy/{ => api_groups/jpeg2000}/tests/__init__.py (100%) rename hvpy/{ => api_groups/jpeg2000}/tests/test_get_jp2_image.py (100%) diff --git a/hvpy/tests/__init__.py b/hvpy/api_groups/jpeg2000/tests/__init__.py similarity index 100% rename from hvpy/tests/__init__.py rename to hvpy/api_groups/jpeg2000/tests/__init__.py diff --git a/hvpy/tests/test_get_jp2_image.py b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py similarity index 100% rename from hvpy/tests/test_get_jp2_image.py rename to hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py From 40544f612bd471ff52312d217ac9db66d304304a Mon Sep 17 00:00:00 2001 From: akash5100 Date: Thu, 23 Jun 2022 20:49:11 +0530 Subject: [PATCH 42/51] update docstring --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 7ef6dce..5645dcd 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -22,15 +22,6 @@ class getJP2ImageInputParameters(HvpyParameters): Returns a JPIP URI instead of the binary data of the image if set to `True`, defaults to `False`. Json : bool, optional Returns the JSON if set to `True`, defaults to `False`. - - - Methods - ------- - convert_date_to_isoformat - Converts the date from a datetime object to a string in the ISO format. - - get_output_type - Returns the output type of the API call. """ date: datetime @@ -40,9 +31,15 @@ class getJP2ImageInputParameters(HvpyParameters): @validator("date") def convert_date_to_isoformat(cls, v): + """ + Converts the date from a datetime object to a string in the ISO format. + """ return v.isoformat() + "Z" def get_output_type(self): + """ + Returns the output type of the API call. + """ if self.Json == True and self.jpip == True: return OutputType.Json elif self.Json == False and self.jpip == True: From 9d546972bfc73a8098bab8249e0c632181f9ef87 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Fri, 24 Jun 2022 11:37:08 +0530 Subject: [PATCH 43/51] Update get_jp2_image.py --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 5645dcd..14f2693 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -40,9 +40,9 @@ def get_output_type(self): """ Returns the output type of the API call. """ - if self.Json == True and self.jpip == True: + if self.Json and self.jpip: return OutputType.Json - elif self.Json == False and self.jpip == True: + elif not self.Json and self.jpip: return OutputType.String else: return OutputType.Raw From 20847845b46daeb1dca3fff6d053e5c86493d732 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Sat, 25 Jun 2022 14:58:28 +0530 Subject: [PATCH 44/51] Remove Optional from getJP2Image endpoint --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 5 ++-- .../jpeg2000/tests/test_get_jp2_image.py | 30 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 14f2693..106c0de 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -1,4 +1,3 @@ -from typing import Optional from datetime import datetime from pydantic import validator @@ -26,8 +25,8 @@ class getJP2ImageInputParameters(HvpyParameters): date: datetime sourceId: int - jpip: Optional[bool] = False - Json: Optional[bool] = False + jpip: bool = False + Json: bool = False @validator("date") def convert_date_to_isoformat(cls, v): diff --git a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py index 1939fcb..0d40021 100644 --- a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py @@ -6,18 +6,18 @@ def test_str_response(): date = datetime(2022, 1, 1, 23, 59, 59) - input = {"date": date, "sourceId": 14, "jpip": True, "Json": False} - input = getJP2ImageInputParameters(**input) - response = execute_api_call(input_parameters=input) + params = {"date": date, "sourceId": 14, "jpip": True, "Json": False} + params = getJP2ImageInputParameters(**params) + response = execute_api_call(input_parameters=params) assert isinstance(response, str) assert response.startswith("jpip://") def test_json_response(): date = datetime(2022, 1, 1, 23, 59, 59) - input = {"date": date, "sourceId": 14, "jpip": True, "Json": True} - input = getJP2ImageInputParameters(**input) - response = execute_api_call(input_parameters=input) + params = {"date": date, "sourceId": 14, "jpip": True, "Json": True} + params = getJP2ImageInputParameters(**params) + response = execute_api_call(input_parameters=params) assert isinstance(response, dict) assert "uri" in response assert response["uri"].startswith("jpip://") @@ -25,23 +25,23 @@ def test_json_response(): def test_raw_response(): date = datetime(2022, 1, 1, 23, 59, 59) - input = {"date": date, "sourceId": 14, "jpip": False, "Json": False} - input = getJP2ImageInputParameters(**input) - response = execute_api_call(input_parameters=input) + params = {"date": date, "sourceId": 14, "jpip": False, "Json": False} + params = getJP2ImageInputParameters(**params) + response = execute_api_call(input_parameters=params) assert isinstance(response, bytes) def test_raw_response_with_json(): date = datetime(2022, 1, 1, 23, 59, 59) - input = {"date": date, "sourceId": 14, "jpip": False, "Json": True} - input = getJP2ImageInputParameters(**input) - response = execute_api_call(input_parameters=input) + params = {"date": date, "sourceId": 14, "jpip": False, "Json": True} + params = getJP2ImageInputParameters(**params) + response = execute_api_call(input_parameters=params) assert isinstance(response, bytes) def test_default_response(): date = datetime(2022, 1, 1, 23, 59, 59) - input = {"date": date, "sourceId": 14} - input = getJP2ImageInputParameters(**input) - response = execute_api_call(input_parameters=input) + params = {"date": date, "sourceId": 14} + params = getJP2ImageInputParameters(**params) + response = execute_api_call(input_parameters=params) assert isinstance(response, bytes) From 95cba5a26f40c689fcb4447bcb9509c9b84bf101 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Sat, 25 Jun 2022 15:26:04 +0530 Subject: [PATCH 45/51] Test for value error --- .../jpeg2000/tests/test_get_jp2_image.py | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py index 0d40021..cf9fb56 100644 --- a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py @@ -1,12 +1,15 @@ from datetime import datetime +import pytest + from hvpy.api_groups.jpeg2000.get_jp2_image import getJP2ImageInputParameters from hvpy.core import execute_api_call +# Test Response def test_str_response(): - date = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date, "sourceId": 14, "jpip": True, "Json": False} + date_obj = datetime(2022, 1, 1, 23, 59, 59) + params = {"date": date_obj, "sourceId": 14, "jpip": True, "Json": False} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, str) @@ -14,8 +17,8 @@ def test_str_response(): def test_json_response(): - date = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date, "sourceId": 14, "jpip": True, "Json": True} + date_obj = datetime(2022, 1, 1, 23, 59, 59) + params = {"date": date_obj, "sourceId": 14, "jpip": True, "Json": True} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, dict) @@ -24,24 +27,36 @@ def test_json_response(): def test_raw_response(): - date = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date, "sourceId": 14, "jpip": False, "Json": False} + date_obj = datetime(2022, 1, 1, 23, 59, 59) + params = {"date": date_obj, "sourceId": 14, "jpip": False, "Json": False} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, bytes) def test_raw_response_with_json(): - date = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date, "sourceId": 14, "jpip": False, "Json": True} + date_obj = datetime(2022, 1, 1, 23, 59, 59) + params = {"date": date_obj, "sourceId": 14, "jpip": False, "Json": True} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, bytes) def test_default_response(): - date = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date, "sourceId": 14} + date_obj = datetime(2022, 1, 1, 23, 59, 59) + params = {"date": date_obj, "sourceId": 14} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, bytes) + + +# Test error +def test_error_handling(): + params = {"sourceId": 14, "jpip": True, "Json": True} + with pytest.raises(ValueError): + params = getJP2ImageInputParameters(**params) + + date_obj = datetime(2022, 1, 1, 23, 59, 59) + params = {"date": date_obj, "jpip": True, "Json": False} + with pytest.raises(ValueError): + params = getJP2ImageInputParameters(**params) From 7c6c5b95dd7fa33f6bc09dde7fa0bd81ea72a99f Mon Sep 17 00:00:00 2001 From: akash5100 Date: Mon, 27 Jun 2022 12:26:51 +0530 Subject: [PATCH 46/51] Fix alias for Json --- hvpy/api_groups/jpeg2000/get_jp2_image.py | 6 ++--- .../jpeg2000/tests/test_get_jp2_image.py | 26 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/get_jp2_image.py b/hvpy/api_groups/jpeg2000/get_jp2_image.py index 106c0de..23fe191 100644 --- a/hvpy/api_groups/jpeg2000/get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/get_jp2_image.py @@ -1,6 +1,6 @@ from datetime import datetime -from pydantic import validator +from pydantic import Field, validator from hvpy.io import HvpyParameters, OutputType @@ -19,14 +19,14 @@ class getJP2ImageInputParameters(HvpyParameters): Unique image datasource identifier. jpip : bool, optional Returns a JPIP URI instead of the binary data of the image if set to `True`, defaults to `False`. - Json : bool, optional + json : bool, optional Returns the JSON if set to `True`, defaults to `False`. """ date: datetime sourceId: int jpip: bool = False - Json: bool = False + Json: bool = Field(False, alias="json") @validator("date") def convert_date_to_isoformat(cls, v): diff --git a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py index cf9fb56..d7e491b 100644 --- a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py @@ -1,15 +1,15 @@ from datetime import datetime import pytest +from pydantic import ValidationError from hvpy.api_groups.jpeg2000.get_jp2_image import getJP2ImageInputParameters from hvpy.core import execute_api_call -# Test Response def test_str_response(): date_obj = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date_obj, "sourceId": 14, "jpip": True, "Json": False} + params = {"date": date_obj, "sourceId": 14, "jpip": True, "json": False} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, str) @@ -18,7 +18,7 @@ def test_str_response(): def test_json_response(): date_obj = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date_obj, "sourceId": 14, "jpip": True, "Json": True} + params = {"date": date_obj, "sourceId": 14, "jpip": True, "json": True} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, dict) @@ -28,7 +28,7 @@ def test_json_response(): def test_raw_response(): date_obj = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date_obj, "sourceId": 14, "jpip": False, "Json": False} + params = {"date": date_obj, "sourceId": 14, "jpip": False, "json": False} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, bytes) @@ -36,7 +36,7 @@ def test_raw_response(): def test_raw_response_with_json(): date_obj = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date_obj, "sourceId": 14, "jpip": False, "Json": True} + params = {"date": date_obj, "sourceId": 14, "jpip": False, "json": True} params = getJP2ImageInputParameters(**params) response = execute_api_call(input_parameters=params) assert isinstance(response, bytes) @@ -50,13 +50,17 @@ def test_default_response(): assert isinstance(response, bytes) -# Test error def test_error_handling(): - params = {"sourceId": 14, "jpip": True, "Json": True} - with pytest.raises(ValueError): + params = {"sourceId": 14, "jpip": True, "json": True} + with pytest.raises(ValidationError): params = getJP2ImageInputParameters(**params) + +def test_unknown_parameters(): date_obj = datetime(2022, 1, 1, 23, 59, 59) - params = {"date": date_obj, "jpip": True, "Json": False} - with pytest.raises(ValueError): - params = getJP2ImageInputParameters(**params) + params = {"date": date_obj, "sourceId": 14, "jpip": True, "json": True, "should_reject_this": True} + params = getJP2ImageInputParameters(**params) + response = execute_api_call(input_parameters=params) + assert isinstance(response, dict) + assert "uri" in response + assert response["uri"].startswith("jpip://") From 6582a1b2545b35a7e2397d41a6348b271df8354b Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 28 Jun 2022 10:25:27 +0530 Subject: [PATCH 47/51] Check for error message --- hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py index d7e491b..4a336fb 100644 --- a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py @@ -51,8 +51,10 @@ def test_default_response(): def test_error_handling(): + error_message = "getJP2ImageInputParameters\ndate\n field required" + params = {"sourceId": 14, "jpip": True, "json": True} - with pytest.raises(ValidationError): + with pytest.raises(ValidationError, match=error_message): params = getJP2ImageInputParameters(**params) From 3b7631037ff9189de006e10f1a002798474fcfaa Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 28 Jun 2022 10:56:03 +0530 Subject: [PATCH 48/51] Test for IO module --- hvpy/tests/__init__.py | 0 hvpy/tests/test_io.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 hvpy/tests/__init__.py create mode 100644 hvpy/tests/test_io.py diff --git a/hvpy/tests/__init__.py b/hvpy/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hvpy/tests/test_io.py b/hvpy/tests/test_io.py new file mode 100644 index 0000000..5da7abb --- /dev/null +++ b/hvpy/tests/test_io.py @@ -0,0 +1,46 @@ +import pytest + +from hvpy.io import HvpyParameters, OutputType + + +def test_default_get_output_type(): + params = HvpyParameters() + assert params.get_output_type() == OutputType.Raw + + +def test_get_output_type(): + class TestInputParameters(HvpyParameters): + a: int + + def get_output_type(self): + if self.a == 1: + return OutputType.Raw + else: + return OutputType.String + + params = {"a": 1} + params = TestInputParameters(**params) + assert params.get_output_type() == OutputType.Raw + + params = {"a": 2} + params = TestInputParameters(**params) + assert params.get_output_type() == OutputType.String + + assert params.url == "https://api.helioviewer.org/v2/Test/" + + +def test_error_handling(): + error_message = "TestInputParameters\na\n field required" + + class TestInputParameters(HvpyParameters): + a: int + + def get_output_type(self): + if self.a == 1: + return OutputType.Raw + else: + return OutputType.String + + params = {"b": 1} + with pytest.raises(ValueError, match=error_message): + params = TestInputParameters(**params) From 206f544eddc0edce5f1714b72b177074ba58ebfb Mon Sep 17 00:00:00 2001 From: akash5100 Date: Wed, 29 Jun 2022 20:33:28 +0530 Subject: [PATCH 49/51] Update test and import endpoint to io.py --- .../jpeg2000/tests/test_get_jp2_image.py | 7 +++ hvpy/tests/test_io.py | 45 +++---------------- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py index 4a336fb..7eb2396 100644 --- a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py @@ -66,3 +66,10 @@ def test_unknown_parameters(): assert isinstance(response, dict) assert "uri" in response assert response["uri"].startswith("jpip://") + + +def test_url_property(): + date_obj = datetime(2022, 1, 1, 23, 59, 59) + params = {"date": date_obj, "sourceId": 14, "jpip": True, "json": True} + params = getJP2ImageInputParameters(**params) + assert params.url == "https://api.helioviewer.org/v2/getJP2Image/" diff --git a/hvpy/tests/test_io.py b/hvpy/tests/test_io.py index 5da7abb..6eaab08 100644 --- a/hvpy/tests/test_io.py +++ b/hvpy/tests/test_io.py @@ -1,46 +1,15 @@ -import pytest - from hvpy.io import HvpyParameters, OutputType -def test_default_get_output_type(): +def test_default_get_output_type_is_raw(): params = HvpyParameters() assert params.get_output_type() == OutputType.Raw -def test_get_output_type(): - class TestInputParameters(HvpyParameters): - a: int - - def get_output_type(self): - if self.a == 1: - return OutputType.Raw - else: - return OutputType.String - - params = {"a": 1} - params = TestInputParameters(**params) - assert params.get_output_type() == OutputType.Raw - - params = {"a": 2} - params = TestInputParameters(**params) - assert params.get_output_type() == OutputType.String - - assert params.url == "https://api.helioviewer.org/v2/Test/" - - -def test_error_handling(): - error_message = "TestInputParameters\na\n field required" - - class TestInputParameters(HvpyParameters): - a: int - - def get_output_type(self): - if self.a == 1: - return OutputType.Raw - else: - return OutputType.String +def test_url_property(): + class MockInputParameters(HvpyParameters): + jpip: bool - params = {"b": 1} - with pytest.raises(ValueError, match=error_message): - params = TestInputParameters(**params) + params = {"jpip": True} + params = MockInputParameters(**params) + assert params.url == "https://api.helioviewer.org/v2/Mock/" From 81d592d15cf5020c0ebc5af435fc53b577f2fae0 Mon Sep 17 00:00:00 2001 From: Akash Verma Date: Wed, 29 Jun 2022 20:52:26 +0530 Subject: [PATCH 50/51] Update hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py Co-authored-by: Nabil Freij --- hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py index 7eb2396..602c63e 100644 --- a/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py +++ b/hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py @@ -51,11 +51,9 @@ def test_default_response(): def test_error_handling(): - error_message = "getJP2ImageInputParameters\ndate\n field required" - params = {"sourceId": 14, "jpip": True, "json": True} - with pytest.raises(ValidationError, match=error_message): - params = getJP2ImageInputParameters(**params) + with pytest.raises(ValidationError, match="getJP2ImageInputParameters\ndate\n field required"): + getJP2ImageInputParameters(**params) def test_unknown_parameters(): From a4b274bb75f1c993553de6ca32da812da1ebf809 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Wed, 29 Jun 2022 21:17:56 +0530 Subject: [PATCH 51/51] Update test --- hvpy/tests/test_io.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hvpy/tests/test_io.py b/hvpy/tests/test_io.py index 6eaab08..2c295e6 100644 --- a/hvpy/tests/test_io.py +++ b/hvpy/tests/test_io.py @@ -7,9 +7,5 @@ def test_default_get_output_type_is_raw(): def test_url_property(): - class MockInputParameters(HvpyParameters): - jpip: bool - - params = {"jpip": True} - params = MockInputParameters(**params) - assert params.url == "https://api.helioviewer.org/v2/Mock/" + params = HvpyParameters() + assert params.url == "https://api.helioviewer.org/v2//"