Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asyncio Listing and Inventory Report Integration #573

Merged
merged 18 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gcsfs/inventory_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def _validate_inventory_report_info(inventory_report_info):
ValueError: If any required key (use_snapshot_listing, location, id)
is missing from the inventory_report_info dictionary.
"""
pass
if "use_snapshot_listing" not in inventory_report_info:
raise ValueError("Use snapshot listing is not configured.")
if "location" not in inventory_report_info:
raise ValueError("Inventory report location is not configured.")
if "id" not in inventory_report_info:
raise ValueError("Inventory report id is not configured.")

async def _fetch_raw_inventory_report_config(gcs_file_system, location, id):
"""
Expand Down
35 changes: 35 additions & 0 deletions gcsfs/tests/test_inventory_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
from gcsfs.inventory_report import InventoryReport

class TestInventoryReport(object):
"""
Unit tests for the inventory report logic, see 'inventory_report.py'.

The test cases follow the same ordering as the methods in `inventory.report.py`.
Each method is covered by either one or more parametrized test cases. Some
methods include a setup method just above them.
"""

@pytest.mark.parametrize("inventory_report_info, expected_error", [
# Check whether missing inventory report info will raise exception.
({"location": "us-west", "id": "123"}, \
"Use snapshot listing is not configured."),
({"use_snapshot_listing": True, "id": "123"}, \
"Inventory report location is not configured."),
# Check complete inventory report infor will not raise exception.
hanseaston marked this conversation as resolved.
Show resolved Hide resolved
({"use_snapshot_listing": True, "location": "us-west"}, \
"Inventory report id is not configured."),
({"use_snapshot_listing": True, "location": "us-west", "id": "123"}, None),
])
def test_validate_inventory_report_info(
self, inventory_report_info, expected_error):
if expected_error is not None:
with pytest.raises(ValueError) as e_info:
InventoryReport._validate_inventory_report_info(
inventory_report_info=inventory_report_info)
assert str(e_info.value) == expected_error
else:
# If no error is expected, we simply call the function
# to ensure no exception is raised.
InventoryReport._validate_inventory_report_info(
inventory_report_info=inventory_report_info)