Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/utils.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2018 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 abc | import abc | ||||
import datetime | import datetime | ||||
import hashlib | |||||
import random | import random | ||||
from hypothesis import strategies | from hypothesis import strategies | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.hashutil import hash_to_bytes, hash_to_hex | from swh.model.hashutil import hash_to_bytes, hash_to_hex | ||||
from swh.indexer.storage import INDEXER_CFG_KEY | from swh.indexer.storage import INDEXER_CFG_KEY | ||||
▲ Show 20 Lines • Show All 459 Lines • ▼ Show 20 Lines | for (orig_pseudo_id, snap) in SNAPSHOTS.items(): | ||||
'branches': snap['branches'] | 'branches': snap['branches'] | ||||
}) | }) | ||||
storage.revision_add(REVISIONS) | storage.revision_add(REVISIONS) | ||||
storage.directory_add([{ | storage.directory_add([{ | ||||
'id': DIRECTORY_ID, | 'id': DIRECTORY_ID, | ||||
'entries': DIRECTORY, | 'entries': DIRECTORY, | ||||
}]) | }]) | ||||
for (obj_id, content) in OBJ_STORAGE_DATA.items(): | for (obj_id, content) in OBJ_STORAGE_DATA.items(): | ||||
# TODO: use MultiHash | content_hashes = hashutil.MultiHash.from_data(content).digest() | ||||
if hasattr(hashlib, 'blake2s'): | |||||
blake2s256 = hashlib.blake2s(content, digest_size=32).digest() | |||||
else: | |||||
# fallback for Python <3.6 | |||||
blake2s256 = bytes([random.randint(0, 255) for _ in range(32)]) | |||||
storage.content_add([{ | storage.content_add([{ | ||||
'data': content, | 'data': content, | ||||
'length': len(content), | 'length': len(content), | ||||
'status': 'visible', | 'status': 'visible', | ||||
'sha1': hash_to_bytes(obj_id), | 'sha1': hash_to_bytes(obj_id), | ||||
'sha1_git': hash_to_bytes(obj_id), | 'sha1_git': hash_to_bytes(obj_id), | ||||
'sha256': hashlib.sha256(content).digest(), | 'sha256': content_hashes['sha256'], | ||||
'blake2s256': blake2s256 | 'blake2s256': content_hashes['blake2s256'] | ||||
}]) | }]) | ||||
class CommonContentIndexerTest(metaclass=abc.ABCMeta): | class CommonContentIndexerTest(metaclass=abc.ABCMeta): | ||||
legacy_get_format = False | legacy_get_format = False | ||||
"""True if and only if the tested indexer uses the legacy format. | """True if and only if the tested indexer uses the legacy format. | ||||
see: https://forge.softwareheritage.org/T1433 | see: https://forge.softwareheritage.org/T1433 | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |