Skip to content

Commit

Permalink
✅ test: Add RasterTileSetSourceCreationOptions tests
Browse files Browse the repository at this point in the history
Found a nice way to leverage pytest diffing when asserting a subset of a dict.
pytest-dev/pytest#2376 (comment)
  • Loading branch information
gtempus committed Dec 15, 2022
1 parent c284157 commit daf1e0a
Showing 1 changed file with 341 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import pytest

from app.models.enum.change_log import ChangeLogStatus
from app.models.enum.creation_options import RasterDrivers
from app.models.enum.sources import RasterSourceType
from app.models.orm.assets import Asset as ORMAsset
from app.models.pydantic.change_log import ChangeLog
from app.models.pydantic.creation_options import RasterTileSetSourceCreationOptions
from app.models.pydantic.jobs import Job
from app.models.pydantic.symbology import Symbology
from app.tasks.raster_tile_cache_assets import raster_tile_cache_asset
from app.tasks.raster_tile_cache_assets.symbology import SymbologyInfo

Expand Down Expand Up @@ -43,13 +47,25 @@ def creation_options_dict(source_asset_uuid):
def source_asset():
return ORMAsset(
creation_options={
"pixel_meaning": "test pixels",
"pixel_meaning": "test_pixels",
"data_type": "boolean",
"grid": "1/4000",
}
)


@pytest.fixture()
def raster_tile_set_source_creation_options():
return RasterTileSetSourceCreationOptions(
pixel_meaning="test_pixels",
data_type="boolean",
grid="1/4000",
source_type="raster",
source_driver="GeoTIFF",
symbology=Symbology(type="date_conf_intensity"),
)


@pytest.fixture()
def reprojection():
return (
Expand All @@ -70,7 +86,7 @@ def reprojection():

@pytest.fixture()
def symbology_info():
return SymbologyInfo(8, 1, AsyncMock(return_value=([], "myjob")))
return SymbologyInfo(8, 1, AsyncMock(return_value=([], "/dummy/symbology/uri")))


@pytest.fixture()
Expand Down Expand Up @@ -165,6 +181,329 @@ async def test_source_asset_is_retrieved_by_uuid(
)


@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.execute", autospec=True
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.symbology_constructor",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.reproject_to_web_mercator",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.RasterTileSetSourceCreationOptions",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.get_asset",
autospec=True,
)
@pytest.mark.asyncio
async def test_overrides_source_information_of_raster_tile_set_source_creation_options(
get_asset_dummy,
raster_tile_set_source_creation_options_mock,
web_mercator_dummy,
symbology_constructor_dummy,
execute_dummy,
tile_cache_asset_uuid,
creation_options_dict,
source_asset,
raster_tile_set_source_creation_options,
reprojection,
symbology_info,
change_log,
):
get_asset_dummy.return_value = source_asset
raster_tile_set_source_creation_options_mock.return_value = (
raster_tile_set_source_creation_options
)
symbology_constructor_dummy.__getitem__.return_value = symbology_info
web_mercator_dummy.return_value = reprojection
execute_dummy.return_value = change_log

await raster_tile_cache_asset(
"test_dataset", "2022", tile_cache_asset_uuid, creation_options_dict
)

_, kwargs = raster_tile_set_source_creation_options_mock.call_args_list[-1]
expected = {
"source_type": RasterSourceType.raster,
"source_driver": RasterDrivers.geotiff,
"source_uri": [
"s3://gfw-data-lake-test/test_dataset/2022/raster/epsg-4326/1/4000/test_pixels/geotiff/tiles.geojson"
],
}
assert expected == {k: v for k, v in kwargs.items() if k in expected}


@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.execute", autospec=True
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.symbology_constructor",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.reproject_to_web_mercator",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.RasterTileSetSourceCreationOptions",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.get_asset",
autospec=True,
)
@pytest.mark.asyncio
async def test_sets_calc_to_none_in_raster_tile_set_source_creation_options_for_web_mercator_projection(
get_asset_dummy,
raster_tile_set_source_creation_options_mock,
web_mercator_dummy,
symbology_constructor_dummy,
execute_dummy,
tile_cache_asset_uuid,
creation_options_dict,
source_asset,
raster_tile_set_source_creation_options,
reprojection,
symbology_info,
change_log,
):
get_asset_dummy.return_value = source_asset
raster_tile_set_source_creation_options_mock.return_value = (
raster_tile_set_source_creation_options
)
symbology_constructor_dummy.__getitem__.return_value = symbology_info
web_mercator_dummy.return_value = reprojection
execute_dummy.return_value = change_log

await raster_tile_cache_asset(
"test_dataset", "2022", tile_cache_asset_uuid, creation_options_dict
)

_, kwargs = raster_tile_set_source_creation_options_mock.call_args_list[-1]
expected = {
"calc": None,
}
assert expected == {k: v for k, v in kwargs.items() if k in expected}


@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.execute", autospec=True
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.symbology_constructor",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.reproject_to_web_mercator",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.RasterTileSetSourceCreationOptions",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.get_asset",
autospec=True,
)
@pytest.mark.asyncio
async def test_sets_resampling_method_from_input_params_in_raster_tile_set_source_creation_options_for_web_mercator_projection(
get_asset_dummy,
raster_tile_set_source_creation_options_mock,
web_mercator_dummy,
symbology_constructor_dummy,
execute_dummy,
tile_cache_asset_uuid,
creation_options_dict,
source_asset,
raster_tile_set_source_creation_options,
reprojection,
symbology_info,
change_log,
):
get_asset_dummy.return_value = source_asset
raster_tile_set_source_creation_options_mock.return_value = (
raster_tile_set_source_creation_options
)
symbology_constructor_dummy.__getitem__.return_value = symbology_info
web_mercator_dummy.return_value = reprojection
execute_dummy.return_value = change_log

await raster_tile_cache_asset(
"test_dataset", "2022", tile_cache_asset_uuid, creation_options_dict
)

_, kwargs = raster_tile_set_source_creation_options_mock.call_args_list[-1]
expected = {"resampling": creation_options_dict["creation_options"]["resampling"]}
assert expected == {k: v for k, v in kwargs.items() if k in expected}


@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.execute", autospec=True
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.symbology_constructor",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.reproject_to_web_mercator",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.RasterTileSetSourceCreationOptions",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.get_asset",
autospec=True,
)
@pytest.mark.asyncio
async def test_sets_compute_information_to_false_in_raster_tile_set_source_creation_options_for_web_mercator_projection(
get_asset_dummy,
raster_tile_set_source_creation_options_mock,
web_mercator_dummy,
symbology_constructor_dummy,
execute_dummy,
tile_cache_asset_uuid,
creation_options_dict,
source_asset,
raster_tile_set_source_creation_options,
reprojection,
symbology_info,
change_log,
):
get_asset_dummy.return_value = source_asset
raster_tile_set_source_creation_options_mock.return_value = (
raster_tile_set_source_creation_options
)
symbology_constructor_dummy.__getitem__.return_value = symbology_info
web_mercator_dummy.return_value = reprojection
execute_dummy.return_value = change_log

await raster_tile_cache_asset(
"test_dataset", "2022", tile_cache_asset_uuid, creation_options_dict
)

_, kwargs = raster_tile_set_source_creation_options_mock.call_args_list[-1]
expected = {
"compute_stats": False,
"compute_histogram": False,
}
assert expected == {k: v for k, v in kwargs.items() if k in expected}


@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.execute", autospec=True
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.symbology_constructor",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.reproject_to_web_mercator",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.RasterTileSetSourceCreationOptions",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.get_asset",
autospec=True,
)
@pytest.mark.asyncio
async def test_sets_symbology_from_input_data_in_raster_tile_set_source_creation_options_for_web_mercator_projection(
get_asset_dummy,
raster_tile_set_source_creation_options_mock,
web_mercator_dummy,
symbology_constructor_dummy,
execute_dummy,
tile_cache_asset_uuid,
creation_options_dict,
source_asset,
raster_tile_set_source_creation_options,
reprojection,
symbology_info,
change_log,
):
get_asset_dummy.return_value = source_asset
raster_tile_set_source_creation_options_mock.return_value = (
raster_tile_set_source_creation_options
)
symbology_constructor_dummy.__getitem__.return_value = symbology_info
web_mercator_dummy.return_value = reprojection
execute_dummy.return_value = change_log

await raster_tile_cache_asset(
"test_dataset", "2022", tile_cache_asset_uuid, creation_options_dict
)

_, kwargs = raster_tile_set_source_creation_options_mock.call_args_list[-1]
expected = {
"symbology": Symbology(
**creation_options_dict["creation_options"]["symbology"]
),
}
assert expected == {k: v for k, v in kwargs.items() if k in expected}


@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.execute", autospec=True
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.symbology_constructor",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.reproject_to_web_mercator",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.RasterTileSetSourceCreationOptions",
autospec=True,
)
@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.get_asset",
autospec=True,
)
@pytest.mark.asyncio
async def test_sets_subset_to_none_in_raster_tile_set_source_creation_options_for_web_mercator_projection(
get_asset_dummy,
raster_tile_set_source_creation_options_mock,
web_mercator_dummy,
symbology_constructor_dummy,
execute_dummy,
tile_cache_asset_uuid,
creation_options_dict,
source_asset,
raster_tile_set_source_creation_options,
reprojection,
symbology_info,
change_log,
):
get_asset_dummy.return_value = source_asset
raster_tile_set_source_creation_options_mock.return_value = (
raster_tile_set_source_creation_options
)
symbology_constructor_dummy.__getitem__.return_value = symbology_info
web_mercator_dummy.return_value = reprojection
execute_dummy.return_value = change_log

await raster_tile_cache_asset(
"test_dataset", "2022", tile_cache_asset_uuid, creation_options_dict
)

_, kwargs = raster_tile_set_source_creation_options_mock.call_args_list[-1]
expected = {
"subset": None,
}
assert expected == {k: v for k, v in kwargs.items() if k in expected}


@patch(
"app.tasks.raster_tile_cache_assets.raster_tile_cache_assets.execute", autospec=True
)
Expand Down

0 comments on commit daf1e0a

Please sign in to comment.