|
16 | 16 | import uuid |
17 | 17 | from pathlib import Path |
18 | 18 | from shutil import copyfile |
| 19 | +from typing import Any, Dict, Tuple |
19 | 20 |
|
20 | 21 | import attr |
21 | 22 | import pytest |
22 | 23 | import tests.utils |
23 | 24 | from simcore_service_storage.constants import DATCORE_STR, SIMCORE_S3_ID, SIMCORE_S3_STR |
| 25 | +from simcore_service_storage.dsm import DataStorageManager |
24 | 26 | from simcore_service_storage.models import FileMetaData |
| 27 | +from simcore_service_storage.s3wrapper.s3_client import MinioClientWrapper |
25 | 28 | from tests.utils import BUCKET_NAME, USER_ID, has_datcore_tokens |
26 | 29 |
|
27 | 30 |
|
@@ -592,6 +595,46 @@ async def test_dsm_list_datasets_s3(dsm_fixture, dsm_mockup_complete_db): |
592 | 595 | assert any("Kember" in d.display_name for d in datasets) |
593 | 596 |
|
594 | 597 |
|
| 598 | +async def test_sync_table_meta_data( |
| 599 | + dsm_fixture: DataStorageManager, |
| 600 | + dsm_mockup_complete_db: Tuple[Dict[str, str], Dict[str, str]], |
| 601 | + s3_client: MinioClientWrapper, |
| 602 | +): |
| 603 | + dsm_fixture.has_project_db = True |
| 604 | + |
| 605 | + expected_removed_files = [] |
| 606 | + # the list should be empty on start |
| 607 | + list_changes: Dict[str, Any] = await dsm_fixture.synchronise_meta_data_table( |
| 608 | + location=SIMCORE_S3_STR, dry_run=True |
| 609 | + ) |
| 610 | + assert "removed" in list_changes |
| 611 | + assert list_changes["removed"] == expected_removed_files |
| 612 | + |
| 613 | + # now remove the files |
| 614 | + for file_entry in dsm_mockup_complete_db: |
| 615 | + s3_key = f"{file_entry['project_id']}/{file_entry['node_id']}/{file_entry['filename']}" |
| 616 | + s3_client.remove_objects(BUCKET_NAME, [s3_key]) |
| 617 | + expected_removed_files.append(s3_key) |
| 618 | + |
| 619 | + # the list should now contain the removed entries |
| 620 | + list_changes: Dict[str, Any] = await dsm_fixture.synchronise_meta_data_table( |
| 621 | + location=SIMCORE_S3_STR, dry_run=True |
| 622 | + ) |
| 623 | + assert "removed" in list_changes |
| 624 | + assert list_changes["removed"] == expected_removed_files |
| 625 | + |
| 626 | + # now effectively call the function should really remove the files |
| 627 | + list_changes: Dict[str, Any] = await dsm_fixture.synchronise_meta_data_table( |
| 628 | + location=SIMCORE_S3_STR, dry_run=False |
| 629 | + ) |
| 630 | + # listing again will show an empty list again |
| 631 | + list_changes: Dict[str, Any] = await dsm_fixture.synchronise_meta_data_table( |
| 632 | + location=SIMCORE_S3_STR, dry_run=True |
| 633 | + ) |
| 634 | + assert "removed" in list_changes |
| 635 | + assert list_changes["removed"] == [] |
| 636 | + |
| 637 | + |
595 | 638 | @pytest.mark.skipif(not has_datcore_tokens(), reason="no datcore tokens") |
596 | 639 | async def test_dsm_list_datasets_datcore(dsm_fixture, datcore_structured_testbucket): |
597 | 640 | datasets = await dsm_fixture.list_datasets(user_id=USER_ID, location=DATCORE_STR) |
|
0 commit comments