Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/test_cookers_base.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import textwrap | |||||
from unittest.mock import MagicMock | from unittest.mock import MagicMock | ||||
from swh.model.identifiers import CoreSWHID | from swh.model.identifiers import CoreSWHID | ||||
from swh.vault.cookers.base import BaseVaultCooker | from swh.vault.cookers.base import BaseVaultCooker | ||||
TEST_BUNDLE_CHUNKS = [b"test content 1\n", b"test content 2\n", b"test content 3\n"] | TEST_BUNDLE_CHUNKS = [b"test content 1\n", b"test content 2\n", b"test content 3\n"] | ||||
TEST_BUNDLE_CONTENT = b"".join(TEST_BUNDLE_CHUNKS) | TEST_BUNDLE_CONTENT = b"".join(TEST_BUNDLE_CHUNKS) | ||||
TEST_BUNDLE_TYPE = "test_type" | TEST_BUNDLE_TYPE = "test_type" | ||||
Show All 37 Lines | def test_code_exception_cook(): | ||||
cooker.prepare_bundle = MagicMock() | cooker.prepare_bundle = MagicMock() | ||||
cooker.prepare_bundle.side_effect = RuntimeError("Nope") | cooker.prepare_bundle.side_effect = RuntimeError("Nope") | ||||
cooker.cook() | cooker.cook() | ||||
# Potentially remove this when we have objstorage streaming | # Potentially remove this when we have objstorage streaming | ||||
cooker.backend.put_bundle.assert_not_called() | cooker.backend.put_bundle.assert_not_called() | ||||
cooker.backend.set_status.assert_called_with(TEST_BUNDLE_TYPE, TEST_SWHID, "failed") | cooker.backend.set_status.assert_called_with(TEST_BUNDLE_TYPE, TEST_SWHID, "failed") | ||||
assert "Nope" not in cooker.backend.set_progress.call_args[0][2] | assert cooker.backend.set_progress.call_args[0][2].startswith( | ||||
textwrap.dedent( | |||||
"""\ | |||||
Internal Server Error. This incident will be reported. | |||||
The full error was: | |||||
Traceback (most recent call last): | |||||
""" | |||||
) | |||||
) | |||||
cooker.backend.send_notif.assert_called_with(TEST_BUNDLE_TYPE, TEST_SWHID) | cooker.backend.send_notif.assert_called_with(TEST_BUNDLE_TYPE, TEST_SWHID) | ||||
def test_policy_exception_cook(): | def test_policy_exception_cook(): | ||||
cooker = BaseVaultCookerMock() | cooker = BaseVaultCookerMock() | ||||
cooker.max_bundle_size = 8 | cooker.max_bundle_size = 8 | ||||
cooker.cook() | cooker.cook() | ||||
# Potentially remove this when we have objstorage streaming | # Potentially remove this when we have objstorage streaming | ||||
cooker.backend.put_bundle.assert_not_called() | cooker.backend.put_bundle.assert_not_called() | ||||
cooker.backend.set_status.assert_called_with(TEST_BUNDLE_TYPE, TEST_SWHID, "failed") | cooker.backend.set_status.assert_called_with(TEST_BUNDLE_TYPE, TEST_SWHID, "failed") | ||||
assert "exceeds" in cooker.backend.set_progress.call_args[0][2] | assert "exceeds" in cooker.backend.set_progress.call_args[0][2] | ||||
cooker.backend.send_notif.assert_called_with(TEST_BUNDLE_TYPE, TEST_SWHID) | cooker.backend.send_notif.assert_called_with(TEST_BUNDLE_TYPE, TEST_SWHID) |