Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage_data.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020-2021 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 pytest | |||||
from swh.model.model import BaseModel | from swh.model.model import BaseModel | ||||
from swh.storage.tests.storage_data import StorageData | from swh.storage.tests.storage_data import StorageData | ||||
def test_storage_data(): | def test_storage_data(): | ||||
data = StorageData() | data = StorageData() | ||||
for attribute_key in [ | for attribute_key in [ | ||||
"contents", | "contents", | ||||
"skipped_contents", | "skipped_contents", | ||||
"directories", | "directories", | ||||
"revisions", | "revisions", | ||||
"releases", | "releases", | ||||
"snapshots", | "snapshots", | ||||
"origins", | "origins", | ||||
"origin_visits", | "origin_visits", | ||||
"fetchers", | "fetchers", | ||||
"authorities", | "authorities", | ||||
"origin_metadata", | "origin_metadata", | ||||
"content_metadata", | "content_metadata", | ||||
]: | ]: | ||||
for obj in getattr(data, attribute_key): | for obj in getattr(data, attribute_key): | ||||
assert isinstance(obj, BaseModel) | assert isinstance(obj, BaseModel) | ||||
@pytest.mark.parametrize( | |||||
"collection", | |||||
("directories", "git_revisions", "hg_revisions", "releases", "snapshots"), | |||||
) | |||||
def test_storage_data_hash(collection): | |||||
data = StorageData() | |||||
for obj in getattr(data, collection): | |||||
assert ( | |||||
obj.compute_hash() == obj.id | |||||
), f"{obj.compute_hash().hex()} != {obj.id.hex()}" |