@@ -4514,7 +4514,7 @@ def test_plugins_search_cop_ghsl_check_input_parameters_valid(
45144514
45154515 @mock .patch ("eodag.plugins.search.cop_ghsl.CopGhslSearch._fetch_constraints" )
45164516 @mock .patch ("eodag.plugins.search.cop_ghsl.requests.get" )
4517- def test_plugins_search_cop_ghs_get_tiles_for_filters (
4517+ def test_plugins_search_cop_ghsl_get_tiles_for_filters (
45184518 self , mock_requests_get , mock_fetch_constraints
45194519 ):
45204520 mock_fetch_constraints .return_value = {"constraints" : self .constraints }
@@ -4576,7 +4576,54 @@ def test_plugins_search_cop_ghs_get_tiles_for_filters(
45764576 ]
45774577 )
45784578
4579- def test_plugins_search_cop_ghs_create_products_from_tiles (self ):
4579+ @mock .patch ("eodag.plugins.search.cop_ghsl.CopGhslSearch._fetch_constraints" )
4580+ @mock .patch ("eodag.plugins.search.cop_ghsl.requests.get" )
4581+ def test_plugins_search_cop_ghsl_get_tile_from_product_id (
4582+ self , mock_requests_get , mock_fetch_constraints
4583+ ):
4584+ """test fetching a tile for a product id"""
4585+ mock_fetch_constraints .return_value = {"constraints" : self .constraints }
4586+ provider_tiles = {
4587+ "grid" : [
4588+ {
4589+ "tileID" : "R3_C3" ,
4590+ "BBox" : ["-160.008" , "69.100" , "-150.008" , "59.100" ],
4591+ },
4592+ {
4593+ "tileID" : "R3_C4" ,
4594+ "BBox" : ["-150.008" , "69.100" , "-140.008" , "59.100" ],
4595+ },
4596+ {
4597+ "tileID" : "R3_C5" ,
4598+ "BBox" : ["-140.008" , "69.100" , "-130.008" , "59.100" ],
4599+ },
4600+ {
4601+ "tileID" : "R3_C6" ,
4602+ "BBox" : ["-130.008" , "69.100" , "-120.008" , "59.100" ],
4603+ },
4604+ ],
4605+ "unit" : "lat/lon" ,
4606+ }
4607+ mock_requests_get .return_value = MockResponse (
4608+ json_data = provider_tiles , status_code = 200
4609+ )
4610+ product_type = "GHS_BUILT_S"
4611+ plugin = next (
4612+ self .plugins_manager .get_search_plugins (
4613+ product_type = product_type , provider = "cop_ghsl"
4614+ )
4615+ )
4616+ params = {
4617+ "productType" : product_type ,
4618+ "id" : "GHS_BUILT_S__4326_3ss_2000_NRES__R3_C4" ,
4619+ }
4620+ tile , unit = plugin ._get_tile_from_product_id (params )
4621+ self .assertEqual ("lat/lon" , unit )
4622+ self .assertEqual (1 , len (tile ))
4623+ self .assertEqual (1 , len (tile ["2000" ]))
4624+ self .assertEqual ("R3_C4" , tile ["2000" ][0 ]["tileID" ])
4625+
4626+ def test_plugins_search_cop_ghsl_create_products_from_tiles (self ):
45804627 """test the creation of products based on tiles returned by the provider"""
45814628 tiles = {
45824629 "2000" : [
@@ -4653,3 +4700,134 @@ def test_plugins_search_cop_ghs_create_products_from_tiles(self):
46534700 geometry = ["-160.008" , "69.100" , "-150.008" , "59.100" ]
46544701 )
46554702 self .assertEqual (geometry , products [0 ].geometry )
4703+
4704+ def test_plugins_search_cop_ghsl_create_products_without_tiles (self ):
4705+ """test if products are created correctly for product types without tiles"""
4706+
4707+ prep = PreparedSearch (items_per_page = 5 )
4708+ # product type with one file
4709+ product_type = "GHS_FUA"
4710+ plugin = next (
4711+ self .plugins_manager .get_search_plugins (
4712+ product_type = product_type , provider = "cop_ghsl"
4713+ )
4714+ )
4715+ plugin .config .product_type_config = {
4716+ "productType" : product_type ,
4717+ "missionStartDate" : "2015-01-01T00:00:00Z" ,
4718+ "missionEndDate" : "2015-12-31T00:00:00Z" ,
4719+ }
4720+ products , count = plugin ._create_products_without_tiles (product_type , prep , {})
4721+ self .assertEqual (1 , count )
4722+ self .assertEqual (1 , len (products ))
4723+ properties = products [0 ].properties
4724+ self .assertEqual (
4725+ "2015-01-01T00:00:00Z" , properties ["startTimeFromAscendingNode" ]
4726+ )
4727+ self .assertEqual (
4728+ "2015-12-31T00:00:00Z" , properties ["completionTimeFromAscendingNode" ]
4729+ )
4730+ self .assertEqual (
4731+ "https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL//GHS_FUA_UCDB2015_GLOBE_R2019A"
4732+ "/V1-0/GHS_FUA_UCDB2015_GLOBE_R2019A_54009_1K_V1_0.zip" ,
4733+ properties ["downloadLink" ],
4734+ )
4735+ # product type with several files
4736+ product_type = "GHS_UCDB_REGION"
4737+ plugin = next (
4738+ self .plugins_manager .get_search_plugins (
4739+ product_type = product_type , provider = "cop_ghsl"
4740+ )
4741+ )
4742+ plugin .config .product_type_config = {
4743+ "productType" : product_type ,
4744+ "missionStartDate" : "1975-01-01T00:00:00Z" ,
4745+ "missionEndDate" : "2030-12-31T00:00:00Z" ,
4746+ }
4747+ # with filter for region
4748+ products , count = plugin ._create_products_without_tiles (
4749+ product_type , prep , {"region" : "EUROPE" , "grouped_by" : "region" }
4750+ )
4751+ self .assertEqual (1 , count )
4752+ self .assertEqual (1 , len (products ))
4753+ properties = products [0 ].properties
4754+ self .assertEqual (
4755+ "1975-01-01T00:00:00Z" , properties ["startTimeFromAscendingNode" ]
4756+ )
4757+ self .assertEqual (
4758+ "2030-12-31T00:00:00Z" , properties ["completionTimeFromAscendingNode" ]
4759+ )
4760+ self .assertEqual ("EUROPE" , properties ["region" ])
4761+ self .assertEqual (
4762+ "https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/GHS_UCDB_GLOBE_R2024A/GHS_UCDB_REGION_GLOBE_R2024A"
4763+ "/GHS_UCDB_REGION_EUROPE_R2024A/V1-1/GHS_UCDB_REGION_EUROPE_R2024A_V1_1.zip" ,
4764+ properties ["downloadLink" ],
4765+ )
4766+
4767+ # product type with several files and assets
4768+ product_type = "GHS_ENACT_POP"
4769+ plugin = next (
4770+ self .plugins_manager .get_search_plugins (
4771+ product_type = product_type , provider = "cop_ghsl"
4772+ )
4773+ )
4774+ filters = {
4775+ "grouped_by" : "month" ,
4776+ "month" : "02" ,
4777+ "tile_size" : "30ss" ,
4778+ "coord_system" : "4326" ,
4779+ }
4780+ product_type_mapping = deepcopy (plugin .config .products .get (product_type , {}))
4781+ filters .update (product_type_mapping )
4782+ products , count = plugin ._create_products_without_tiles (
4783+ product_type , prep , filters
4784+ )
4785+ self .assertEqual (1 , count )
4786+ self .assertEqual (1 , len (products ))
4787+ properties = products [0 ].properties
4788+ self .assertEqual (
4789+ "2011-02-01T00:00:00Z" , properties ["startTimeFromAscendingNode" ]
4790+ )
4791+ self .assertEqual (
4792+ "2011-02-28T23:59:59Z" , properties ["completionTimeFromAscendingNode" ]
4793+ )
4794+ self .assertEqual ("2011" , properties ["year" ])
4795+ self .assertEqual ("02" , properties ["month" ])
4796+ assets = products [0 ].assets
4797+ self .assertEqual (2 , len (assets ))
4798+ self .assertIn ("day" , assets )
4799+ self .assertEqual (
4800+ "https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/ENACT/ENACT_POP_2011_EU28_R2020A"
4801+ "/ENACT_POP_D022011_EU28_R2020A_4326_30ss/V1-0/ENACT_POP_D022011_EU28_R2020A_4326_30ss_V1_0.zip" ,
4802+ assets ["day" ]["href" ],
4803+ )
4804+ self .assertIn ("night" , assets )
4805+
4806+ @mock .patch ("eodag.plugins.search.cop_ghsl.CopGhslSearch._fetch_constraints" )
4807+ def test_plugins_search_cop_ghsl_discover_queryables (self , mock_fetch_constraints ):
4808+ """test that the correct queryables are returned"""
4809+ mock_fetch_constraints .return_value = {"constraints" : self .constraints }
4810+ plugin = next (
4811+ self .plugins_manager .get_search_plugins (
4812+ product_type = "GHS_BUILT_S" , provider = "cop_ghsl"
4813+ )
4814+ )
4815+ kwargs = {"productType" : "GHS_BUILT_S" }
4816+ queryables = plugin .discover_queryables (** kwargs )
4817+ self .assertEqual (6 , len (queryables ))
4818+ expected_queryables = [
4819+ "year" ,
4820+ "tile_size" ,
4821+ "coord_system" ,
4822+ "start" ,
4823+ "end" ,
4824+ "geom" ,
4825+ ]
4826+ for qu in expected_queryables :
4827+ self .assertIn (qu , queryables )
4828+ kwargs = {"productType" : "GHS_ENACT_POP" }
4829+ queryables = plugin .discover_queryables (** kwargs )
4830+ self .assertEqual (6 , len (queryables ))
4831+ expected_queryables = ["year" , "tile_size" , "coord_system" , "start" , "end" ]
4832+ for qu in expected_queryables :
4833+ self .assertIn (qu , queryables )
0 commit comments