def test_zero_grid(minimal_global_cfg, minimal_layer_cfg, minimal_dc, mock_range): minimal_global_cfg.wcs = True minimal_layer_cfg["wcs"] = { "native_crs": "EPSG:4326", "default_bands": ["band1", "band2", "band3"], } minimal_layer_cfg["product_name"] = "foo_nativeres" lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) mock_range["bboxes"]["EPSG:4326"] = { "top": 0.1, "bottom": 0.1, "left": -0.1, "right": 0.1, } with patch("datacube_ows.product_ranges.get_ranges") as get_rng: get_rng.return_value = mock_range with pytest.raises(ConfigException) as excinfo: lyr.make_ready(minimal_dc) assert not lyr.ready assert "Grid High y is zero" in str(excinfo.value) assert "a_layer" in str(excinfo.value) assert "EPSG:4326" in str(excinfo.value) lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) mock_range["bboxes"]["EPSG:4326"] = { "top": 0.1, "bottom": -0.1, "left": -0.1, "right": -0.1, } with patch("datacube_ows.product_ranges.get_ranges") as get_rng: get_rng.return_value = mock_range with pytest.raises(ConfigException) as excinfo: lyr.make_ready(minimal_dc) assert "Grid High x is zero" in str(excinfo.value) assert "a_layer" in str(excinfo.value) assert "EPSG:4326" in str(excinfo.value)
def test_manual_merge(minimal_layer_cfg, minimal_global_cfg): minimal_layer_cfg["image_processing"]["manual_merge"] = True minimal_layer_cfg["image_processing"]["apply_solar_corrections"] = False lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert not lyr.ready minimal_layer_cfg["image_processing"]["manual_merge"] = False minimal_layer_cfg["image_processing"]["apply_solar_corrections"] = True with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "Solar correction requires manual_merge" in str(excinfo.value)
def test_flag_bad_prod(minimal_layer_cfg, minimal_global_cfg, minimal_dc): minimal_layer_cfg["flags"] = {"product": "foolookupfail", "band": "band1"} lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) with pytest.raises(ConfigException) as excinfo: lyr.make_ready(dc=minimal_dc) assert "foolookupfail" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_plural_in_nonmultiproduct(minimal_layer_cfg, minimal_global_cfg): minimal_layer_cfg["low_res_product_names"] = "smolfoolookupfail" with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "a_layer" in str(excinfo.value) assert "'low_res_product_names' entry in non-multi-product layer" in str( excinfo.value) assert "use 'low_res_product_name' only" in str(excinfo.value) del minimal_layer_cfg["low_res_product_names"] minimal_layer_cfg["product_names"] = ["foo", "bar"] with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "a_layer" in str(excinfo.value) assert "'product_names' entry in non-multi-product layer" in str( excinfo.value) assert "use 'product_name' only" in str(excinfo.value)
def test_img_proc_no_extent_func(minimal_layer_cfg, minimal_global_cfg): del minimal_layer_cfg["image_processing"]["extent_mask_func"] with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "required" in str(excinfo.value) assert "a_layer" in str(excinfo.value) assert "extent_mask_func" in str(excinfo.value)
def test_no_styles(minimal_layer_cfg, minimal_global_cfg): del minimal_layer_cfg["styling"]["styles"] with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "Missing required" in str(excinfo.value) assert "styles" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_bad_default_style(minimal_layer_cfg, minimal_global_cfg): minimal_layer_cfg["styling"]["default_style"] = "nonexistent" with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "not in the 'styles'" in str(excinfo.value) assert "nonexistent" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_multi_product_lowres(minimal_multiprod_cfg, minimal_global_cfg, minimal_dc): minimal_multiprod_cfg["low_res_product_names"] = ["smol_foo", "smol_bar"] lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) lyr.make_ready(minimal_dc) assert len(lyr.products) == 2 assert len(lyr.low_res_products) == 2
def test_multi_product_name_mismatch(minimal_multiprod_cfg, minimal_global_cfg): minimal_multiprod_cfg["low_res_product_names"] = ["smol_foo"] with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) assert "low_res_product_names" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_singular_in_multiproduct(minimal_multiprod_cfg, minimal_global_cfg): minimal_multiprod_cfg["low_res_product_name"] = "smolfoolookupfail" with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) assert "'low_res_product_name' entry in multi-product layer" in str( excinfo.value) assert "use 'low_res_product_names' only" in str(excinfo.value) assert "a_layer" in str(excinfo.value) del minimal_multiprod_cfg["low_res_product_name"] minimal_multiprod_cfg["product_name"] = "foo" with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) assert "'product_name' entry in multi-product layer" in str(excinfo.value) assert "use 'product_names' only" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_noprod_multiproduct(minimal_multiprod_cfg, minimal_global_cfg, minimal_dc): minimal_multiprod_cfg["product_names"] = [] with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) assert "a_layer" in str(excinfo.value) assert "No products declared" in str(excinfo.value)
def test_bad_lowres_product_name(minimal_layer_cfg, minimal_global_cfg, minimal_dc): minimal_layer_cfg["low_res_product_name"] = "smolfoolookupfail" lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) with pytest.raises(ConfigException) as excinfo: lyr.make_ready(dc=minimal_dc) assert "Could not find product" in str(excinfo.value) assert "smolfoolookupfail" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_bad_product_name(minimal_layer_cfg, minimal_global_cfg, minimal_dc): minimal_layer_cfg["product_name"] = "foolookupfail" minimal_dc.index.products.get_by_name.return_value = None lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) with pytest.raises(ConfigException) as excinfo: lyr.make_ready(dc=minimal_dc) assert "Could not find product" in str(excinfo.value) assert "foolookupfail" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_no_wcs_default_bands(minimal_layer_cfg, minimal_global_cfg): minimal_global_cfg.wcs = True minimal_layer_cfg["wcs"] = {} with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "Missing required" in str(excinfo.value) assert "wcs" in str(excinfo.value) assert "default_bands" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_flag_plural_in_nonmultiproduct(minimal_layer_cfg, minimal_global_cfg): minimal_layer_cfg["flags"] = { "band": "foo", "products": ["prod1", "prod2"], } with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "a_layer" in str(excinfo.value) assert "'products' entry in flags section of non-multi-product layer" in str( excinfo.value) assert "use 'product' only" in str(excinfo.value) del minimal_layer_cfg["flags"]["products"] minimal_layer_cfg["flags"]["low_res_products"] = ["smolfoo", "smolbar"] with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "'low_res_products' entry in flags section of non-multi-product layer" in str( excinfo.value) assert "use 'low_res_product' only" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_multi_product_pq(minimal_multiprod_cfg, minimal_global_cfg, minimal_dc): minimal_multiprod_cfg["flags"] = { "products": ["flag_foo", "flag_bar"], "band": "band4", } lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) lyr.make_ready(minimal_dc) assert len(lyr.products) == 2 assert len(lyr.pq_products) == 2
def test_invalid_native_format(minimal_layer_cfg, minimal_global_cfg): minimal_global_cfg.wcs = True minimal_layer_cfg["wcs"] = { "default_bands": ["band1", "band2"], "native_format": "geosplunge" } with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "a_layer" in str(excinfo.value) assert "geosplunge" in str(excinfo.value)
def test_id_badauth(minimal_layer_cfg, minimal_global_cfg): minimal_layer_cfg["identifiers"] = { "auth0": "5318008", "authn": "mnnnmnnh" } with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "non-declared authority" in str(excinfo.value) assert "authn" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_flag_no_band(minimal_layer_cfg, minimal_global_cfg): minimal_layer_cfg["flags"] = { "product": "foo", } with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "required" in str(excinfo.value) assert "a_layer" in str(excinfo.value) assert "band" in str(excinfo.value)
def test_minimal_multiproduct(minimal_multiprod_cfg, minimal_global_cfg, minimal_dc, mock_range): lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) assert lyr.name == "a_layer" assert not lyr.ready with patch("datacube_ows.product_ranges.get_ranges") as get_rng: get_rng.return_value = mock_range lyr.make_ready(minimal_dc) assert lyr.ready assert not lyr.hide assert "a_layer" in str(lyr)
def test_multi_product_lrpq(minimal_multiprod_cfg, minimal_global_cfg, minimal_dc): minimal_multiprod_cfg["flags"] = [{ "products": ["flag_foo", "flag_bar"], "low_res_products": ["smol_flag_foo", "smol_flag_bar"], "band": "band4", }] lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) lyr.make_ready(minimal_dc) assert len(lyr.products) == 2 assert len(lyr.flag_bands["band4"].pq_products) == 2 assert len(lyr.flag_bands["band4"].pq_low_res_products) == 2
def test_flag_singular_in_multiproduct(minimal_multiprod_cfg, minimal_global_cfg): minimal_multiprod_cfg["flags"] = { "band": "foo", "product": "goo", } with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) assert "'product' entry in flags section of multi-product layer" in str( excinfo.value) assert "use 'products' only" in str(excinfo.value) assert "a_layer" in str(excinfo.value) del minimal_multiprod_cfg["flags"]["product"] minimal_multiprod_cfg["flags"]["low_res_product"] = "smolfoo" with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_multiprod_cfg, global_cfg=minimal_global_cfg) assert "'low_res_product' entry in flags section of multi-product layer" in str( excinfo.value) assert "use 'low_res_products' only" in str(excinfo.value) assert "a_layer" in str(excinfo.value)
def test_native_crs_none(minimal_global_cfg, minimal_layer_cfg, minimal_dc, mock_range): minimal_global_cfg.wcs = True minimal_layer_cfg["wcs"] = { "default_bands": ["band1", "band2"] } minimal_layer_cfg["product_name"] = "foo_nonativecrs" lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) with patch("datacube_ows.product_ranges.get_ranges") as get_rng: get_rng.return_value = mock_range with pytest.raises(ConfigException) as excinfo: lyr.make_ready(minimal_dc) assert "a_layer" in str(excinfo.value) assert "No native CRS" in str(excinfo.value)
def test_flag_info_mask(minimal_layer_cfg, minimal_global_cfg, minimal_dc): minimal_layer_cfg["flags"] = { "product": "foo", "band": "band4", "ignore_info_flags": ["moo", "blat", "zap"] } lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) lyr.make_ready(dc=minimal_dc) assert not 1 & lyr.info_mask assert 2 & lyr.info_mask assert not 4 & lyr.info_mask assert 8 & lyr.info_mask assert not 16 & lyr.info_mask assert 32 & lyr.info_mask
def test_no_native_resolution_noniter(minimal_global_cfg, minimal_layer_cfg, minimal_dc, mock_range): minimal_global_cfg.wcs = True minimal_layer_cfg["wcs"] = { "native_crs": "EPSG:4326", "default_bands": ["band1", "band2", "band3"], "native_resolution": 45, } minimal_layer_cfg["product_name"] = "foo_nonativeres" lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) with patch("datacube_ows.product_ranges.get_ranges") as get_rng: get_rng.return_value = mock_range with pytest.raises(ConfigException) as excinfo: lyr.make_ready(minimal_dc) assert "a_layer" in str(excinfo.value) assert "Invalid native resolution" in str(excinfo.value)
def test_native_resolution_mismatch(minimal_global_cfg, minimal_layer_cfg, minimal_dc, mock_range): minimal_global_cfg.wcs = True minimal_layer_cfg["wcs"] = { "native_crs": "EPSG:4326", "default_bands": ["band1", "band2", "band3"], "native_resolution": [0.1, 0.1], } minimal_layer_cfg["product_name"] = "foo_nativeres" lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) with patch("datacube_ows.product_ranges.get_ranges") as get_rng: get_rng.return_value = mock_range lyr.make_ready(minimal_dc) assert not lyr.hide assert lyr.ready assert math.isclose(lyr.resolution_x, 0.001, rel_tol=1e-8) assert math.isclose(lyr.resolution_y, 0.001, rel_tol=1e-8)
def test_native_crs_mismatch(minimal_global_cfg, minimal_layer_cfg, minimal_dc): minimal_global_cfg.wcs = True minimal_layer_cfg["wcs"] = { "native_crs": "EPSG:1234", "default_bands": ["band1", "band2", "band3"], } minimal_layer_cfg["product_name"] = "foo_nativecrs" lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) lyr.extract_bboxes = MagicMock() lyr.extract_bboxes.return_value = { "EPSG": { "top": 1, "bottom": -1, "left": -1, "right": 1, } } lyr.make_ready(minimal_dc) assert lyr.native_CRS == "EPSG:4326"
def test_native_crs_unpublished(minimal_global_cfg, minimal_layer_cfg, minimal_dc): minimal_global_cfg.wcs = True minimal_layer_cfg["wcs"] = { "default_bands": ["band1", "band2", "band3"], } minimal_layer_cfg["product_name"] = "foo_badnativecrs" lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) lyr.extract_bboxes = MagicMock() lyr.extract_bboxes.return_value = { "EPSG": { "top": 1, "bottom": -1, "left": -1, "right": 1, } } with pytest.raises(ConfigException) as excinfo: lyr.make_ready(minimal_dc) assert "EPSG:9999" in str(excinfo.value) assert "a_layer" in str(excinfo.value) assert "not in published CRSs" in str(excinfo.value)
def test_no_default_style(minimal_layer_cfg, minimal_global_cfg): del minimal_layer_cfg["styling"]["default_style"] lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert lyr.default_style.name == 'band1'
def test_bad_timeres(minimal_layer_cfg, minimal_global_cfg): minimal_layer_cfg["time_resolution"] = "prime_ministers" with pytest.raises(ConfigException) as excinfo: lyr = parse_ows_layer(minimal_layer_cfg, global_cfg=minimal_global_cfg) assert "Invalid time resolution" in str(excinfo.value) assert "prime_ministers" in str(excinfo.value)