|
9 | 9 | from obstore.store import LocalStore |
10 | 10 | from pytest_httpx import HTTPXMock, IteratorStream |
11 | 11 |
|
12 | | -from tests.storage_data import ers_granules, s5p_granules, umbra_granules |
13 | | -from tilebox.storage.aio import ASFStorageClient, CopernicusStorageClient, UmbraStorageClient, _HttpClient |
14 | | -from tilebox.storage.granule import ASFStorageGranule, CopernicusStorageGranule, UmbraStorageGranule |
| 12 | +from tests.storage_data import ers_granules, landsat_granules, s5p_granules, umbra_granules |
| 13 | +from tilebox.storage.aio import ( |
| 14 | + ASFStorageClient, |
| 15 | + CopernicusStorageClient, |
| 16 | + UmbraStorageClient, |
| 17 | + USGSLandsatStorageClient, |
| 18 | + _HttpClient, |
| 19 | +) |
| 20 | +from tilebox.storage.granule import ( |
| 21 | + ASFStorageGranule, |
| 22 | + CopernicusStorageGranule, |
| 23 | + UmbraStorageGranule, |
| 24 | + USGSLandsatStorageGranule, |
| 25 | +) |
15 | 26 |
|
16 | 27 |
|
17 | 28 | @pytest.mark.asyncio |
@@ -277,3 +288,74 @@ async def test_copernicus_storage_client_download_objects(granule: CopernicusSto |
277 | 288 | assert folder.exists() |
278 | 289 | assert (folder / granule.granule_name).read_bytes() == b"content1" |
279 | 290 | assert not (folder / f"other_product_{granule.granule_name}").exists() |
| 291 | + |
| 292 | + |
| 293 | +@pytest.mark.asyncio |
| 294 | +@given(landsat_granules()) |
| 295 | +@settings(max_examples=1, deadline=timedelta(milliseconds=100)) |
| 296 | +async def test_landsat_storage_client_download(granule: USGSLandsatStorageGranule) -> None: |
| 297 | + with TemporaryDirectory(delete=True) as tmp_path: |
| 298 | + store_path = Path(tmp_path) / "store" |
| 299 | + store_path.mkdir(exist_ok=True, parents=True) |
| 300 | + store = LocalStore(store_path) |
| 301 | + |
| 302 | + await store.put_async( |
| 303 | + f"{granule.location.removeprefix('s3://usgs-landsat/')}/{granule.granule_name}", b"content1" |
| 304 | + ) |
| 305 | + with patch("tilebox.storage.aio.S3Store") as store_mock: |
| 306 | + store_mock.return_value = store |
| 307 | + landsat = USGSLandsatStorageClient(cache_directory=Path(tmp_path)) |
| 308 | + |
| 309 | + folder = await landsat.download(granule, show_progress=False) |
| 310 | + assert folder.exists() |
| 311 | + assert (folder / granule.granule_name).read_bytes() == b"content1" |
| 312 | + |
| 313 | + |
| 314 | +@pytest.mark.asyncio |
| 315 | +@given(landsat_granules()) |
| 316 | +@settings(max_examples=1, deadline=timedelta(milliseconds=100)) |
| 317 | +async def test_landsat_storage_client_list_objects(granule: USGSLandsatStorageGranule) -> None: |
| 318 | + with TemporaryDirectory(delete=True) as tmp_path: |
| 319 | + store_path = Path(tmp_path) / "store" |
| 320 | + store_path.mkdir(exist_ok=True, parents=True) |
| 321 | + store = LocalStore(store_path) |
| 322 | + |
| 323 | + await store.put_async( |
| 324 | + f"{granule.location.removeprefix('s3://usgs-landsat/')}/{granule.granule_name}", b"content1" |
| 325 | + ) |
| 326 | + await store.put_async( |
| 327 | + f"{granule.location.removeprefix('s3://usgs-landsat/')}/{granule.granule_name}_thumb_small.jpeg", |
| 328 | + b"content2", |
| 329 | + ) |
| 330 | + with patch("tilebox.storage.aio.S3Store") as store_mock: |
| 331 | + store_mock.return_value = store |
| 332 | + landsat = USGSLandsatStorageClient(cache_directory=Path(tmp_path)) |
| 333 | + |
| 334 | + objects = await landsat.list_objects(granule) |
| 335 | + assert len(objects) == 2 |
| 336 | + assert sorted(objects) == sorted([granule.granule_name, f"{granule.granule_name}_thumb_small.jpeg"]) |
| 337 | + |
| 338 | + |
| 339 | +@pytest.mark.asyncio |
| 340 | +@given(landsat_granules()) |
| 341 | +@settings(max_examples=1, deadline=timedelta(milliseconds=100)) |
| 342 | +async def test_landsat_storage_client_download_objects(granule: USGSLandsatStorageGranule) -> None: |
| 343 | + with TemporaryDirectory(delete=True) as tmp_path: |
| 344 | + store_path = Path(tmp_path) / "store" |
| 345 | + store_path.mkdir(exist_ok=True, parents=True) |
| 346 | + store = LocalStore(store_path) |
| 347 | + |
| 348 | + await store.put_async( |
| 349 | + f"{granule.location.removeprefix('s3://usgs-landsat/')}/{granule.granule_name}", b"content1" |
| 350 | + ) |
| 351 | + await store.put_async( |
| 352 | + f"{granule.location.removeprefix('s3://usgs-landsat/')}/other_product_{granule.granule_name}", b"content2" |
| 353 | + ) |
| 354 | + with patch("tilebox.storage.aio.S3Store") as store_mock: |
| 355 | + store_mock.return_value = store |
| 356 | + landsat = USGSLandsatStorageClient(cache_directory=Path(tmp_path)) |
| 357 | + |
| 358 | + folder = await landsat.download_objects(granule, [granule.granule_name], show_progress=False) |
| 359 | + assert folder.exists() |
| 360 | + assert (folder / granule.granule_name).read_bytes() == b"content1" |
| 361 | + assert not (folder / f"other_product_{granule.granule_name}").exists() |
0 commit comments