Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/deposit/tests/test_deposit.py
Show All 10 Lines | |||||
from swh.model.hashutil import hash_to_bytes, hash_to_hex | from swh.model.hashutil import hash_to_bytes, hash_to_hex | ||||
from swh.loader.package.deposit.loader import DepositLoader | from swh.loader.package.deposit.loader import DepositLoader | ||||
from swh.loader.package.tests.common import ( | from swh.loader.package.tests.common import ( | ||||
check_snapshot, | check_snapshot, | ||||
check_metadata_paths, | check_metadata_paths, | ||||
get_stats, | get_stats, | ||||
) | ) | ||||
from swh.loader.tests.common import assert_last_visit_matches | |||||
from swh.core.pytest_plugin import requests_mock_datadir_factory | from swh.core.pytest_plugin import requests_mock_datadir_factory | ||||
DEPOSIT_URL = "https://deposit.softwareheritage.org/1/private" | DEPOSIT_URL = "https://deposit.softwareheritage.org/1/private" | ||||
@pytest.fixture | @pytest.fixture | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | ): | ||||
url = "some-url-2" | url = "some-url-2" | ||||
deposit_id = 666 | deposit_id = 666 | ||||
loader = DepositLoader(url, deposit_id) | loader = DepositLoader(url, deposit_id) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
assert actual_load_status["status"] == "uneventful" | assert actual_load_status["status"] == "uneventful" | ||||
assert actual_load_status["snapshot_id"] is not None | assert actual_load_status["snapshot_id"] is not None | ||||
assert_last_visit_matches(loader.storage, url, status="partial", type="deposit") | |||||
stats = get_stats(loader.storage) | stats = get_stats(loader.storage) | ||||
assert { | assert { | ||||
"content": 0, | "content": 0, | ||||
"directory": 0, | "directory": 0, | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"person": 0, | "person": 0, | ||||
"release": 0, | "release": 0, | ||||
"revision": 0, | "revision": 0, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} == stats | } == stats | ||||
origin_visit = loader.storage.origin_visit_get_latest(url) | |||||
assert origin_visit["status"] == "partial" | |||||
assert origin_visit["type"] == "deposit" | |||||
def test_revision_metadata_structure(swh_config, requests_mock_datadir): | def test_revision_metadata_structure(swh_config, requests_mock_datadir): | ||||
url = "https://hal-test.archives-ouvertes.fr/some-external-id" | url = "https://hal-test.archives-ouvertes.fr/some-external-id" | ||||
deposit_id = 666 | deposit_id = 666 | ||||
loader = DepositLoader(url, deposit_id) | loader = DepositLoader(url, deposit_id) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
assert actual_load_status["status"] == "eventful" | assert actual_load_status["status"] == "eventful" | ||||
Show All 30 Lines | def test_deposit_loading_ok(swh_config, requests_mock_datadir): | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "b2b327b33dc85818bd23c3ccda8b7e675a66ecbd" | expected_snapshot_id = "b2b327b33dc85818bd23c3ccda8b7e675a66ecbd" | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id, | "snapshot_id": expected_snapshot_id, | ||||
} | } | ||||
assert_last_visit_matches(loader.storage, url, status="full", type="deposit") | |||||
stats = get_stats(loader.storage) | stats = get_stats(loader.storage) | ||||
assert { | assert { | ||||
"content": 303, | "content": 303, | ||||
"directory": 12, | "directory": 12, | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"person": 1, | "person": 1, | ||||
"release": 0, | "release": 0, | ||||
"revision": 1, | "revision": 1, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} == stats | } == stats | ||||
origin_visit = loader.storage.origin_visit_get_latest(url) | |||||
assert origin_visit["status"] == "full" | |||||
assert origin_visit["type"] == "deposit" | |||||
revision_id = "637318680351f5d78856d13264faebbd91efe9bb" | revision_id = "637318680351f5d78856d13264faebbd91efe9bb" | ||||
expected_branches = { | expected_branches = { | ||||
"HEAD": {"target": revision_id, "target_type": "revision",}, | "HEAD": {"target": revision_id, "target_type": "revision",}, | ||||
} | } | ||||
expected_snapshot = { | expected_snapshot = { | ||||
"id": expected_snapshot_id, | "id": expected_snapshot_id, | ||||
"branches": expected_branches, | "branches": expected_branches, | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | def test_deposit_loading_ok_2(swh_config, requests_mock_datadir): | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "3e68440fdd7c81d283f8f3aebb6f0c8657864192" | expected_snapshot_id = "3e68440fdd7c81d283f8f3aebb6f0c8657864192" | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id, | "snapshot_id": expected_snapshot_id, | ||||
} | } | ||||
assert_last_visit_matches(loader.storage, url, status="full", type="deposit") | |||||
revision_id = "564d18943d71be80d0d73b43a77cfb205bcde96c" | revision_id = "564d18943d71be80d0d73b43a77cfb205bcde96c" | ||||
expected_branches = {"HEAD": {"target": revision_id, "target_type": "revision"}} | expected_branches = {"HEAD": {"target": revision_id, "target_type": "revision"}} | ||||
expected_snapshot = { | expected_snapshot = { | ||||
"id": expected_snapshot_id, | "id": expected_snapshot_id, | ||||
"branches": expected_branches, | "branches": expected_branches, | ||||
} | } | ||||
check_snapshot(expected_snapshot, storage=loader.storage) | check_snapshot(expected_snapshot, storage=loader.storage) | ||||
origin_visit = loader.storage.origin_visit_get_latest(url) | |||||
# The visit is partial because some hash collision were detected | |||||
assert origin_visit["status"] == "full" | |||||
assert origin_visit["type"] == "deposit" | |||||
raw_meta = loader.client.metadata_get(deposit_id) | raw_meta = loader.client.metadata_get(deposit_id) | ||||
# Ensure the date fields are set appropriately in the revision | # Ensure the date fields are set appropriately in the revision | ||||
# Retrieve the revision | # Retrieve the revision | ||||
revision = next(loader.storage.revision_get([hash_to_bytes(revision_id)])) | revision = next(loader.storage.revision_get([hash_to_bytes(revision_id)])) | ||||
assert revision | assert revision | ||||
assert revision["date"] == raw_meta["deposit"]["author_date"] | assert revision["date"] == raw_meta["deposit"]["author_date"] | ||||
assert revision["committer_date"] == raw_meta["deposit"]["committer_date"] | assert revision["committer_date"] == raw_meta["deposit"]["committer_date"] | ||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |