Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/test_backend.py
Show All 35 Lines | |||||
def assertTimestampAlmostNow(ts, tolerance_secs=1.0): # noqa | def assertTimestampAlmostNow(ts, tolerance_secs=1.0): # noqa | ||||
now = datetime.datetime.now(datetime.timezone.utc) | now = datetime.datetime.now(datetime.timezone.utc) | ||||
creation_delta_secs = (ts - now).total_seconds() | creation_delta_secs = (ts - now).total_seconds() | ||||
assert creation_delta_secs < tolerance_secs | assert creation_delta_secs < tolerance_secs | ||||
def fake_cook(backend, obj_type, result_content, sticky=False): | def fake_cook(backend, bundle_type, result_content, sticky=False): | ||||
content, obj_id = hash_content(result_content) | content, obj_id = hash_content(result_content) | ||||
with mock_cooking(backend): | with mock_cooking(backend): | ||||
backend.create_task(obj_type, obj_id, sticky) | backend.create_task(bundle_type, obj_id, sticky) | ||||
backend.cache.add(obj_type, obj_id, b"content") | backend.cache.add(bundle_type, obj_id, b"content") | ||||
backend.set_status(obj_type, obj_id, "done") | backend.set_status(bundle_type, obj_id, "done") | ||||
return obj_id, content | return obj_id, content | ||||
def fail_cook(backend, obj_type, obj_id, failure_reason): | def fail_cook(backend, bundle_type, obj_id, failure_reason): | ||||
with mock_cooking(backend): | with mock_cooking(backend): | ||||
backend.create_task(obj_type, obj_id) | backend.create_task(bundle_type, obj_id) | ||||
backend.set_status(obj_type, obj_id, "failed") | backend.set_status(bundle_type, obj_id, "failed") | ||||
backend.set_progress(obj_type, obj_id, failure_reason) | backend.set_progress(bundle_type, obj_id, failure_reason) | ||||
TEST_TYPE = "revision_gitfast" | TEST_TYPE = "revision_gitfast" | ||||
TEST_HEX_ID = "4a4b9771542143cf070386f86b4b92d42966bdbc" | TEST_HEX_ID = "4a4b9771542143cf070386f86b4b92d42966bdbc" | ||||
TEST_OBJ_ID = hashutil.hash_to_bytes(TEST_HEX_ID) | TEST_OBJ_ID = hashutil.hash_to_bytes(TEST_HEX_ID) | ||||
TEST_PROGRESS = ( | TEST_PROGRESS = ( | ||||
"Mr. White, You're telling me you're cooking again?" " \N{ASTONISHED FACE} " | "Mr. White, You're telling me you're cooking again?" " \N{ASTONISHED FACE} " | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 288 Lines • Show Last 20 Lines |