Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/test_cache.py
# Copyright (C) 2017 The Software Heritage developers | # Copyright (C) 2017-2022 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 | ||||
from swh.model import hashutil | |||||
from swh.model.swhids import CoreSWHID | from swh.model.swhids import CoreSWHID | ||||
TEST_TYPE_1 = "revision_gitfast" | TEST_TYPE_1 = "revision_gitfast" | ||||
TEST_TYPE_2 = "directory" | TEST_TYPE_2 = "directory" | ||||
TEST_SWHID_1 = CoreSWHID.from_string( | TEST_SWHID_1 = CoreSWHID.from_string( | ||||
"swh:1:rev:4a4b9771542143cf070386f86b4b92d42966bdbc" | "swh:1:rev:4a4b9771542143cf070386f86b4b92d42966bdbc" | ||||
) | ) | ||||
TEST_SWHID_2 = CoreSWHID.from_string( | TEST_SWHID_2 = CoreSWHID.from_string( | ||||
"swh:1:dir:17a3e48bce37be5226490e750202ad3a9a1a3fe9" | "swh:1:dir:17a3e48bce37be5226490e750202ad3a9a1a3fe9" | ||||
) | ) | ||||
TEST_CONTENT_1 = b"test content 1" | TEST_CONTENT_1 = b"test content 1" | ||||
TEST_CONTENT_2 = b"test content 2" | TEST_CONTENT_2 = b"test content 2" | ||||
# Let's try to avoid replicating edge-cases already tested in | # Let's try to avoid replicating edge-cases already tested in | ||||
# swh-objstorage, and instead focus on testing behaviors specific to the | # swh-objstorage, and instead focus on testing behaviors specific to the | ||||
# Vault cache here. | # Vault cache here. | ||||
def test_internal_id(swh_vault): | def test_internal_id(swh_vault): | ||||
sid = swh_vault.cache._get_internal_id(TEST_TYPE_1, TEST_SWHID_1) | sid = swh_vault.cache._get_internal_id(TEST_TYPE_1, TEST_SWHID_1) | ||||
assert hashutil.hash_to_hex(sid) == "ec2a99d6b21a68648a9d0c99c5d7c35f69268564" | assert sid["sha1"].hex() == "ec2a99d6b21a68648a9d0c99c5d7c35f69268564" | ||||
def test_simple_add_get(swh_vault): | def test_simple_add_get(swh_vault): | ||||
swh_vault.cache.add(TEST_TYPE_1, TEST_SWHID_1, TEST_CONTENT_1) | swh_vault.cache.add(TEST_TYPE_1, TEST_SWHID_1, TEST_CONTENT_1) | ||||
assert swh_vault.cache.get(TEST_TYPE_1, TEST_SWHID_1) == TEST_CONTENT_1 | assert swh_vault.cache.get(TEST_TYPE_1, TEST_SWHID_1) == TEST_CONTENT_1 | ||||
assert swh_vault.cache.is_cached(TEST_TYPE_1, TEST_SWHID_1) | assert swh_vault.cache.is_cached(TEST_TYPE_1, TEST_SWHID_1) | ||||
Show All 25 Lines |