def test_override_config_from_env(self): """Default configuration must be overridden by environment variables""" default_config = config.load_default_config() os.environ["EODAG__USGS__PRIORITY"] = "5" os.environ["EODAG__USGS__API__EXTRACT"] = "false" os.environ["EODAG__USGS__API__CREDENTIALS__USERNAME"] = "******" os.environ["EODAG__USGS__API__CREDENTIALS__PASSWORD"] = "******" os.environ["EODAG__AWS_EOS__SEARCH__PRODUCT_LOCATION_SCHEME"] = "file" os.environ["EODAG__AWS_EOS__AUTH__CREDENTIALS__APIKEY"] = "api-key" os.environ[ "EODAG__AWS_EOS__AUTH__CREDENTIALS__AWS_ACCESS_KEY_ID"] = "access-key-id" os.environ[ "EODAG__AWS_EOS__AUTH__CREDENTIALS__AWS_SECRET_ACCESS_KEY"] = "secret-access-key" os.environ["EODAG__PEPS__DOWNLOAD__OUTPUTS_PREFIX"] = "/data" config.override_config_from_env(default_config) usgs_conf = default_config["usgs"] self.assertEqual(usgs_conf.priority, 5) self.assertEqual(usgs_conf.api.extract, False) self.assertEqual(usgs_conf.api.credentials["username"], "usr") self.assertEqual(usgs_conf.api.credentials["password"], "pwd") aws_conf = default_config["aws_eos"] self.assertEqual(aws_conf.search.product_location_scheme, "file") self.assertEqual(aws_conf.auth.credentials["apikey"], "api-key") self.assertEqual(aws_conf.auth.credentials["aws_access_key_id"], "access-key-id") self.assertEqual(aws_conf.auth.credentials["aws_secret_access_key"], "secret-access-key") peps_conf = default_config["peps"] self.assertEqual(peps_conf.download.outputs_prefix, "/data")
def test_override_config_from_file(self): """Default configuration must be overridden from a conf file""" default_config = config.load_default_config() file_path_override = os.path.join(os.path.dirname(__file__), "resources", "file_config_override.yml") # Content of file_config_override.yml # usgs: # priority: 5 # api: # extract: False # credentials: # username: usr # password: pwd # # aws_eos: # search: # product_location_scheme: file # auth: # credentials: # apikey: api-key # aws_access_key_id: access-key-id # aws_secret_access_key: secret-access-key # # peps: # download: # outputs_prefix: /data # # theia: # download: # outputs_prefix: config.override_config_from_file(default_config, file_path_override) usgs_conf = default_config["usgs"] self.assertEqual(usgs_conf.priority, 5) self.assertEqual(usgs_conf.api.extract, False) self.assertEqual(usgs_conf.api.credentials["username"], "usr") self.assertEqual(usgs_conf.api.credentials["password"], "pwd") aws_conf = default_config["aws_eos"] self.assertEqual(aws_conf.search.product_location_scheme, "file") self.assertEqual(aws_conf.auth.credentials["apikey"], "api-key") self.assertEqual(aws_conf.auth.credentials["aws_access_key_id"], "access-key-id") self.assertEqual(aws_conf.auth.credentials["aws_secret_access_key"], "secret-access-key") peps_conf = default_config["peps"] self.assertEqual(peps_conf.download.outputs_prefix, "/data") theia_conf = default_config["theia"] self.assertEqual(theia_conf.download.outputs_prefix, "/tmp")
def test_load_default_config(self): """Default config must be successfully loaded""" conf = config.load_default_config() self.assertIsInstance(conf, dict) for key, value in conf.items(): # keys of the default conf dict are the names of the provider self.assertEqual(key, value.name) # providers implementing download or api store their downloaded products in # tempdir by default download_plugin = getattr(value, "download", getattr(value, "api", None)) if download_plugin is not None: self.assertEqual(download_plugin.outputs_prefix, tempfile.gettempdir()) # priority is set to 0 unless you are 'peps' provider if key == "peps": self.assertEqual(value.priority, 1) else: self.assertEqual(value.priority, 0)
def test_override_config_from_str(self): """Default configuration must be overridden from a yaml conf str""" default_config = config.load_default_config() conf_update = yaml.safe_load(""" my_new_provider: priority: 4 search: type: StacSearch api_endpoint: https://api.my_new_provider/search products: S2_MSI_L1C: productType: sentinel2_l1c GENERIC_PRODUCT_TYPE: productType: '{productType}' download: type: AwsDownload base_uri: https://api.my_new_provider flatten_top_dirs: True auth: type: AwsAuth credentials: aws_access_key_id: access-key-id aws_secret_access_key: secret-access-key """) config.override_config_from_mapping(default_config, conf_update) my_new_provider_conf = default_config["my_new_provider"] self.assertEqual(my_new_provider_conf.priority, 4) self.assertIsInstance(my_new_provider_conf.search, config.PluginConfig) self.assertEqual( my_new_provider_conf.products["S2_MSI_L1C"]["productType"], "sentinel2_l1c") self.assertEqual( my_new_provider_conf.auth.credentials["aws_secret_access_key"], "secret-access-key", )
def test_override_config_from_file(self): """Default configuration must be overridden from a conf file""" default_config = config.load_default_config() file_path_override = os.path.join(os.path.dirname(__file__), "resources", "file_config_override.yml") # Content of file_config_override.yml # usgs: # priority: 5 # api: # extract: False # credentials: # username: usr # password: pwd # # aws_eos: # search: # product_location_scheme: file # auth: # credentials: # apikey: api-key # aws_access_key_id: access-key-id # aws_secret_access_key: secret-access-key # # peps: # download: # outputs_prefix: /data # # theia: # download: # outputs_prefix: # # my_new_provider: # priority: 4 # search: # noqa: F821 type: StacSearch # api_endpoint: https://api.my_new_provider/search # products: # S2_MSI_L1C: # productType: sentinel2_l1c # GENERIC_PRODUCT_TYPE: # productType: '{productType}' # download: # noqa: F821 type: AwsDownload # base_uri: https://api.my_new_provider # flatten_top_dirs: True # auth: # noqa: F821 type: AwsAuth # credentials: # aws_access_key_id: access-key-id # aws_secret_access_key: secret-access-key config.override_config_from_file(default_config, file_path_override) usgs_conf = default_config["usgs"] self.assertEqual(usgs_conf.priority, 5) self.assertEqual(usgs_conf.api.extract, False) self.assertEqual(usgs_conf.api.credentials["username"], "usr") self.assertEqual(usgs_conf.api.credentials["password"], "pwd") aws_conf = default_config["aws_eos"] self.assertEqual(aws_conf.search.product_location_scheme, "file") self.assertEqual(aws_conf.auth.credentials["apikey"], "api-key") self.assertEqual(aws_conf.auth.credentials["aws_access_key_id"], "access-key-id") self.assertEqual(aws_conf.auth.credentials["aws_secret_access_key"], "secret-access-key") peps_conf = default_config["peps"] self.assertEqual(peps_conf.download.outputs_prefix, "/data") theia_conf = default_config["theia"] self.assertEqual(theia_conf.download.outputs_prefix[-4:], "/tmp") my_new_provider_conf = default_config["my_new_provider"] self.assertEqual(my_new_provider_conf.priority, 4) self.assertIsInstance(my_new_provider_conf.search, config.PluginConfig) self.assertEqual(my_new_provider_conf.search.type, "StacSearch") self.assertEqual( my_new_provider_conf.search.api_endpoint, "https://api.my_new_provider/search", ) self.assertIsInstance(my_new_provider_conf.products, dict) self.assertEqual( my_new_provider_conf.products["S2_MSI_L1C"]["productType"], "sentinel2_l1c") self.assertEqual( my_new_provider_conf.products["GENERIC_PRODUCT_TYPE"] ["productType"], "{productType}", ) self.assertIsInstance(my_new_provider_conf.download, config.PluginConfig) self.assertEqual(my_new_provider_conf.download.type, "AwsDownload") self.assertEqual(my_new_provider_conf.download.base_uri, "https://api.my_new_provider") self.assertTrue(my_new_provider_conf.download.flatten_top_dirs) self.assertIsInstance(my_new_provider_conf.auth, config.PluginConfig) self.assertEqual(my_new_provider_conf.auth.type, "AwsAuth") self.assertEqual( my_new_provider_conf.auth.credentials["aws_access_key_id"], "access-key-id") self.assertEqual( my_new_provider_conf.auth.credentials["aws_secret_access_key"], "secret-access-key", )