Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/data.py
Show All 20 Lines | |||||
from swh.loader.git.from_disk import GitLoaderFromArchive | from swh.loader.git.from_disk import GitLoaderFromArchive | ||||
from swh.model.hashutil import DEFAULT_ALGORITHMS, hash_to_hex | from swh.model.hashutil import DEFAULT_ALGORITHMS, hash_to_hex | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Content, | Content, | ||||
Directory, | Directory, | ||||
Origin, | Origin, | ||||
OriginVisit, | OriginVisit, | ||||
OriginVisitStatus, | OriginVisitStatus, | ||||
Sha1Git, | |||||
Snapshot, | Snapshot, | ||||
) | ) | ||||
from swh.model.swhids import CoreSWHID, ObjectType, QualifiedSWHID | from swh.model.swhids import CoreSWHID, ObjectType, QualifiedSWHID | ||||
from swh.search import get_search | from swh.search import get_search | ||||
from swh.storage import get_storage | from swh.storage import get_storage | ||||
from swh.storage.algos.dir_iterators import dir_iterator | from swh.storage.algos.dir_iterators import dir_iterator | ||||
from swh.storage.algos.snapshot import snapshot_get_latest | from swh.storage.algos.snapshot import snapshot_get_latest | ||||
from swh.storage.interface import Sha1 | from swh.storage.interface import Sha1 | ||||
Show All 17 Lines | _TEST_INDEXER_BASE_CONFIG = { | ||||
}, | }, | ||||
"indexer_storage": { | "indexer_storage": { | ||||
"cls": "memory", | "cls": "memory", | ||||
"args": {}, | "args": {}, | ||||
}, | }, | ||||
} | } | ||||
def random_sha1(): | def random_sha1_packed() -> Sha1Git: | ||||
return hash_to_hex(bytes(random.randint(0, 255) for _ in range(20))) | return bytes(random.randint(0, 255) for _ in range(20)) | ||||
def random_sha256(): | def random_sha1() -> str: | ||||
return hash_to_hex(random_sha1_packed()) | |||||
def random_sha256() -> str: | |||||
return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) | return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) | ||||
def random_blake2s256(): | def random_blake2s256() -> str: | ||||
return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) | return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) | ||||
def random_object_type() -> ObjectType: | |||||
return random.choice( | |||||
[ | |||||
ObjectType.CONTENT, | |||||
ObjectType.DIRECTORY, | |||||
ObjectType.REVISION, | |||||
ObjectType.RELEASE, | |||||
ObjectType.SNAPSHOT, | |||||
vlorentz: this is dead code now | |||||
Done Inline ActionsSure. I misinterpreted you before thinking it would be good ot have anyways. Will remove. Ericson2314: Sure. I misinterpreted you before thinking it would be good ot have anyways. Will remove. | |||||
] | |||||
) | |||||
def random_swhid() -> CoreSWHID: | |||||
return CoreSWHID( | |||||
object_type=random_object_type(), | |||||
object_id=random_sha1_packed(), | |||||
) | |||||
def random_content(): | def random_content(): | ||||
return { | return { | ||||
"sha1": random_sha1(), | "sha1": random_sha1(), | ||||
"sha1_git": random_sha1(), | "sha1_git": random_sha1(), | ||||
"sha256": random_sha256(), | "sha256": random_sha256(), | ||||
"blake2s256": random_blake2s256(), | "blake2s256": random_blake2s256(), | ||||
} | } | ||||
▲ Show 20 Lines • Show All 473 Lines • Show Last 20 Lines |
this is dead code now