Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/test_cli.py
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def test_cook_unknown_cooker(): | ||||
assert "do not have a gitfast cooker" in result.stdout | assert "do not have a gitfast cooker" in result.stdout | ||||
result = runner.invoke(vault_cli_group, ["cook", "swh:1:rev:" + "0" * 40, "-"]) | result = runner.invoke(vault_cli_group, ["cook", "swh:1:rev:" + "0" * 40, "-"]) | ||||
assert isinstance(result.exception, SystemExit) | assert isinstance(result.exception, SystemExit) | ||||
assert "explicit --cooker-type" in result.stdout | assert "explicit --cooker-type" in result.stdout | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"obj_type,cooker_name_suffix,swhid_type", | "bundle_type,cooker_name_suffix,swhid_type", | ||||
[("directory", "", "dir"), ("revision", "gitfast", "rev"),], | [("directory", "", "dir"), ("revision", "gitfast", "rev"),], | ||||
) | ) | ||||
def test_cook_directory(obj_type, cooker_name_suffix, swhid_type, mocker): | def test_cook_directory(bundle_type, cooker_name_suffix, swhid_type, mocker): | ||||
storage = object() | storage = object() | ||||
mocker.patch("swh.storage.get_storage", return_value=storage) | mocker.patch("swh.storage.get_storage", return_value=storage) | ||||
backend = MagicMock(spec=InMemoryVaultBackend) | backend = MagicMock(spec=InMemoryVaultBackend) | ||||
backend.fetch.return_value = b"bundle content" | backend.fetch.return_value = b"bundle content" | ||||
mocker.patch( | mocker.patch( | ||||
"swh.vault.in_memory_backend.InMemoryVaultBackend", return_value=backend | "swh.vault.in_memory_backend.InMemoryVaultBackend", return_value=backend | ||||
) | ) | ||||
Show All 25 Lines | with tempfile.NamedTemporaryFile("a", suffix=".yml") as config_fd: | ||||
vault_cli_group, | vault_cli_group, | ||||
["cook", f"swh:1:{swhid_type}:{'0'*40}", "-", "-C", config_fd.name], | ["cook", f"swh:1:{swhid_type}:{'0'*40}", "-", "-C", config_fd.name], | ||||
) | ) | ||||
if result.exception is not None: | if result.exception is not None: | ||||
raise result.exception | raise result.exception | ||||
cooker_cls.assert_called_once_with( | cooker_cls.assert_called_once_with( | ||||
obj_type=f"{obj_type}_{cooker_name_suffix}" if cooker_name_suffix else obj_type, | bundle_type=f"{bundle_type}_{cooker_name_suffix}" | ||||
if cooker_name_suffix | |||||
else bundle_type, | |||||
obj_id=b"\x00" * 20, | obj_id=b"\x00" * 20, | ||||
backend=backend, | backend=backend, | ||||
storage=storage, | storage=storage, | ||||
graph=None, | graph=None, | ||||
objstorage=None, | objstorage=None, | ||||
max_bundle_size=None, | max_bundle_size=None, | ||||
) | ) | ||||
cooker.cook.assert_called_once_with() | cooker.cook.assert_called_once_with() | ||||
assert result.stdout_bytes == b"bundle content" | assert result.stdout_bytes == b"bundle content" |