diff --git a/CHANGELOG.md b/CHANGELOG.md index aebb4429..37db0181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,10 @@ You can check your current version with the following command: ``` For more information, see [UP42 Python package description](https://pypi.org/project/up42-py/). +## 2.1.0a6 + +**Sep TBD, 2024** +- Fix test coverage for `Catalog` class. ## 2.1.0a8 diff --git a/tests/conftest.py b/tests/conftest.py index 1c0eb0f6..7f65d548 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,6 @@ pytest_plugins = [ "tests.fixtures.fixtures_auth", - "tests.fixtures.fixtures_catalog", "tests.fixtures.fixtures_order", "tests.fixtures.fixtures_storage", "tests.fixtures.fixtures_tasking", diff --git a/tests/fixtures/fixtures_catalog.py b/tests/fixtures/fixtures_catalog.py deleted file mode 100644 index 974bf7ed..00000000 --- a/tests/fixtures/fixtures_catalog.py +++ /dev/null @@ -1,21 +0,0 @@ -import json -import pathlib - -import pytest - -from up42 import catalog - -from . import fixtures_globals as constants - - -@pytest.fixture -def catalog_mock(auth_mock, requests_mock): - url_data_product_schema = f"{constants.API_HOST}/orders/schema/{constants.DATA_PRODUCT_ID}" - with open( - pathlib.Path(__file__).resolve().parents[1] / "mock_data/data_product_spot_schema.json", - encoding="utf-8", - ) as json_file: - json_data_product_schema = json.load(json_file) - requests_mock.get(url=url_data_product_schema, json=json_data_product_schema) - - return catalog.Catalog(auth=auth_mock, workspace_id=constants.WORKSPACE_ID) diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 14905a58..01b019f1 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -1,5 +1,6 @@ import pathlib -from typing import Optional, cast +import uuid +from typing import List, Optional, cast import geojson # type: ignore import geopandas as gpd # type: ignore @@ -15,6 +16,8 @@ from . import helpers from .fixtures import fixtures_globals as constants +Geometry = catalog.Geometry + PHR = "phr" SIMPLE_BOX = shapely.box(0, 0, 1, 1).__geo_interface__ START_DATE = "2014-01-01" @@ -115,6 +118,10 @@ class TestCatalog: host = "oneatlas" catalog = catalog.Catalog(auth=mock.MagicMock(), workspace_id=constants.WORKSPACE_ID) + @pytest.fixture(params=["output_dir", "no_output_dir"]) + def output_directory(self, request, tmp_path) -> Optional[pathlib.Path]: + return tmp_path if request.param == "output_dir" else None + @pytest.fixture def product_glossary(self, requests_mock: req_mock.Mocker): collections_url = f"{constants.API_HOST}/v2/collections" @@ -258,7 +265,9 @@ def test_should_search( pd.testing.assert_frame_equal(gpd.GeoDataFrame.from_features(results, **columns), expected_df) @pytest.mark.usefixtures("product_glossary") - def test_should_download_available_quicklooks(self, requests_mock: req_mock.Mocker, tmp_path): + def test_should_download_available_quicklooks( + self, requests_mock: req_mock.Mocker, output_directory: Optional[pathlib.Path] + ): missing_image_id = "missing-image-id" image_id = "image-id" missing_quicklook_url = f"{constants.API_HOST}/catalog/{self.host}/image/{missing_image_id}/quicklook" @@ -271,9 +280,10 @@ def test_should_download_available_quicklooks(self, requests_mock: req_mock.Mock out_paths = self.catalog.download_quicklooks( image_ids=[image_id, missing_image_id], collection=PHR, - output_directory=tmp_path, + output_directory=output_directory, ) - assert out_paths == [str(tmp_path / f"quicklook_{image_id}.jpg")] + download_folder: pathlib.Path = output_directory if output_directory else pathlib.Path.cwd() / "catalog" + assert out_paths == [str(download_folder / f"quicklook_{image_id}.jpg")] @pytest.mark.parametrize( "usage_type", @@ -349,13 +359,57 @@ def test_should_estimate_order(self, requests_mock: req_mock.Mocker, auth_mock: requests_mock.post(url=url_order_estimation, json=expected_payload) assert catalog_obj.estimate_order(order_parameters) == 100 - -def test_construct_order_parameters(catalog_mock): - order_parameters = catalog_mock.construct_order_parameters( - data_product_id=constants.DATA_PRODUCT_ID, - image_id="123", - aoi=SIMPLE_BOX, + @pytest.mark.parametrize( + "aoi", + [ + SIMPLE_BOX, + None, + ], + ids=[ + "aoi:SIMPLE_BOX", + "aoi:None", + ], ) - assert isinstance(order_parameters, dict) - assert list(order_parameters.keys()) == ["dataProduct", "params"] - assert order_parameters["params"]["acquisitionMode"] is None + @pytest.mark.parametrize( + "tags", + [ + ["tag"], + None, + ], + ids=[ + "tags:Value", + "tags:None", + ], + ) + def test_should_construct_order_parameters( + self, + auth_mock: mock.MagicMock, + requests_mock: req_mock.Mocker, + aoi: Optional[Geometry], + tags: Optional[List[str]], + ): + schema_property = "any-property" + image_id = str(uuid.uuid4()) + url_schema = f"{constants.API_HOST}/orders/schema/{constants.DATA_PRODUCT_ID}" + requests_mock.get( + url_schema, + json={ + "required": [schema_property], + "properties": {schema_property: {"type": "string", "title": "string", "format": "string"}}, + }, + ) + order_parameters: order.OrderParams = catalog.Catalog( + auth_mock, constants.WORKSPACE_ID + ).construct_order_parameters( + data_product_id=constants.DATA_PRODUCT_ID, + image_id=image_id, + aoi=aoi, + tags=tags, + ) + assert schema_property in order_parameters["params"] + assert order_parameters["params"]["id"] == image_id + assert order_parameters["dataProduct"] == constants.DATA_PRODUCT_ID + if tags is not None: + assert order_parameters["tags"] == tags + if aoi is not None: + assert order_parameters["params"]["aoi"] == aoi diff --git a/up42/catalog.py b/up42/catalog.py index c9e0cd7f..df637548 100644 --- a/up42/catalog.py +++ b/up42/catalog.py @@ -274,14 +274,7 @@ def construct_order_parameters( self, data_product_id: str, image_id: str, - aoi: Union[ - dict, - geojson.Feature, - geojson.FeatureCollection, - list, - geopandas.GeoDataFrame, - geom.Polygon, - ] = None, + aoi: Optional[Geometry] = None, tags: Optional[List[str]] = None, ) -> order.OrderParams: """