Пример #1
0
    def test_get_data_bad_download_on_unsupported_dataset_address_scheme_error(
            self):
        """If downloader doesn't return the downloaded file path, get_data must return an empty array"""  # noqa
        product = EOProduct(self.provider,
                            self.eoproduct_props,
                            productType=self.product_type)

        product.driver = mock.MagicMock(spec_set=NoDriver())
        product.driver.get_data_address.side_effect = UnsupportedDatasetAddressScheme

        mock_downloader = mock.MagicMock(spec_set=Download(
            provider=self.provider,
            config=config.PluginConfig.from_mapping({"extract": False}),
        ))
        mock_downloader.download.return_value = None
        mock_authenticator = mock.MagicMock(spec_set=Authentication(
            provider=self.provider,
            config=config.PluginConfig.from_mapping({})))

        product.register_downloader(mock_downloader, mock_authenticator)

        self.assertRaises(DownloadError, product.download)

        data, band = self.execute_get_data(product, give_back=("band", ))

        self.assertEqual(product.driver.get_data_address.call_count, 1)
        product.driver.get_data_address.assert_called_with(product, band)
        self.assertIsInstance(data, xr.DataArray)
        self.assertEqual(data.values.size, 0)
Пример #2
0
    def test_get_data_local_product_ok(self):
        """A call to get_data on a product present in the local filesystem must succeed"""  # noqa
        self.eoproduct_props.update(
            {"downloadLink": "file://{}".format(self.local_product_abspath)})
        product = EOProduct(self.provider,
                            self.eoproduct_props,
                            productType=self.product_type)
        product.driver = mock.MagicMock(spec_set=NoDriver())
        product.driver.get_data_address.return_value = self.local_band_file

        data, band = self.execute_get_data(product, give_back=("band", ))

        self.assertEqual(product.driver.get_data_address.call_count, 1)
        product.driver.get_data_address.assert_called_with(product, band)
        self.assertIsInstance(data, xr.DataArray)
        self.assertNotEqual(data.values.size, 0)
Пример #3
0
    def test_get_data_dl_on_unsupported_ds_address_scheme_error_wo_downloader(
            self):
        """If a product is not on filesystem and a downloader isn't registered, get_data must return an empty array"""  # noqa
        product = EOProduct(self.provider,
                            self.eoproduct_props,
                            productType=self.product_type)

        product.driver = mock.MagicMock(spec_set=NoDriver())
        product.driver.get_data_address.side_effect = UnsupportedDatasetAddressScheme

        self.assertRaises(RuntimeError, product.download)

        data = self.execute_get_data(product)

        self.assertEqual(product.driver.get_data_address.call_count, 1)
        self.assertIsInstance(data, xr.DataArray)
        self.assertEqual(data.values.size, 0)
Пример #4
0
    def test_get_data_download_on_unsupported_dataset_address_scheme_error(
            self):
        """If a product is not on the local filesystem, it must download itself before returning the data"""  # noqa
        product = EOProduct(self.provider,
                            self.eoproduct_props,
                            productType=self.product_type)

        def get_data_address(*args, **kwargs):
            eo_product = args[0]
            if eo_product.location.startswith("https"):
                raise UnsupportedDatasetAddressScheme
            return self.local_band_file

        product.driver = mock.MagicMock(spec_set=NoDriver())
        product.driver.get_data_address.side_effect = get_data_address

        mock_downloader = mock.MagicMock(spec_set=Download(
            provider=self.provider,
            config=config.PluginConfig.from_mapping({
                "extract": False,
                "archive_depth": 1
            }),
        ))
        mock_downloader.download.return_value = self.local_product_as_archive_path
        # mock_downloader.config = {'extract': False, 'archive_depth': 1}
        mock_authenticator = mock.MagicMock(spec_set=Authentication(
            provider=self.provider,
            config=config.PluginConfig.from_mapping({})))

        product.register_downloader(mock_downloader,
                                    mock_authenticator.authenticate())
        data, band = self.execute_get_data(product, give_back=("band", ))

        self.assertEqual(product.driver.get_data_address.call_count, 2)
        product.driver.get_data_address.assert_called_with(product, band)
        self.assertIsInstance(data, xr.DataArray)
        self.assertNotEqual(data.values.size, 0)