From 53ae862898490114b53d14de484a7c658f723d62 Mon Sep 17 00:00:00 2001 From: Darren Chaddock Date: Wed, 5 Feb 2025 14:49:31 -0700 Subject: [PATCH] revamped tests for data product searches --- COVERAGE.md | 12 +- RELEASE_NOTES.md | 1 + pyaurorax/search/data_products/__init__.py | 56 ++- .../search/data_products/_data_products.py | 14 +- .../data_products/classes/data_product.py | 2 - .../search/data_products/classes/search.py | 22 +- pyaurorax/search/ephemeris/__init__.py | 59 +++ .../cli/search/conjunctions/test_get_data.py | 39 +- .../cli/search/conjunctions/test_get_logs.py | 20 +- .../cli/search/conjunctions/test_get_query.py | 4 +- .../search/conjunctions/test_get_status.py | 28 +- .../conjunctions/test_search_resubmit.py | 4 +- .../cli/search/data_products/test_get_data.py | 40 +- .../cli/search/data_products/test_get_logs.py | 19 +- .../search/data_products/test_get_query.py | 4 +- .../search/data_products/test_get_status.py | 34 +- .../data_products/test_search_resubmit.py | 7 +- .../cli/search/ephemeris/test_get_data.py | 38 +- .../cli/search/ephemeris/test_get_logs.py | 19 +- .../cli/search/ephemeris/test_get_query.py | 4 +- .../cli/search/ephemeris/test_get_status.py | 34 +- .../search/ephemeris/test_search_resubmit.py | 4 +- tests/test_suite/conftest.py | 88 ++++- .../search/conjunctions/test_search_object.py | 1 - .../search/data_products/test_data_object.py | 49 +++ .../data_products/test_data_products.py | 361 ------------------ .../search/data_products/test_describe.py | 50 +++ .../data_products/test_get_request_url.py | 23 ++ .../search/data_products/test_search.py | 242 ++++++++++++ .../data_products/test_search_legacy.py | 63 +++ .../data_products/test_search_object.py | 138 +++++++ .../data_products/test_upload_delete.py | 121 ++++++ .../search/ephemeris/test_data_object.py | 2 +- .../search/ephemeris/test_search_object.py | 8 +- tests/test_suite/search/test_location.py | 34 +- 35 files changed, 1124 insertions(+), 520 deletions(-) create mode 100644 tests/test_suite/search/data_products/test_data_object.py delete mode 100644 tests/test_suite/search/data_products/test_data_products.py create mode 100644 tests/test_suite/search/data_products/test_describe.py create mode 100644 tests/test_suite/search/data_products/test_get_request_url.py create mode 100644 tests/test_suite/search/data_products/test_search.py create mode 100644 tests/test_suite/search/data_products/test_search_legacy.py create mode 100644 tests/test_suite/search/data_products/test_search_object.py create mode 100644 tests/test_suite/search/data_products/test_upload_delete.py diff --git a/COVERAGE.md b/COVERAGE.md index 47c638ab..d888257e 100644 --- a/COVERAGE.md +++ b/COVERAGE.md @@ -36,15 +36,15 @@ pyaurorax/search/conjunctions/classes/criteria_block.py 67 0 10 pyaurorax/search/conjunctions/classes/search.py 215 1 99% 366 pyaurorax/search/conjunctions/swarmaurora/__init__.py 15 0 100% pyaurorax/search/conjunctions/swarmaurora/_swarmaurora.py 24 0 100% -pyaurorax/search/data_products/__init__.py 33 2 94% 124, 234 -pyaurorax/search/data_products/_data_products.py 100 27 73% 40-44, 86, 92, 96, 101, 128, 143-145, 154, 169, 177-204, 211-214 +pyaurorax/search/data_products/__init__.py 33 0 100% +pyaurorax/search/data_products/_data_products.py 84 2 98% 128, 145 pyaurorax/search/data_products/classes/data_product.py 47 1 98% 130 -pyaurorax/search/data_products/classes/search.py 128 46 64% 33, 142, 145, 156-197, 209, 235, 272, 291-292, 300-301, 371-376 -pyaurorax/search/ephemeris/__init__.py 28 0 100% +pyaurorax/search/data_products/classes/search.py 121 0 100% +pyaurorax/search/ephemeris/__init__.py 29 0 100% pyaurorax/search/ephemeris/_ephemeris.py 78 2 97% 142, 151 pyaurorax/search/ephemeris/classes/ephemeris.py 42 1 98% 97 pyaurorax/search/ephemeris/classes/search.py 118 0 100% -pyaurorax/search/location.py 29 6 79% 52-55, 63-66 +pyaurorax/search/location.py 29 0 100% pyaurorax/search/metadata/__init__.py 14 0 100% pyaurorax/search/metadata/_metadata.py 20 5 75% 29-31, 45, 54 pyaurorax/search/metadata_filters.py 61 25 59% 63-66, 69, 73-78, 86-89, 135-137, 145, 147, 159-169 @@ -94,7 +94,7 @@ pyaurorax/tools/mosaic/_prep_skymaps.py 119 112 pyaurorax/tools/spectra/__init__.py 10 1 90% 129 pyaurorax/tools/spectra/_plot.py 114 108 5% 42-233 -------------------------------------------------------------------------------------------- -TOTAL 6045 2516 58% +TOTAL 6023 2437 60% 13 empty files skipped. ``` diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 5b51f184..ee425572 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -7,6 +7,7 @@ Version 1.13.0 - improve handling of conjunction/ephemeris/data product searches that return no results when retrieving data - improve handling of conjunction/ephemeris/data product searches which receive incorrect criteria blocks - issue when ordering by 'owner' for `aurorax.search.sources.list()` and `aurorax.search.sources.search()` functions + - incorrect typing for `aurorax.search.data_products.search()` function's `data_product_type` parameter (corrected to be list of literals, instead of single literal) - removed `aurorax-cli search sources get_stats` command (`aurorax-cli search sources get --include-stats` flag covers this functionality) - removed `aurorax-cli search util ground_to_nbtrace` and `aurorax-cli search util ground_to_sbtrace` commands (use library functions instead) - removed setter class for `api_headers` and `srs_obj` in `PyAurorax()` objects diff --git a/pyaurorax/search/data_products/__init__.py b/pyaurorax/search/data_products/__init__.py index 7e4f0563..8ba09aee 100644 --- a/pyaurorax/search/data_products/__init__.py +++ b/pyaurorax/search/data_products/__init__.py @@ -25,7 +25,6 @@ from .classes.search import DataProductSearch from ..sources.classes.data_source import DataSource from ..metadata_filters import MetadataFilter -from ..._util import show_warning from ._data_products import search as func_search from ._data_products import upload as func_upload from ._data_products import delete as func_delete @@ -54,7 +53,7 @@ def search(self, programs: Optional[List[str]] = None, platforms: Optional[List[str]] = None, instrument_types: Optional[List[str]] = None, - data_product_types: Optional[Literal["keogram", "montage", "movie", "summary_plot", "data_availability"]] = None, + data_product_types: Optional[List[Literal["keogram", "montage", "movie", "summary_plot", "data_availability"]]] = None, metadata_filters: Optional[Union[MetadataFilter, List[Dict]]] = None, metadata_filters_logical_operator: Optional[Literal["and", "or", "AND", "OR"]] = None, response_format: Optional[Dict] = None, @@ -118,13 +117,6 @@ def search(self, Returns: A `pyaurorax.search.DataProductSearch` object """ - # show warnings - if (isinstance(metadata_filters, MetadataFilter) and metadata_filters_logical_operator is not None): - # logical operator supplied, but MetadataFilter supplied too - show_warning("Supplying a MetadataFilter object in addition to the metadata_filters_logical_operator " + - "parameter is redundant. Only the MetadataFilter object is needed. The " + - "metadata_filters_logical_operator parameter will be ignored") - # return return func_search( self.__aurorax_obj, @@ -266,3 +258,49 @@ def get_request_url(self, request_id: str) -> str: The request URL """ return func_get_request_url(self.__aurorax_obj, request_id) + + def create_response_format_template(self, default: bool = False) -> Dict: + """ + Generate a template dictionary that can be used as the response_format parameter + in a data products search. + + Args: + default (bool): + The default value to set for every parameter that can be returned, defaults + to False. + + Returns: + A template dictionary for the response format + """ + return { + "start": default, + "end": default, + "data_source": { + "identifier": default, + "program": default, + "platform": default, + "instrument_type": default, + "source_type": default, + "display_name": default, + "ephemeris_metadata_schema": { + "field_name": default, + "description": default, + "data_type": default, + "allowed_values": default, + "additional_description": default + }, + "data_product_metadata_schema": { + "field_name": default, + "description": default, + "data_type": default, + "allowed_values": default, + "additional_description": default + }, + "owner": default, + "maintainers": default, + "metadata": default + }, + "url": default, + "data_product_type": default, + "metadata": default + } diff --git a/pyaurorax/search/data_products/_data_products.py b/pyaurorax/search/data_products/_data_products.py index df1ac24f..8e22b3d5 100644 --- a/pyaurorax/search/data_products/_data_products.py +++ b/pyaurorax/search/data_products/_data_products.py @@ -37,7 +37,7 @@ def __validate_data_source(aurorax_obj, identifier, records): # get data source try: ds = get_using_identifier(aurorax_obj, identifier, FORMAT_DEFAULT, False) - except AuroraXAPIError as e: + except AuroraXAPIError as e: # pragma: nocover if ("no data source record found" in str(e).lower()): raise AuroraXAPIError("Data source with identifier %d could not be found" % (identifier)) from e else: @@ -87,7 +87,7 @@ def search(aurorax_obj, start, end, programs, platforms, instrument_types, data_ s.wait(poll_interval=poll_interval, verbose=verbose) # check if error condition encountered - if (s.status["search_result"]["error_condition"] is True): + if (s.status["search_result"]["error_condition"] is True): # pragma: nocover # error encountered raise AuroraXSearchError(s.logs[-1]["summary"]) @@ -140,7 +140,7 @@ def upload(aurorax_obj, identifier, all_records, validate_source, chunk_size): # evaluate response if (res.status_code == 400): - if isinstance(res.data, list): + if isinstance(res.data, list): # pragma: nocover raise AuroraXUploadError("%s - %s" % (res.status_code, res.data[0]["message"])) raise AuroraXUploadError("%s - %s" % (res.data["error_code"], res.data["error_message"])) @@ -150,7 +150,7 @@ def upload(aurorax_obj, identifier, all_records, validate_source, chunk_size): def delete_urls(aurorax_obj, data_source, urls): # check to make sure the identifier, program, platform, and instrument type are all set in the data source - if not all([data_source.identifier, data_source.program, data_source.platform, data_source.instrument_type]): + if not all([data_source.identifier, data_source.program, data_source.platform, data_source.instrument_type]): # pragma: nocover raise AuroraXError("One or more required data source parameters are missing, delete operation aborted") # do request @@ -165,7 +165,7 @@ def delete_urls(aurorax_obj, data_source, urls): res = delete_req.execute() # evaluate response - if (res.status_code == 400): + if (res.status_code == 400): # pragma: nocover raise AuroraXAPIError("%s - %s" % (res.data["error_code"], res.data["error_message"])) # return @@ -174,7 +174,7 @@ def delete_urls(aurorax_obj, data_source, urls): def delete(aurorax_obj, data_source, start, end, data_product_types): # check to make sure the identifier, program, platform, and instrument type are all set in the data source - if not all([data_source.identifier, data_source.program, data_source.platform, data_source.instrument_type]): + if not all([data_source.identifier, data_source.program, data_source.platform, data_source.instrument_type]): # pragma: nocover raise AuroraXError("One or more required data source parameters are missing, delete operation aborted") # do request to get all data products between start and end datetimes @@ -192,7 +192,7 @@ def delete(aurorax_obj, data_source, start, end, data_product_types): poll_interval=__STANDARD_POLLING_SLEEP_TIME, return_immediately=False, verbose=False) - except Exception as e: + except Exception as e: # pragma: nocover raise AuroraXError(e) from e # collect URLs from search result diff --git a/pyaurorax/search/data_products/classes/data_product.py b/pyaurorax/search/data_products/classes/data_product.py index a846587e..ae561ee0 100644 --- a/pyaurorax/search/data_products/classes/data_product.py +++ b/pyaurorax/search/data_products/classes/data_product.py @@ -128,8 +128,6 @@ def to_json_serializable(self) -> Dict: for key, value in self.metadata.items(): if (isinstance(value, datetime.datetime) is True or isinstance(value, datetime.date) is True): self.metadata[key] = self.metadata[key].strftime("%Y-%m-%dT%H:%M:%S.%f") - # if (isinstance(self.metadata, list) is True): - # self.metadata = {} # format data source fields for query d["program"] = self.data_source.program diff --git a/pyaurorax/search/data_products/classes/search.py b/pyaurorax/search/data_products/classes/search.py index fe213276..c892da89 100644 --- a/pyaurorax/search/data_products/classes/search.py +++ b/pyaurorax/search/data_products/classes/search.py @@ -29,8 +29,9 @@ get_data as requests_get_data, get_status as requests_get_status, ) +from ...._util import show_warning if TYPE_CHECKING: - from ....pyaurorax import PyAuroraX + from ....pyaurorax import PyAuroraX # pragma: nocover class DataProductSearch: @@ -109,11 +110,18 @@ def __init__(self, programs: Optional[List[str]] = None, platforms: Optional[List[str]] = None, instrument_types: Optional[List[str]] = None, - data_product_types: Optional[Literal["keogram", "montage", "movie", "summary_plot", "data_availability"]] = None, + data_product_types: Optional[List[Literal["keogram", "montage", "movie", "summary_plot", "data_availability"]]] = None, metadata_filters: Optional[Union[MetadataFilter, List[Dict]]] = None, metadata_filters_logical_operator: Optional[Literal["and", "or", "AND", "OR"]] = None, response_format: Optional[Dict] = None) -> None: + # show warnings + if (isinstance(metadata_filters, MetadataFilter) and metadata_filters_logical_operator is not None): + # logical operator supplied, but MetadataFilter supplied too + show_warning("Supplying a MetadataFilter object in addition to the metadata_filters_logical_operator " + + "parameter is redundant. Only the MetadataFilter object is needed. The " + + "metadata_filters_logical_operator parameter will be ignored") + # set variables using passed in args self.__aurorax_obj = aurorax_obj self.start = start @@ -174,9 +182,7 @@ def pretty_print(self): # set logs string if (self.executed is True): - if (len(self.logs) == 0): - logs_str = "[0 log messages]" - elif (len(self.logs) == 1): + if (len(self.logs) == 1): # pragma: nocover logs_str = "[1 log message]" else: logs_str = "[%d log messages]" % (len(self.logs)) @@ -230,10 +236,6 @@ def query(self): # return return self.__query - @query.setter - def query(self, query): - self.__query = query - def execute(self) -> None: """ Initiate a data product search request @@ -268,7 +270,7 @@ def update_status(self, status: Optional[Dict] = None) -> None: status = requests_get_status(self.__aurorax_obj, self.request_url) # check response - if (status is None): + if (status is None): # pragma: nocover raise AuroraXAPIError("Could not retrieve status for this request") # update request status by checking if data URI is set diff --git a/pyaurorax/search/ephemeris/__init__.py b/pyaurorax/search/ephemeris/__init__.py index 9d8d1a21..1d6f1768 100644 --- a/pyaurorax/search/ephemeris/__init__.py +++ b/pyaurorax/search/ephemeris/__init__.py @@ -214,3 +214,62 @@ def get_request_url(self, request_id: str) -> str: The request URL """ return func_get_request_url(self.__aurorax_obj, request_id) + + def create_response_format_template(self, default: bool = False) -> Dict: + """ + Generate a template dictionary that can be used as the response_format parameter + in an ephemeris search. + + Args: + default (bool): + The default value to set for every parameter that can be returned, defaults + to False. + + Returns: + A template dictionary for the response format + """ + return { + "data_source": { + "identifier": default, + "program": default, + "platform": default, + "instrument_type": default, + "source_type": default, + "display_name": default, + "ephemeris_metadata_schema": { + "field_name": default, + "description": default, + "data_type": default, + "allowed_values": default, + "additional_description": default + }, + "data_product_metadata_schema": { + "field_name": default, + "description": default, + "data_type": default, + "allowed_values": default, + "additional_description": default + }, + "owner": default, + "maintainers": default, + "metadata": default + }, + "epoch": default, + "location_geo": { + "lat": default, + "lon": default + }, + "location_gsm": { + "lat": default, + "lon": default + }, + "nbtrace": { + "lat": default, + "lon": default + }, + "sbtrace": { + "lat": default, + "lon": default + }, + "metadata": default + } diff --git a/tests/test_suite/cli/search/conjunctions/test_get_data.py b/tests/test_suite/cli/search/conjunctions/test_get_data.py index 503803f4..23974a83 100644 --- a/tests/test_suite/cli/search/conjunctions/test_get_data.py +++ b/tests/test_suite/cli/search/conjunctions/test_get_data.py @@ -27,9 +27,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, conjunction_search_id): +def test_simple(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_data %s" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_data %s" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -40,10 +40,14 @@ def test_simple(cli_runner, conjunction_search_id): @pytest.mark.cli -def test_with_outfile(cli_runner, conjunction_search_id): +def test_with_outfile(cli_runner, api_url, conjunction_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search conjunctions get_data %s --outfile=%s" % (conjunction_search_id, output_filename)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_data %s --outfile=%s" % ( + api_url, + conjunction_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -53,10 +57,15 @@ def test_with_outfile(cli_runner, conjunction_search_id): @pytest.mark.cli -def test_with_outfile_indent(cli_runner, conjunction_search_id): +def test_with_outfile_indent(cli_runner, api_url, conjunction_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search conjunctions get_data %s --outfile=%s --indent=2" % (conjunction_search_id, output_filename)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search conjunctions get_data %s --outfile=%s --indent=2" % ( + api_url, + conjunction_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -66,10 +75,15 @@ def test_with_outfile_indent(cli_runner, conjunction_search_id): @pytest.mark.cli -def test_with_outfile_minify(cli_runner, conjunction_search_id): +def test_with_outfile_minify(cli_runner, api_url, conjunction_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search conjunctions get_data %s --outfile=%s --minify" % (conjunction_search_id, output_filename)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search conjunctions get_data %s --outfile=%s --minify" % ( + api_url, + conjunction_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -80,8 +94,13 @@ def test_with_outfile_minify(cli_runner, conjunction_search_id): @pytest.mark.cli @pytest.mark.parametrize("arg_value", ["dict", "objects"]) -def test_output_to_terminal(cli_runner, conjunction_search_id, arg_value): +def test_output_to_terminal(cli_runner, api_url, conjunction_search_id, arg_value): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_data %s --output-to-terminal=%s" % (conjunction_search_id, arg_value)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search conjunctions get_data %s --output-to-terminal=%s" % ( + api_url, + conjunction_search_id, + arg_value, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout diff --git a/tests/test_suite/cli/search/conjunctions/test_get_logs.py b/tests/test_suite/cli/search/conjunctions/test_get_logs.py index 5bbe162c..c7bab6bb 100644 --- a/tests/test_suite/cli/search/conjunctions/test_get_logs.py +++ b/tests/test_suite/cli/search/conjunctions/test_get_logs.py @@ -24,9 +24,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, conjunction_search_id): +def test_simple(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_logs %s" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_logs %s" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert result.stdout != "" @@ -41,24 +41,28 @@ def test_bad_request_id(cli_runner): @pytest.mark.cli @pytest.mark.parametrize("filter_param", ["debug", "info", "warn", "error"]) -def test_filter_logs(cli_runner, conjunction_search_id, filter_param): +def test_filter_logs(cli_runner, api_url, conjunction_search_id, filter_param): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_logs %s --filter=%s" % (conjunction_search_id, filter_param)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_logs %s --filter=%s" % ( + api_url, + conjunction_search_id, + filter_param, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_table_max_width(cli_runner, conjunction_search_id): +def test_table_max_width(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_logs %s --table-max-width=100" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_logs %s --table-max-width=100" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_no_truncate(cli_runner, conjunction_search_id): +def test_no_truncate(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_logs %s --no-truncate" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_logs %s --no-truncate" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/conjunctions/test_get_query.py b/tests/test_suite/cli/search/conjunctions/test_get_query.py index 5c05784d..69c203be 100644 --- a/tests/test_suite/cli/search/conjunctions/test_get_query.py +++ b/tests/test_suite/cli/search/conjunctions/test_get_query.py @@ -24,9 +24,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, conjunction_search_id): +def test_simple(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_query %s" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_query %s" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/conjunctions/test_get_status.py b/tests/test_suite/cli/search/conjunctions/test_get_status.py index cf010ef3..908027cf 100644 --- a/tests/test_suite/cli/search/conjunctions/test_get_status.py +++ b/tests/test_suite/cli/search/conjunctions/test_get_status.py @@ -24,42 +24,50 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, conjunction_search_id): +def test_simple(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_status %s" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_status %s" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_show_logs(cli_runner, conjunction_search_id): +def test_show_logs(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_status %s --show-logs" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_status %s --show-logs" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_show_query(cli_runner, conjunction_search_id): +def test_show_query(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_status %s --show-query" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_status %s --show-query" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli @pytest.mark.parametrize("filter_param", ["debug", "info", "warn", "error"]) -def test_filter_logs(cli_runner, conjunction_search_id, filter_param): +def test_filter_logs(cli_runner, api_url, conjunction_search_id, filter_param): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_status %s --show-logs --filter-logs=%s" % (conjunction_search_id, filter_param)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search conjunctions get_status %s --show-logs --filter-logs=%s" % ( + api_url, + conjunction_search_id, + filter_param, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_table_max_width(cli_runner, conjunction_search_id): +def test_table_max_width(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions get_status %s --table-max-width=100" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions get_status %s --table-max-width=100" % ( + api_url, + conjunction_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/conjunctions/test_search_resubmit.py b/tests/test_suite/cli/search/conjunctions/test_search_resubmit.py index 88b1bfa4..b37e3e35 100644 --- a/tests/test_suite/cli/search/conjunctions/test_search_resubmit.py +++ b/tests/test_suite/cli/search/conjunctions/test_search_resubmit.py @@ -24,9 +24,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, conjunction_search_id): +def test_simple(cli_runner, api_url, conjunction_search_id): # get the data - result = cli_runner.invoke(cli, "search conjunctions search_resubmit %s" % (conjunction_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search conjunctions search_resubmit %s" % (api_url, conjunction_search_id)) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/data_products/test_get_data.py b/tests/test_suite/cli/search/data_products/test_get_data.py index 16d97aa4..1412ea4b 100644 --- a/tests/test_suite/cli/search/data_products/test_get_data.py +++ b/tests/test_suite/cli/search/data_products/test_get_data.py @@ -27,9 +27,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, data_products_search_id): +def test_simple(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products get_data %s" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_data %s" % (api_url, data_products_search_id)) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -40,10 +40,15 @@ def test_simple(cli_runner, data_products_search_id): @pytest.mark.cli -def test_with_outfile(cli_runner, data_products_search_id): +def test_with_outfile(cli_runner, api_url, data_products_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search data_products get_data %s --outfile=%s" % (data_products_search_id, output_filename)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search data_products get_data %s --outfile=%s" % ( + api_url, + data_products_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -53,10 +58,15 @@ def test_with_outfile(cli_runner, data_products_search_id): @pytest.mark.cli -def test_with_outfile_indent(cli_runner, data_products_search_id): +def test_with_outfile_indent(cli_runner, api_url, data_products_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search data_products get_data %s --outfile=%s --indent=2" % (data_products_search_id, output_filename)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search data_products get_data %s --outfile=%s --indent=2" % ( + api_url, + data_products_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -66,10 +76,15 @@ def test_with_outfile_indent(cli_runner, data_products_search_id): @pytest.mark.cli -def test_with_outfile_minify(cli_runner, data_products_search_id): +def test_with_outfile_minify(cli_runner, api_url, data_products_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search data_products get_data %s --outfile=%s --minify" % (data_products_search_id, output_filename)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search data_products get_data %s --outfile=%s --minify" % ( + api_url, + data_products_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -80,8 +95,13 @@ def test_with_outfile_minify(cli_runner, data_products_search_id): @pytest.mark.cli @pytest.mark.parametrize("arg_value", ["dict", "objects"]) -def test_output_to_terminal(cli_runner, data_products_search_id, arg_value): +def test_output_to_terminal(cli_runner, api_url, data_products_search_id, arg_value): # get the data - result = cli_runner.invoke(cli, "search data_products get_data %s --output-to-terminal=%s" % (data_products_search_id, arg_value)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search data_products get_data %s --output-to-terminal=%s" % ( + api_url, + data_products_search_id, + arg_value, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout diff --git a/tests/test_suite/cli/search/data_products/test_get_logs.py b/tests/test_suite/cli/search/data_products/test_get_logs.py index 3a18fb43..0b4e0b36 100644 --- a/tests/test_suite/cli/search/data_products/test_get_logs.py +++ b/tests/test_suite/cli/search/data_products/test_get_logs.py @@ -24,9 +24,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, data_products_search_id): +def test_simple(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products get_logs %s" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_logs %s" % (api_url, data_products_search_id)) assert result.exit_code == 0 assert result.stdout != "" @@ -41,16 +41,23 @@ def test_bad_request_id(cli_runner): @pytest.mark.cli @pytest.mark.parametrize("filter_param", ["debug", "info", "warn", "error"]) -def test_filter_logs(cli_runner, data_products_search_id, filter_param): +def test_filter_logs(cli_runner, api_url, data_products_search_id, filter_param): # get the data - result = cli_runner.invoke(cli, "search data_products get_logs %s --filter=%s" % (data_products_search_id, filter_param)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_logs %s --filter=%s" % ( + api_url, + data_products_search_id, + filter_param, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_table_max_width(cli_runner, data_products_search_id): +def test_table_max_width(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products get_logs %s --table-max-width=100" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_logs %s --table-max-width=100" % ( + api_url, + data_products_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/data_products/test_get_query.py b/tests/test_suite/cli/search/data_products/test_get_query.py index c75383ed..06638d1b 100644 --- a/tests/test_suite/cli/search/data_products/test_get_query.py +++ b/tests/test_suite/cli/search/data_products/test_get_query.py @@ -24,9 +24,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, data_products_search_id): +def test_simple(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products get_query %s" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_query %s" % (api_url, data_products_search_id)) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/data_products/test_get_status.py b/tests/test_suite/cli/search/data_products/test_get_status.py index f0753b60..8d442ffa 100644 --- a/tests/test_suite/cli/search/data_products/test_get_status.py +++ b/tests/test_suite/cli/search/data_products/test_get_status.py @@ -24,42 +24,56 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, data_products_search_id): +def test_simple(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products get_status %s" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_status %s" % (api_url, data_products_search_id)) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_show_logs(cli_runner, data_products_search_id): +def test_show_logs(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products get_status %s --show-logs" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_status %s --show-logs" % ( + api_url, + data_products_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_show_query(cli_runner, data_products_search_id): +def test_show_query(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products get_status %s --show-query" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_status %s --show-query" % ( + api_url, + data_products_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli @pytest.mark.parametrize("filter_param", ["debug", "info", "warn", "error"]) -def test_filter_logs(cli_runner, data_products_search_id, filter_param): +def test_filter_logs(cli_runner, api_url, data_products_search_id, filter_param): # get the data - result = cli_runner.invoke(cli, "search data_products get_status %s --show-logs --filter-logs=%s" % (data_products_search_id, filter_param)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search data_products get_status %s --show-logs --filter-logs=%s" % ( + api_url, + data_products_search_id, + filter_param, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_table_max_width(cli_runner, data_products_search_id): +def test_table_max_width(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products get_status %s --table-max-width=100" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products get_status %s --table-max-width=100" % ( + api_url, + data_products_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/data_products/test_search_resubmit.py b/tests/test_suite/cli/search/data_products/test_search_resubmit.py index 22ac75f2..db699f7e 100644 --- a/tests/test_suite/cli/search/data_products/test_search_resubmit.py +++ b/tests/test_suite/cli/search/data_products/test_search_resubmit.py @@ -24,9 +24,12 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, data_products_search_id): +def test_simple(cli_runner, api_url, data_products_search_id): # get the data - result = cli_runner.invoke(cli, "search data_products search_resubmit %s" % (data_products_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search data_products search_resubmit %s" % ( + api_url, + data_products_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/ephemeris/test_get_data.py b/tests/test_suite/cli/search/ephemeris/test_get_data.py index e30230b2..f9456284 100644 --- a/tests/test_suite/cli/search/ephemeris/test_get_data.py +++ b/tests/test_suite/cli/search/ephemeris/test_get_data.py @@ -27,9 +27,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, ephemeris_search_id): +def test_simple(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_data %s" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_data %s" % (api_url, ephemeris_search_id)) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -40,10 +40,14 @@ def test_simple(cli_runner, ephemeris_search_id): @pytest.mark.cli -def test_with_outfile(cli_runner, ephemeris_search_id): +def test_with_outfile(cli_runner, api_url, ephemeris_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search ephemeris get_data %s --outfile=%s" % (ephemeris_search_id, output_filename)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_data %s --outfile=%s" % ( + api_url, + ephemeris_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -53,10 +57,15 @@ def test_with_outfile(cli_runner, ephemeris_search_id): @pytest.mark.cli -def test_with_outfile_indent(cli_runner, ephemeris_search_id): +def test_with_outfile_indent(cli_runner, api_url, ephemeris_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search ephemeris get_data %s --outfile=%s --indent=2" % (ephemeris_search_id, output_filename)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search ephemeris get_data %s --outfile=%s --indent=2" % ( + api_url, + ephemeris_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -66,10 +75,15 @@ def test_with_outfile_indent(cli_runner, ephemeris_search_id): @pytest.mark.cli -def test_with_outfile_minify(cli_runner, ephemeris_search_id): +def test_with_outfile_minify(cli_runner, api_url, ephemeris_search_id): # get the data output_filename = "/tmp/pyaurorax_testing_%s_data.json" % (''.join(random.choices(string.ascii_lowercase + string.digits, k=8))) - result = cli_runner.invoke(cli, "search ephemeris get_data %s --outfile=%s --minify" % (ephemeris_search_id, output_filename)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search ephemeris get_data %s --outfile=%s --minify" % ( + api_url, + ephemeris_search_id, + output_filename, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout @@ -80,8 +94,12 @@ def test_with_outfile_minify(cli_runner, ephemeris_search_id): @pytest.mark.cli @pytest.mark.parametrize("arg_value", ["dict", "objects"]) -def test_output_to_terminal(cli_runner, ephemeris_search_id, arg_value): +def test_output_to_terminal(cli_runner, api_url, ephemeris_search_id, arg_value): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_data %s --output-to-terminal=%s" % (ephemeris_search_id, arg_value)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_data %s --output-to-terminal=%s" % ( + api_url, + ephemeris_search_id, + arg_value, + )) assert result.exit_code == 0 assert "Checking request status" in result.stdout diff --git a/tests/test_suite/cli/search/ephemeris/test_get_logs.py b/tests/test_suite/cli/search/ephemeris/test_get_logs.py index 924cde19..0bcf082a 100644 --- a/tests/test_suite/cli/search/ephemeris/test_get_logs.py +++ b/tests/test_suite/cli/search/ephemeris/test_get_logs.py @@ -24,9 +24,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, ephemeris_search_id): +def test_simple(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_logs %s" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_logs %s" % (api_url, ephemeris_search_id)) assert result.exit_code == 0 assert result.stdout != "" @@ -41,16 +41,23 @@ def test_bad_request_id(cli_runner): @pytest.mark.cli @pytest.mark.parametrize("filter_param", ["debug", "info", "warn", "error"]) -def test_filter_logs(cli_runner, ephemeris_search_id, filter_param): +def test_filter_logs(cli_runner, api_url, ephemeris_search_id, filter_param): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_logs %s --filter=%s" % (ephemeris_search_id, filter_param)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_logs %s --filter=%s" % ( + api_url, + ephemeris_search_id, + filter_param, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_table_max_width(cli_runner, ephemeris_search_id): +def test_table_max_width(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_logs %s --table-max-width=100" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_logs %s --table-max-width=100" % ( + api_url, + ephemeris_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/ephemeris/test_get_query.py b/tests/test_suite/cli/search/ephemeris/test_get_query.py index 34a88c32..57d63a33 100644 --- a/tests/test_suite/cli/search/ephemeris/test_get_query.py +++ b/tests/test_suite/cli/search/ephemeris/test_get_query.py @@ -24,9 +24,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, ephemeris_search_id): +def test_simple(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_query %s" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_query %s" % (api_url, ephemeris_search_id)) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/ephemeris/test_get_status.py b/tests/test_suite/cli/search/ephemeris/test_get_status.py index 54d2d85c..e7217a0d 100644 --- a/tests/test_suite/cli/search/ephemeris/test_get_status.py +++ b/tests/test_suite/cli/search/ephemeris/test_get_status.py @@ -24,42 +24,56 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, ephemeris_search_id): +def test_simple(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_status %s" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_status %s" % (api_url, ephemeris_search_id)) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_show_logs(cli_runner, ephemeris_search_id): +def test_show_logs(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_status %s --show-logs" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_status %s --show-logs" % ( + api_url, + ephemeris_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_show_query(cli_runner, ephemeris_search_id): +def test_show_query(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_status %s --show-query" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_status %s --show-query" % ( + api_url, + ephemeris_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli @pytest.mark.parametrize("filter_param", ["debug", "info", "warn", "error"]) -def test_filter_logs(cli_runner, ephemeris_search_id, filter_param): +def test_filter_logs(cli_runner, api_url, ephemeris_search_id, filter_param): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_status %s --show-logs --filter-logs=%s" % (ephemeris_search_id, filter_param)) + result = cli_runner.invoke( + cli, "--api-base-url=%s search ephemeris get_status %s --show-logs --filter-logs=%s" % ( + api_url, + ephemeris_search_id, + filter_param, + )) assert result.exit_code == 0 assert result.stdout != "" @pytest.mark.cli -def test_table_max_width(cli_runner, ephemeris_search_id): +def test_table_max_width(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris get_status %s --table-max-width=100" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris get_status %s --table-max-width=100" % ( + api_url, + ephemeris_search_id, + )) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/cli/search/ephemeris/test_search_resubmit.py b/tests/test_suite/cli/search/ephemeris/test_search_resubmit.py index cd6235d5..2a47f5c2 100644 --- a/tests/test_suite/cli/search/ephemeris/test_search_resubmit.py +++ b/tests/test_suite/cli/search/ephemeris/test_search_resubmit.py @@ -24,9 +24,9 @@ def test_help(cli_runner): @pytest.mark.cli -def test_simple(cli_runner, ephemeris_search_id): +def test_simple(cli_runner, api_url, ephemeris_search_id): # get the data - result = cli_runner.invoke(cli, "search ephemeris search_resubmit %s" % (ephemeris_search_id)) + result = cli_runner.invoke(cli, "--api-base-url=%s search ephemeris search_resubmit %s" % (api_url, ephemeris_search_id)) assert result.exit_code == 0 assert result.stdout != "" diff --git a/tests/test_suite/conftest.py b/tests/test_suite/conftest.py index 85451bb1..137f04cd 100644 --- a/tests/test_suite/conftest.py +++ b/tests/test_suite/conftest.py @@ -23,6 +23,11 @@ from pathlib import Path from dotenv import load_dotenv +# globals +CONJUNCTION_SEARCH_REQUEST_ID = None +EPHEMERIS_SEARCH_REQUEST_ID = None +DATA_PRODUCTS_SEARCH_REQUEST_ID = None + def pytest_addoption(parser): parser.addoption("--api-url", action="store", default="https://api.staging.aurorax.space", help="A specific API URL to use") @@ -41,10 +46,7 @@ def cli_runner(): @pytest.fixture(scope="session") def conjunction_search_id(): - # NOTE: the below conjunction search request ID was taken from a - # manual conjunction search against the production API (example1.json - # from the examples/queries/conjunctions directory). - return "9c888643-af01-4ff9-922b-a772b3ff68cd" + return CONJUNCTION_SEARCH_REQUEST_ID @pytest.fixture(scope="session") @@ -54,10 +56,7 @@ def conjunction_search_input_filename(): @pytest.fixture(scope="session") def ephemeris_search_id(): - # NOTE: the below conjunction search request ID was taken from a - # manual ephemeris search against the production API (example2.json - # from the examples/queries/ephemeris directory). - return "ac2a02d9-94ee-499b-ad74-839e989b1859" + return EPHEMERIS_SEARCH_REQUEST_ID @pytest.fixture(scope="session") @@ -67,10 +66,7 @@ def ephemeris_search_input_filename(): @pytest.fixture(scope="session") def data_products_search_id(): - # NOTE: the below conjunction search request ID was taken from a - # manual data products search against the production API (example2.json - # from the examples/queries/data_products directory). - return "d719bcef-9ec5-4227-ba87-0fda7738ef57" + return DATA_PRODUCTS_SEARCH_REQUEST_ID @pytest.fixture(scope="session") @@ -99,7 +95,14 @@ def pytest_sessionstart(session): """ Called before any test is done """ + # init + d1 = datetime.datetime.now() + global CONJUNCTION_SEARCH_REQUEST_ID + global EPHEMERIS_SEARCH_REQUEST_ID + global DATA_PRODUCTS_SEARCH_REQUEST_ID + # initial setup + print("[SETUP] Setting up API URL and API key ...") api_url = session.config.getoption("--api-url") api_key = session.config.getoption("--api-key") if (api_key is None): @@ -109,6 +112,7 @@ def pytest_sessionstart(session): # create the generic data source that will be used for # ephemeris and data products upload/delete tests + print("[SETUP] Creating testing data source ...") program = "test-program" platform = "test-platform" instrument_type = "test-instrument-type" @@ -125,12 +129,42 @@ def pytest_sessionstart(session): source_type=source_type) aurorax.search.sources.add(ds) + # perform simple conjunction search, set the request ID + print("[SETUP] Performing conjunction search ...") + s = aurorax.search.conjunctions.search(datetime.datetime(2020, 1, 1, 0, 0, 0), + datetime.datetime(2020, 1, 1, 6, 59, 59), + 500, + ground=[aurorax.search.GroundCriteriaBlock(programs=["themis-asi"])], + space=[aurorax.search.SpaceCriteriaBlock(programs=["swarm"])]) + CONJUNCTION_SEARCH_REQUEST_ID = s.request_id + + # perform simple ephemeris search, set the request ID + print("[SETUP] Performing ephemeris search ...") + s = aurorax.search.ephemeris.search(datetime.datetime(2019, 1, 1, 0, 0, 0), + datetime.datetime(2019, 1, 1, 0, 9, 59), + programs=["swarm"], + platforms=["swarma"], + instrument_types=["footprint"]) + EPHEMERIS_SEARCH_REQUEST_ID = s.request_id + + # perform simple data product search, set the request ID + print("[SETUP] Performing data products search ...") + s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 6, 0, 0), + datetime.datetime(2020, 1, 1, 6, 59, 59), + programs=["auroramax"], + data_product_types=["keogram"]) + DATA_PRODUCTS_SEARCH_REQUEST_ID = s.request_id + + # complete + print("[SETUP] Initialization completed in %s" % (datetime.datetime.now() - d1)) + def pytest_sessionfinish(session, exitstatus): """ Called after whole test run finished, right before returning the exit status to the system. """ + print("[TEARDOWN] Cleaning up all testing data dirs ...") # delete all data testing dirs glob_str = "%s/pyaurorax_data_*testing*" % (str(Path.home())) path_list = sorted(glob.glob(glob_str)) @@ -231,3 +265,33 @@ def ephemeris_search_dict(): "start": "2025-02-05T16:36:43.720Z", "end": "2025-02-05T16:36:43.720Z" } + + +@pytest.fixture(scope="session") +def data_products_search_obj(): + # init + aurorax = pyaurorax.PyAuroraX() + + # set vars + start_dt = datetime.datetime(2020, 1, 1, 0, 0, 0) + end_dt = datetime.datetime(2020, 1, 1, 23, 59, 59) + programs = ["auroramax"] + + # create search object + s = aurorax.search.DataProductSearch(aurorax, start_dt, end_dt, programs=programs) + + # return + return s + + +@pytest.fixture(scope="session") +def data_products_search_dict(): + return { + "data_sources": { + "programs": ["themis-asi"], + "platforms": ["gillam"], + "instrument_types": ["panchromatic ASI"], + }, + "start": "2025-02-05T16:36:43.720Z", + "end": "2025-02-05T16:36:43.720Z" + } diff --git a/tests/test_suite/search/conjunctions/test_search_object.py b/tests/test_suite/search/conjunctions/test_search_object.py index ec979988..1d35daa8 100644 --- a/tests/test_suite/search/conjunctions/test_search_object.py +++ b/tests/test_suite/search/conjunctions/test_search_object.py @@ -80,7 +80,6 @@ def test_create_object(aurorax, test_dict, capsys): # check describe function description = s.describe() - print(description) assert description != "" diff --git a/tests/test_suite/search/data_products/test_data_object.py b/tests/test_suite/search/data_products/test_data_object.py new file mode 100644 index 00000000..77d3d44c --- /dev/null +++ b/tests/test_suite/search/data_products/test_data_object.py @@ -0,0 +1,49 @@ +# Copyright 2024 University of Calgary +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest +import datetime +from pyaurorax.search import DataSource, DataProductData, DATA_PRODUCT_TYPE_KEOGRAM + + +@pytest.mark.search_ro +def test_create_data_product_object(aurorax): + # set values + program = "test-program" + platform = "test-platform" + instrument_type = "test-instrument-type" + start_dt = datetime.datetime(2020, 1, 1, 0, 0, 0) + end_dt = start_dt.replace(hour=23, minute=59, second=59) + data_product_type = DATA_PRODUCT_TYPE_KEOGRAM + url = "testing_url.jpg" + metadata = {} + + # get identifier + data_source = aurorax.search.sources.get(program, platform, instrument_type) + + # create DataProduct object + d = DataProductData( + data_source=data_source, + data_product_type=data_product_type, + url=url, + start=start_dt, + end=end_dt, + metadata=metadata, + ) + + assert isinstance(d, DataProductData) is True + assert isinstance(d.data_source, DataSource) is True + assert d.data_source.program == program + assert d.data_source.platform == platform + assert d.data_source.instrument_type == instrument_type diff --git a/tests/test_suite/search/data_products/test_data_products.py b/tests/test_suite/search/data_products/test_data_products.py deleted file mode 100644 index afb8cf63..00000000 --- a/tests/test_suite/search/data_products/test_data_products.py +++ /dev/null @@ -1,361 +0,0 @@ - -# import pytest -# import datetime -# import time -# from pyaurorax.search import ( -# DataSource, -# DataProductData, -# DataProductSearch, -# DATA_PRODUCT_TYPE_KEOGRAM, -# DATA_PRODUCT_TYPE_MOVIE, -# ) - -# # globals -# MAX_WAIT_TIME = 30 - - -# @pytest.mark.search_ro -# def test_create_data_product_object(aurorax): -# # set values -# program = "test-program" -# platform = "test-platform" -# instrument_type = "test-instrument-type" -# start_dt = datetime.datetime(2020, 1, 1, 0, 0, 0) -# end_dt = start_dt.replace(hour=23, minute=59, second=59) -# data_product_type = DATA_PRODUCT_TYPE_KEOGRAM -# url = "testing_url.jpg" -# metadata = {} - -# # get identifier -# data_source = aurorax.search.sources.get(program, platform, instrument_type) - -# # create DataProduct object -# d = DataProductData( -# data_source=data_source, -# data_product_type=data_product_type, -# url=url, -# start=start_dt, -# end=end_dt, -# metadata=metadata, -# ) - -# assert isinstance(d, DataProductData) is True -# assert isinstance(d.data_source, DataSource) is True -# assert d.data_source.program == program -# assert d.data_source.platform == platform -# assert d.data_source.instrument_type == instrument_type - - -# @pytest.mark.search_ro -# def test_create_data_products_search_object(aurorax): -# # set vars -# start_dt = datetime.datetime(2020, 1, 1, 0, 0, 0) -# end_dt = datetime.datetime(2020, 1, 1, 23, 59, 59) -# programs = ["auroramax"] - -# s = DataProductSearch(aurorax, start_dt, end_dt, programs=programs) - -# assert isinstance(s, DataProductSearch) is True -# assert s.start == start_dt -# assert s.end == end_dt -# assert s.programs == programs - - -# @pytest.mark.search_ro -# def test_search_data_products_synchronous(aurorax): -# s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), -# datetime.datetime(2020, 1, 2, 23, 59, 59), -# programs=["auroramax"], -# data_product_types=[DATA_PRODUCT_TYPE_KEOGRAM], -# verbose=False) - -# assert isinstance(s.data, list) is True -# assert len(s.data) > 0 -# assert isinstance(s.data[0], DataProductData) is True - - -# @pytest.mark.search_ro -# def test_search_data_products_asynchronous(aurorax): -# s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), -# datetime.datetime(2020, 1, 2, 23, 59, 59), -# programs=["auroramax"], -# return_immediately=True) - -# s.update_status() -# total_sleep_time = 0 -# while (s.completed is False and total_sleep_time < MAX_WAIT_TIME): -# time.sleep(1) -# s.update_status() -# total_sleep_time += 1 - -# if (total_sleep_time == MAX_WAIT_TIME): -# # search is taking too long to complete -# raise AssertionError("Request took too long to complete") - -# s.get_data() - -# assert isinstance(s.data, list) is True -# assert len(s.data) > 0 -# assert isinstance(s.data[0], DataProductData) is True - - -# @pytest.mark.search_ro -# def test_search_data_products_metadata_filters_synchronous(aurorax): -# metadata_filters = [{ -# "key": "keogram_type", -# "operator": "=", -# "values": ["daily_hires"] -# }, { -# "key": "movie_type", -# "operator": "=", -# "values": ["real-time daily"] -# }] -# s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), -# datetime.datetime(2020, 1, 2, 23, 59, 59), -# programs=["auroramax"], -# data_product_types=[DATA_PRODUCT_TYPE_KEOGRAM, DATA_PRODUCT_TYPE_MOVIE], -# metadata_filters=metadata_filters, -# verbose=False, -# metadata_filters_logical_operator="OR") - -# result = s.data -# result_filter = list( -# filter( -# lambda dp: (dp.data_product_type == DATA_PRODUCT_TYPE_MOVIE and dp.metadata["movie_type"] == "real-time daily") or -# (dp.data_product_type == DATA_PRODUCT_TYPE_KEOGRAM and dp.metadata["keogram_type"] == "daily_hires"), result)) - -# assert len(s.data) == len(result_filter) - - -# @pytest.mark.search_ro -# def test_search_data_products_response_format_asynchronous(aurorax): -# s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), -# datetime.datetime(2020, 1, 2, 23, 59, 59), -# programs=["auroramax"], -# response_format={ -# "start": True, -# "end": True, -# "data_source": { -# "identifier": True, -# "program": True, -# }, -# "url": True, -# "metadata": True -# }, -# return_immediately=True) - -# s.update_status() -# total_sleep_time = 0 -# while (s.completed is False and total_sleep_time < MAX_WAIT_TIME): -# time.sleep(1) -# s.update_status() -# total_sleep_time += 1 - -# if (total_sleep_time == MAX_WAIT_TIME): -# # search is taking too long to complete -# raise AssertionError("Request took too long to complete") - -# s.get_data() - -# assert isinstance(s.data, list) is True -# assert len(s.data) > 0 -# assert isinstance(s.data[0], dict) is True -# assert "data_product_type" not in s.data[0].keys() - - -# @pytest.mark.search_ro -# def test_search_data_products_logs(aurorax): -# s = DataProductSearch( -# aurorax, -# datetime.datetime(2020, 1, 1, 0, 0, 0), -# datetime.datetime(2020, 1, 1, 23, 59, 59), -# programs=["auroramax"], -# ) - -# s.execute() -# s.update_status() -# total_sleep_time = 0 -# while (s.completed is False and total_sleep_time < MAX_WAIT_TIME): -# time.sleep(1) -# s.update_status() -# total_sleep_time += 1 - -# if (total_sleep_time == MAX_WAIT_TIME): -# # search is taking too long to complete -# raise AssertionError("Request took too long to complete") - -# assert len(s.logs) > 0 - - -# @pytest.mark.search_ro -# def test_search_data_products_status(aurorax): -# s = DataProductSearch( -# aurorax, -# datetime.datetime(2020, 1, 1, 0, 0, 0), -# datetime.datetime(2020, 1, 1, 23, 59, 59), -# programs=["auroramax"], -# ) - -# s.execute() -# s.update_status() -# total_sleep_time = 0 -# while (s.completed is False and total_sleep_time < MAX_WAIT_TIME): -# time.sleep(1) -# s.update_status() -# total_sleep_time += 1 - -# if (total_sleep_time == MAX_WAIT_TIME): -# # search is taking too long to complete -# raise AssertionError("Request took too long to complete") - -# assert s.completed is True - - -# @pytest.mark.search_rw -# def test_upload_and_delete_data_products(aurorax): -# # set values -# program = "test-program" -# platform = "test-platform" -# instrument_type = "test-instrument-type" - -# # get the data source ID -# ds = aurorax.search.sources.get(program, platform, instrument_type) - -# # set values -# metadata = { -# "test_meta1": "testing1", -# "test_meta2": "testing2", -# } -# url1 = "test.jpg" -# start_dt1 = datetime.datetime(2020, 1, 1, 0, 0, 0) -# end_dt1 = start_dt1.replace(hour=23, minute=59, second=59) -# url2 = "test2.jpg" -# start_dt2 = datetime.datetime(2020, 1, 2, 0, 0, 0) -# end_dt2 = start_dt2.replace(hour=23, minute=59, second=59) -# data_product_type = DATA_PRODUCT_TYPE_KEOGRAM - -# # create DataProducts objects -# dp1 = DataProductData(data_source=ds, data_product_type=data_product_type, url=url1, start=start_dt1, end=end_dt1, metadata=metadata) -# dp2 = DataProductData(data_source=ds, data_product_type=data_product_type, url=url2, start=start_dt2, end=end_dt2, metadata=metadata) - -# # set records array -# records = [dp1, dp2] - -# # upload records -# result = aurorax.search.data_products.upload(ds.identifier, records, True) -# assert result == 0 - -# # check that records got uploaded -# # -# # NOTE: we periodically check a few times -# max_tries = 10 -# for i in range(1, max_tries + 1): -# # wait to it to be ingested -# time.sleep(5) - -# # search for data -# s = DataProductSearch( -# aurorax, -# start_dt1, -# end_dt2, -# programs=[program], -# platforms=[platform], -# instrument_types=[instrument_type], -# ) -# s.execute() -# s.wait() -# s.get_data() - -# # check -# if (len(s.data) == 0): -# if (i == max_tries): -# # failed after all the tries for checking -# raise AssertionError("Max tries reached") -# else: -# continue -# assert len(s.data) > 0 -# break - -# # cleanup by deleting the data products data that was uploaded -# delete_result = aurorax.search.ephemeris.delete( -# ds, -# datetime.datetime(2020, 1, 1, 0, 0), -# datetime.datetime(2020, 1, 3, 0, 0), -# ) -# assert delete_result == 0 - - -# @pytest.mark.search_rw -# def test_upload_and_delete_urls_data_products(aurorax): -# # get data source -# program = "test-program" -# platform = "test-platform" -# instrument_type = "test-instrument-type" -# ds = aurorax.search.sources.get(program, platform, instrument_type) - -# # upload record -# url1 = "test_delete1.jpg" -# start_dt1 = datetime.datetime(2020, 2, 1, 0, 0, 0) -# end_dt1 = start_dt1.replace(hour=23, minute=59, second=59) -# url2 = "test_delete2.jpg" -# start_dt2 = datetime.datetime(2020, 2, 2, 0, 0, 0) -# end_dt2 = start_dt2.replace(hour=23, minute=59, second=59) -# dp1 = DataProductData(data_source=ds, data_product_type=DATA_PRODUCT_TYPE_KEOGRAM, url=url1, start=start_dt1, end=end_dt1) -# dp2 = DataProductData(data_source=ds, data_product_type=DATA_PRODUCT_TYPE_KEOGRAM, url=url2, start=start_dt2, end=end_dt2) -# records = [dp1, dp2] -# result = aurorax.search.data_products.upload(ds.identifier, records, True) -# assert result == 0 - -# # set urls to delete -# urls_to_delete = [dp1.url, dp2.url] - -# # delete data -# delete_result = aurorax.search.data_products.delete_urls(ds, urls_to_delete) -# assert delete_result == 0 - - -# @pytest.mark.search_ro -# def test_cancel_data_products_search(aurorax): -# # set up query params -# start_dt = datetime.datetime(2018, 1, 1) -# end_dt = datetime.datetime(2021, 12, 31, 23, 59, 59) -# programs = ["themis-asi", "auroramax", "trex"] - -# # search for data products -# s = DataProductSearch(aurorax, start=start_dt, end=end_dt, programs=programs) -# s.execute() - -# # cancel the search request -# result = s.cancel(wait=True) -# assert result == 0 - - -# @pytest.mark.search_ro -# def test_describe_data_products_search(aurorax): -# # set params -# start = datetime.datetime(2020, 1, 1, 0, 0, 0) -# end = datetime.datetime(2020, 1, 2, 23, 59, 59) -# programs = ["auroramax"] -# data_product_types = [DATA_PRODUCT_TYPE_KEOGRAM] -# expected_response_str = "Find data_products for ((program in (auroramax) filtered by " \ -# "metadata ()) AND data_product_metadata_filters []) AND data_product start >= " \ -# "2020-01-01T00:00 UTC AND data_product end <= 2020-01-02T23:59:59 UTC AND " \ -# "data_product_type in (keogram)" - -# # create search object -# s = DataProductSearch(aurorax, start, end, programs=programs, data_product_types=data_product_types) # type: ignore - -# # get describe string -# describe_str = aurorax.search.data_products.describe(s) - -# # test response -# assert describe_str is not None -# assert describe_str == expected_response_str - - -# @pytest.mark.search_ro -# def test_get_request_url(aurorax): -# request_id = "testing-request-id" -# expected_url = aurorax.api_base_url + "/api/v1/data_products/requests/" + request_id -# returned_url = aurorax.search.data_products.get_request_url(request_id) -# assert returned_url == expected_url diff --git a/tests/test_suite/search/data_products/test_describe.py b/tests/test_suite/search/data_products/test_describe.py new file mode 100644 index 00000000..52e530fc --- /dev/null +++ b/tests/test_suite/search/data_products/test_describe.py @@ -0,0 +1,50 @@ +# Copyright 2024 University of Calgary +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest +import pyaurorax + + +@pytest.mark.search_ro +def test_simple(aurorax, data_products_search_obj): + # get describe string + describe_str = aurorax.search.data_products.describe(data_products_search_obj) + + # test response + assert describe_str is not None and describe_str != "" + + +@pytest.mark.search_ro +def test_search_object(aurorax, data_products_search_obj): + # get describe string + describe_str = aurorax.search.data_products.describe(search_obj=data_products_search_obj) + + # test response + assert describe_str is not None and describe_str != "" + + +@pytest.mark.search_ro +def test_search_dict(aurorax, data_products_search_dict): + # get describe string + describe_str = aurorax.search.data_products.describe(query_dict=data_products_search_dict) + + # test response + assert describe_str is not None and describe_str != "" + + +@pytest.mark.search_ro +def test_bad(aurorax): + with pytest.raises(pyaurorax.AuroraXError) as e_info: + aurorax.search.data_products.describe() + assert "One of 'search_obj' or 'query_dict' must be supplied" in str(e_info) diff --git a/tests/test_suite/search/data_products/test_get_request_url.py b/tests/test_suite/search/data_products/test_get_request_url.py new file mode 100644 index 00000000..1ead90f8 --- /dev/null +++ b/tests/test_suite/search/data_products/test_get_request_url.py @@ -0,0 +1,23 @@ +# Copyright 2024 University of Calgary +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest + + +@pytest.mark.search_ro +def test_get_request_url(aurorax): + request_id = "testing-request-id" + expected_url = aurorax.api_base_url + "/api/v1/data_products/requests/" + request_id + returned_url = aurorax.search.data_products.get_request_url(request_id) + assert returned_url == expected_url diff --git a/tests/test_suite/search/data_products/test_search.py b/tests/test_suite/search/data_products/test_search.py new file mode 100644 index 00000000..0753f94f --- /dev/null +++ b/tests/test_suite/search/data_products/test_search.py @@ -0,0 +1,242 @@ +# Copyright 2024 University of Calgary +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest +import datetime +import warnings +from pyaurorax.search import DataProductSearch, DataProductData + + +@pytest.mark.search_ro +def test_simple(aurorax, capsys): + # do search + s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), + datetime.datetime(2020, 1, 2, 23, 59, 59), + programs=["auroramax"], + data_product_types=["keogram"], + verbose=True) + captured_stdout = capsys.readouterr().out + assert captured_stdout != "" + + # check + assert isinstance(s.data, list) is True + assert len(s.data) > 0 + for dp in s.data: + assert isinstance(dp, DataProductData) is True + + # check __str__ and __repr__ for DataProductSearch type + print_str = str(s) + assert print_str != "" + assert isinstance(str(s), str) is True + assert isinstance(repr(s), str) is True + s.pretty_print() + captured_stdout = capsys.readouterr().out + assert captured_stdout != "" + + # check describe function + description = s.describe() + assert description != "" + + +@pytest.mark.search_ro +def test_single_result(aurorax, capsys): + # set metadata filters + metadata_filters = aurorax.search.MetadataFilter( + expressions=[aurorax.search.MetadataFilterExpression("keogram_type", "daily_hires", operator="=")]) + + # perform search + s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), + datetime.datetime(2020, 1, 1, 23, 59, 59), + programs=["auroramax"], + data_product_types=["keogram"], + metadata_filters=metadata_filters, + verbose=False) + + # check + assert isinstance(s.data, list) is True + assert len(s.data) == 1 + for e in s.data: + assert isinstance(e, DataProductData) is True + + # check __str__ and __repr__ for DataProductSearch type + print_str = str(s) + assert print_str != "" + assert isinstance(str(s), str) is True + assert isinstance(repr(s), str) is True + s.pretty_print() + captured_stdout = capsys.readouterr().out + assert captured_stdout != "" + + +@pytest.mark.search_ro +def test_metadata_filters(aurorax): + # set metadata filters + metadata_filters = aurorax.search.MetadataFilter( + expressions=[ + aurorax.search.MetadataFilterExpression("keogram_type", "daily_hires", operator="="), + aurorax.search.MetadataFilterExpression("movie_type", "real-time daily", operator="="), + ], + operator="OR", + ) + + # perform search + s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), + datetime.datetime(2020, 1, 2, 23, 59, 59), + programs=["auroramax"], + data_product_types=["keogram", "movie"], + metadata_filters=metadata_filters) + + # check + assert isinstance(s.data, list) is True + assert len(s.data) > 0 + for dp in s.data: + assert isinstance(dp, DataProductData) is True + + # check describe function + description = s.describe() + assert description != "" + + +@pytest.mark.search_ro +def test_async(aurorax): + s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), + datetime.datetime(2020, 1, 2, 23, 59, 59), + programs=["auroramax"], + return_immediately=True) + + # get data + # + # NOTE: this is not supposed to be done at this point, but for coverage we + # include it + s.get_data() + + # update the status + # + # NOTE: this is not needed, but for coverage we include it + s.update_status() + + # wait for the request to finish + s.wait() + + # check for data + # + # NOTE: again, this is not needed, but for coverage we include it + s.check_for_data() + + # get data + s.get_data() + + # check + assert isinstance(s.data, list) is True + assert len(s.data) > 0 + for e in s.data: + assert isinstance(e, DataProductData) is True + + +@pytest.mark.search_ro +def test_response_format(aurorax): + # do search + s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), + datetime.datetime(2020, 1, 2, 23, 59, 59), + programs=["auroramax"], + response_format={ + "start": True, + "end": True, + "data_source": { + "identifier": True, + "program": True, + "platform": True, + "instrument_type": True, + }, + "url": True, + "data_product_type": True, + }) + + # wait for data + s.wait() + s.get_data() + + # check + assert isinstance(s.data, list) is True + assert len(s.data) > 0 + for e in s.data: + assert isinstance(e, dict) is True + assert "metadata" not in e.keys() + + # check describe function + description = s.describe() + assert description != "" + + +@pytest.mark.search_ro +def test_no_data(aurorax, capsys): + s = aurorax.search.data_products.search( + datetime.datetime(1990, 1, 1, 0, 0, 0), + datetime.datetime(1990, 1, 2, 23, 59, 59), + programs=["auroramax"], + ) + + # check + assert isinstance(s.data, list) is True + assert len(s.data) == 0 + + # check __str__ and __repr__ for DataProductSearch type + print_str = str(s) + assert print_str != "" + assert isinstance(str(s), str) is True + assert isinstance(repr(s), str) is True + s.pretty_print() + captured_stdout = capsys.readouterr().out + assert captured_stdout != "" + + +@pytest.mark.search_ro +def test_metadata_filter_warning(aurorax): + # set metadata filters + metadata_filters = aurorax.search.MetadataFilter( + expressions=[ + aurorax.search.MetadataFilterExpression("keogram_type", "daily_hires", operator="="), + aurorax.search.MetadataFilterExpression("movie_type", "real-time daily", operator="="), + ], + operator="OR", + ) + + # create object + with warnings.catch_warnings(record=True) as w: + _ = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), + datetime.datetime(2020, 1, 2, 23, 59, 59), + programs=["auroramax"], + data_product_types=["keogram", "movie"], + metadata_filters=metadata_filters, + metadata_filters_logical_operator="OR") + assert len(w) == 1 + assert issubclass(w[-1].category, UserWarning) + assert "Supplying a MetadataFilter object in addition to the metadata_filters_logical_operator parameter is redundant." in str(w[-1].message) + + +@pytest.mark.search_ro +def test_cancel(aurorax): + start_dt = datetime.datetime(2018, 1, 1, 0, 0, 0) + end_dt = datetime.datetime(2021, 12, 31, 23, 59, 59) + programs = ["themis"] + + # do search + s = DataProductSearch(aurorax, start=start_dt, end=end_dt, programs=programs) + s.execute() + + # cancel it + result = s.cancel(wait=True) + + # check it was cancelled + assert result == 0 diff --git a/tests/test_suite/search/data_products/test_search_legacy.py b/tests/test_suite/search/data_products/test_search_legacy.py new file mode 100644 index 00000000..bc86656f --- /dev/null +++ b/tests/test_suite/search/data_products/test_search_legacy.py @@ -0,0 +1,63 @@ +# Copyright 2024 University of Calgary +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest +import datetime +from pyaurorax.search import DataProductData, DATA_PRODUCT_TYPE_MOVIE, DATA_PRODUCT_TYPE_KEOGRAM + + +@pytest.mark.search_ro +def test_metadata_filters(aurorax, capsys): + metadata_filters = [{ + "key": "keogram_type", + "operator": "=", + "values": ["daily_hires"] + }, { + "key": "movie_type", + "operator": "=", + "values": ["real-time daily"] + }] + s = aurorax.search.data_products.search(datetime.datetime(2020, 1, 1, 0, 0, 0), + datetime.datetime(2020, 1, 2, 23, 59, 59), + programs=["auroramax"], + data_product_types=[DATA_PRODUCT_TYPE_KEOGRAM, DATA_PRODUCT_TYPE_MOVIE], + metadata_filters=metadata_filters, + verbose=False, + metadata_filters_logical_operator="OR") + + # check + assert isinstance(s.data, list) is True + assert len(s.data) > 0 + for e in s.data: + assert isinstance(e, DataProductData) is True + + # check __str__ and __repr__ for DataProductSearch type + print_str = str(s) + assert print_str != "" + assert isinstance(str(s), str) is True + assert isinstance(repr(s), str) is True + s.pretty_print() + captured_stdout = capsys.readouterr().out + assert captured_stdout != "" + + # check describe function + description = s.describe() + assert description != "" + + # deeper check on results + result_filter = list( + filter( + lambda dp: (dp.data_product_type == DATA_PRODUCT_TYPE_MOVIE and dp.metadata["movie_type"] == "real-time daily") or + (dp.data_product_type == DATA_PRODUCT_TYPE_KEOGRAM and dp.metadata["keogram_type"] == "daily_hires"), s.data)) + assert len(s.data) == len(result_filter) diff --git a/tests/test_suite/search/data_products/test_search_object.py b/tests/test_suite/search/data_products/test_search_object.py new file mode 100644 index 00000000..7a75614b --- /dev/null +++ b/tests/test_suite/search/data_products/test_search_object.py @@ -0,0 +1,138 @@ +# Copyright 2024 University of Calgary +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest +import datetime +import warnings +from pyaurorax.search import DataProductSearch, DATA_PRODUCT_TYPE_KEOGRAM, DATA_PRODUCT_TYPE_MOVIE + + +@pytest.mark.search_ro +def test_simple(aurorax, capsys): + # set vars + start_dt = datetime.datetime(2020, 1, 1, 0, 0, 0) + end_dt = datetime.datetime(2020, 1, 1, 23, 59, 59) + programs = ["auroramax"] + + # create search object + s = DataProductSearch(aurorax, start_dt, end_dt, programs=programs) + + # check + assert isinstance(s, DataProductSearch) is True + assert s.start == start_dt + assert s.end == end_dt + assert s.programs == programs + assert s.query != "" + + # check __str__ and __repr__ for DataProductSearch type + print_str = str(s) + assert print_str != "" + assert isinstance(str(s), str) is True + assert isinstance(repr(s), str) is True + s.pretty_print() + captured_stdout = capsys.readouterr().out + assert captured_stdout != "" + + # check describe function + description = s.describe() + assert description != "" + + +@pytest.mark.search_ro +def test_with_metadata_filters(aurorax, capsys): + # set search parameters + start = datetime.datetime(2020, 1, 1, 0, 0, 0) + end = datetime.datetime(2020, 1, 2, 23, 59, 59) + programs = ["auroramax"] + + # set metadata filters + metadata_filter = aurorax.search.MetadataFilter( + expressions=[ + aurorax.search.MetadataFilterExpression("keogram_type", "daily_hires", operator="="), + aurorax.search.MetadataFilterExpression("movie_type", "real-time daily", operator="=") + ], + operator="OR", + ) + + # create object + s = DataProductSearch( + aurorax, + start, + end, + programs=programs, + data_product_types=["keogram", "movie"], + metadata_filters=metadata_filter, + ) + + # check + assert isinstance(s, DataProductSearch) is True + + # deeper check on data + for dp in s.data: + if (dp.data_product_type == DATA_PRODUCT_TYPE_MOVIE): + assert dp.metadata["movie_type"] == "real-time daily" # type: ignore + elif (dp.data_product_type == DATA_PRODUCT_TYPE_KEOGRAM): + assert dp.metadata["keogram_type"] == "daily_hires" # type: ignore + else: + raise AssertionError("Unexpected data product record included in search results") + + # check __str__ and __repr__ for EphemerisSearch type + print_str = str(s) + assert print_str != "" + assert isinstance(str(s), str) is True + assert isinstance(repr(s), str) is True + s.pretty_print() + captured_stdout = capsys.readouterr().out + assert captured_stdout != "" + + # check describe function + description = s.describe() + assert description != "" + + +@pytest.mark.search_ro +def test_create_response_format_template(aurorax): + response_format = aurorax.search.data_products.create_response_format_template() + assert isinstance(response_format, dict) is True + + +@pytest.mark.search_ro +def test_metadata_filter_warning(aurorax): + # set search parameters + start = datetime.datetime(2020, 1, 1, 0, 0, 0) + end = datetime.datetime(2020, 1, 2, 23, 59, 59) + programs = ["auroramax"] + + # set metadata filters + metadata_filter = aurorax.search.MetadataFilter( + expressions=[ + aurorax.search.MetadataFilterExpression("keogram_type", "daily_hires", operator="="), + aurorax.search.MetadataFilterExpression("movie_type", "real-time daily", operator="=") + ], + operator="OR", + ) + + # create object + with warnings.catch_warnings(record=True) as w: + _ = DataProductSearch( + aurorax, + start, + end, + programs=programs, + metadata_filters=metadata_filter, + metadata_filters_logical_operator="OR", + ) + assert len(w) == 1 + assert issubclass(w[-1].category, UserWarning) + assert "Supplying a MetadataFilter object in addition to the metadata_filters_logical_operator parameter is redundant." in str(w[-1].message) diff --git a/tests/test_suite/search/data_products/test_upload_delete.py b/tests/test_suite/search/data_products/test_upload_delete.py new file mode 100644 index 00000000..bc0baca8 --- /dev/null +++ b/tests/test_suite/search/data_products/test_upload_delete.py @@ -0,0 +1,121 @@ +# Copyright 2024 University of Calgary +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest +import datetime +import time +from pyaurorax.search import DataProductSearch, DataProductData, DATA_PRODUCT_TYPE_KEOGRAM + + +@pytest.mark.search_rw +def test_upload_and_delete(aurorax): + # set values + program = "test-program" + platform = "test-platform" + instrument_type = "test-instrument-type" + + # get the data source ID + ds = aurorax.search.sources.get(program, platform, instrument_type) + + # set values + metadata = { + "test_meta1": "testing1", + "test_meta2": "testing2", + } + url1 = "test.jpg" + start_dt1 = datetime.datetime(2020, 1, 1, 0, 0, 0) + end_dt1 = start_dt1.replace(hour=23, minute=59, second=59) + url2 = "test2.jpg" + start_dt2 = datetime.datetime(2020, 1, 2, 0, 0, 0) + end_dt2 = start_dt2.replace(hour=23, minute=59, second=59) + data_product_type = DATA_PRODUCT_TYPE_KEOGRAM + + # create DataProducts objects + dp1 = DataProductData(data_source=ds, data_product_type=data_product_type, url=url1, start=start_dt1, end=end_dt1, metadata=metadata) + dp2 = DataProductData(data_source=ds, data_product_type=data_product_type, url=url2, start=start_dt2, end=end_dt2, metadata=metadata) + + # set records array + records = [dp1, dp2] + + # upload records + result = aurorax.search.data_products.upload(ds.identifier, records, validate_source=True) + assert result == 0 + + # check that records got uploaded + # + # NOTE: we periodically check a few times + max_tries = 10 + for i in range(1, max_tries + 1): + # wait to it to be ingested + time.sleep(5) + + # search for data + s = DataProductSearch( + aurorax, + start_dt1, + end_dt2, + programs=[program], + platforms=[platform], + instrument_types=[instrument_type], + ) + s.execute() + s.wait() + s.get_data() + + # check + if (len(s.data) == 0): + if (i == max_tries): + # failed after all the tries for checking + raise AssertionError("Max tries reached") + else: + continue + assert len(s.data) > 0 + break + + # cleanup by deleting the data products data that was uploaded + delete_result = aurorax.search.data_products.delete( + ds, + datetime.datetime(2020, 1, 1, 0, 0), + datetime.datetime(2020, 1, 3, 0, 0), + ) + assert delete_result == 0 + + +@pytest.mark.search_rw +def test_upload_and_delete_urls(aurorax): + # get data source + program = "test-program" + platform = "test-platform" + instrument_type = "test-instrument-type" + ds = aurorax.search.sources.get(program, platform, instrument_type) + + # upload record + url1 = "test_delete1.jpg" + start_dt1 = datetime.datetime(2020, 2, 1, 0, 0, 0) + end_dt1 = start_dt1.replace(hour=23, minute=59, second=59) + url2 = "test_delete2.jpg" + start_dt2 = datetime.datetime(2020, 2, 2, 0, 0, 0) + end_dt2 = start_dt2.replace(hour=23, minute=59, second=59) + dp1 = DataProductData(data_source=ds, data_product_type=DATA_PRODUCT_TYPE_KEOGRAM, url=url1, start=start_dt1, end=end_dt1) + dp2 = DataProductData(data_source=ds, data_product_type=DATA_PRODUCT_TYPE_KEOGRAM, url=url2, start=start_dt2, end=end_dt2) + records = [dp1, dp2] + result = aurorax.search.data_products.upload(ds.identifier, records, True) + assert result == 0 + + # set urls to delete + urls_to_delete = [dp1.url, dp2.url] + + # delete data + delete_result = aurorax.search.data_products.delete_urls(ds, urls_to_delete) + assert delete_result == 0 diff --git a/tests/test_suite/search/ephemeris/test_data_object.py b/tests/test_suite/search/ephemeris/test_data_object.py index 13c1b651..fa40759a 100644 --- a/tests/test_suite/search/ephemeris/test_data_object.py +++ b/tests/test_suite/search/ephemeris/test_data_object.py @@ -18,7 +18,7 @@ @pytest.mark.search_ro -def test_create_ephemeris_data_object(aurorax): +def test_create_data_object(aurorax): # set values program = "test-program" platform = "test-platform" diff --git a/tests/test_suite/search/ephemeris/test_search_object.py b/tests/test_suite/search/ephemeris/test_search_object.py index 1abcb2e4..30687f5f 100644 --- a/tests/test_suite/search/ephemeris/test_search_object.py +++ b/tests/test_suite/search/ephemeris/test_search_object.py @@ -57,7 +57,6 @@ def test_simple(aurorax, capsys): # check describe function description = s.describe() - print(description) assert description != "" @@ -104,10 +103,15 @@ def test_with_metadata_filters(aurorax, capsys): # check describe function description = s.describe() - print(description) assert description != "" +@pytest.mark.search_ro +def test_create_response_format_template(aurorax): + response_format = aurorax.search.ephemeris.create_response_format_template() + assert isinstance(response_format, dict) is True + + @pytest.mark.search_ro def test_metadata_filter_warning(aurorax): # set search parameters diff --git a/tests/test_suite/search/test_location.py b/tests/test_suite/search/test_location.py index e812d448..0031b662 100644 --- a/tests/test_suite/search/test_location.py +++ b/tests/test_suite/search/test_location.py @@ -18,25 +18,25 @@ @pytest.mark.search_ro def test_create_object(): - l = Location(lat=51, lon=-110) - assert l.lat == 51.0 and l.lon == -110.0 + loc = Location(lat=51, lon=-110) + assert loc.lat == 51.0 and loc.lon == -110.0 - print_str = print(l) + print_str = print(loc) assert print_str != "" @pytest.mark.search_ro def test_change_object(): - l = Location(lat=51, lon=-110) - l.lat = 80.0 - l.lon = -150 - assert l.lat == 80.0 and l.lon == -150.0 + loc = Location(lat=51, lon=-110) + loc.lat = 80.0 + loc.lon = -150 + assert loc.lat == 80.0 and loc.lon == -150.0 @pytest.mark.search_ro def test_create_empty_object(): - l = Location(lat=None, lon=None) - assert l.lat is None and l.lon is None + loc = Location(lat=None, lon=None) + assert loc.lat is None and loc.lon is None @pytest.mark.search_ro @@ -47,31 +47,31 @@ def test_create_invalid_object(): @pytest.mark.search_ro def test_invalid_change1(): - l = Location(lat=51, lon=-114.) + loc = Location(lat=51, lon=-114.) with pytest.raises(ValueError) as e_info: - l.lat = None # type: ignore + loc.lat = None # type: ignore assert "Latitude and longitude must both be numbers, or both be None" in str(e_info) @pytest.mark.search_ro def test_invalid_change2(): - l = Location(lat=51, lon=-114.) + loc = Location(lat=51, lon=-114.) with pytest.raises(ValueError) as e_info: - l.lon = None # type: ignore + loc.lon = None # type: ignore assert "Latitude and longitude must both be numbers, or both be None" in str(e_info) @pytest.mark.search_ro def test_invalid_change3(): - l = Location(lat=None, lon=None) + loc = Location(lat=None, lon=None) with pytest.raises(ValueError) as e_info: - l.lat = 51 + loc.lat = 51 assert "Latitude and longitude must both be numbers, or both be None" in str(e_info) @pytest.mark.search_ro def test_invalid_change4(): - l = Location(lat=None, lon=None) + loc = Location(lat=None, lon=None) with pytest.raises(ValueError) as e_info: - l.lon = -114. + loc.lon = -114. assert "Latitude and longitude must both be numbers, or both be None" in str(e_info)