swh_storage = <swh.storage.storage.Storage object at 0x7f5a00f19f98>
def test_check_snapshot_failures(swh_storage):
"""Failure scenarios:
0. snapshot parameter is not a snapshot
1. snapshot id is correct but branches mismatched
2. snapshot id is not correct, it's not found in the storage
3. snapshot reference an alias which does not exist
4. snapshot is found in storage, targeted revision does not exist
5. snapshot is found in storage, targeted revision exists but the directory the
revision targets does not exist
6. snapshot is found in storage, target revision exists, targeted directory by the
revision exist. Content targeted by the directory does not exist.
7. snapshot is found in storage, targeted release does not exist
"""
snap_id_hex = "2498dbf535f882bc7f9a18fb16c9ad27fda7bab7"
snapshot = Snapshot(
id=hash_to_bytes(snap_id_hex),
branches={
b"master": SnapshotBranch(
target=hash_to_bytes(hash_hex), target_type=TargetType.REVISION,
),
},
)
s = swh_storage.snapshot_add([snapshot])
assert s == {
"snapshot:add": 1,
}
unexpected_snapshot = Snapshot(
branches={
b"tip": SnapshotBranch( # wrong branch
target=hash_to_bytes(hash_hex), target_type=TargetType.RELEASE
)
},
)
# 0. not a Snapshot object, raise!
with pytest.raises(AssertionError, match="variable 'snapshot' must be a snapshot"):
check_snapshot(ORIGIN_VISIT, swh_storage)
# 1. snapshot id is correct but branches mismatched
with pytest.raises(AssertionError): # sadly debian build raises only assertion
check_snapshot(attr.evolve(unexpected_snapshot, id=snapshot.id), swh_storage)
# 2. snapshot id is not correct, it's not found in the storage
wrong_snap_id = hash_to_bytes("999666f535f882bc7f9a18fb16c9ad27fda7bab7")
with pytest.raises(AssertionError, match="is not found"):
> check_snapshot(attr.evolve(unexpected_snapshot, id=wrong_snap_id), swh_storage)
.tox/py3/lib/python3.7/site-packages/swh/loader/tests/test_init.py:405:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/loader/tests/__init__.py:142: in check_snapshot
snapshot_dict = storage.snapshot_get(snapshot.id)
.tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:24: in d
return f(*a, **kw)
.tox/py3/lib/python3.7/site-packages/swh/core/db/common.py:62: in _meth
return meth(self, *args, db=db, cur=cur, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <swh.storage.storage.Storage object at 0x7f5a00f19f98>
snapshot_id = b"\x99\x96f\xf55\xf8\x82\xbc\x7f\x9a\x18\xfb\x16\xc9\xad'\xfd\xa7\xba\xb7"
db = <swh.storage.db.Db object at 0x7f5a00f196d8>
cur = <cursor object at 0x7f5a01e00dd8; closed: -1>
@timed
@db_transaction(statement_timeout=2000)
def snapshot_get(
self, snapshot_id: Sha1Git, db=None, cur=None
) -> Optional[Dict[str, Any]]:
d = self.snapshot_get_branches(snapshot_id)
return {
> "id": d["id"],
"branches": {
name: branch.to_dict() if branch else None
for (name, branch) in d["branches"].items()
},
"next_branch": d["next_branch"],
}
E TypeError: 'NoneType' object is not subscriptable
.tox/py3/lib/python3.7/site-packages/swh/storage/storage.py:748: TypeError
TEST RESULT
TEST RESULT
- Run At
- Aug 7 2020, 9:32 PM