def test_dataset(self):
        """"""
        client = Client()
        
        dataset = client.get_dataset(name='FAOSTAT_data_producer_prices')
        self.assertEqual(dataset.version, 'v1')
        self.assertEqual(len(dataset.files), 1)
        self.assertEqual(dataset.files[0].file_size, 26481)
        self.assertEqual(dataset.data_type.data_type, 'crop_production')

        dataset2 = client.get_dataset_by_uuid(dataset.uuid)
        self.assertEqual(dataset, dataset2)
    def test_download_dataset(self):
        """"""
        client = Client()
        client.MAX_WAITING_PERIOD = 0.1

        dataset = client.get_dataset(name='test_write_raster')
        downloads = client.download_dataset(dataset, target_dir=DATA_DIR)
        self.assertEqual(len(downloads), 2)
        for download, dsfile in zip(downloads, dataset.files):
            self.assertTrue(download.is_file())
            self.assertEqual(download.stat().st_size, dsfile.file_size)
            self.assertEqual(download.name, dsfile.file_name)
            self.assertEqual(download.parent.name, dataset.version)
            self.assertEqual(download.parent.parent.name, dataset.name)
            self.assertEqual(download.parent.parent.parent.name, dataset.data_type.data_type)
            download.unlink()
        rm_empty_dir(download.parent.parent.parent)
    def test_download_file(self):
        """"""
        client = Client()
        client.MAX_WAITING_PERIOD = 0.1
        dataset = client.get_dataset(name='FAOSTAT_data_producer_prices')

        # test failure
        def fail(x, y):
            raise Download.Failed("on purpose")
        self.assertRaises(Download.Failed,
            client.download_file, DATA_DIR, dataset.files[0], check=fail)
        self.assertFalse(DATA_DIR.joinpath(dataset.files[0].file_name).is_file())

        # test success
        download = client.download_file(DATA_DIR, dataset.files[0])
        self.assertEqual(download, DATA_DIR / dataset.files[0].file_name)
        self.assertTrue(download.is_file())
        self.assertEqual(download.stat().st_size, dataset.files[0].file_size)
        download.unlink()
        self.assertFalse(download.is_file())