Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_model.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 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 copy | import copy | ||||
from hypothesis import given | from hypothesis import given | ||||
import pytest | |||||
from swh.model.model import Content, Directory, Revision, Release, Snapshot | from swh.model.model import Content, Directory, Revision, Release, Snapshot | ||||
from swh.model.model import MissingData | |||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.hypothesis_strategies import objects, origins, origin_visits | from swh.model.hypothesis_strategies import objects, origins, origin_visits | ||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | ||||
directory_identifier, revision_identifier, release_identifier, | directory_identifier, revision_identifier, release_identifier, | ||||
snapshot_identifier | snapshot_identifier | ||||
) | ) | ||||
from swh.model.tests.test_identifiers import ( | from swh.model.tests.test_identifiers import ( | ||||
directory_example, revision_example, release_example, snapshot_example | directory_example, revision_example, release_example, snapshot_example | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
def test_content_hashes(): | def test_content_hashes(): | ||||
hashes = dict( | hashes = dict( | ||||
sha1=b'foo', sha1_git=b'bar', sha256=b'baz', blake2s256=b'qux') | sha1=b'foo', sha1_git=b'bar', sha256=b'baz', blake2s256=b'qux') | ||||
c = Content(length=42, status='visible', **hashes) | c = Content(length=42, status='visible', **hashes) | ||||
assert c.hashes() == hashes | assert c.hashes() == hashes | ||||
def test_content_data(): | |||||
c = Content( | |||||
length=42, status='visible', data=b'foo', | |||||
sha1=b'foo', sha1_git=b'bar', sha256=b'baz', blake2s256=b'qux') | |||||
assert c.with_data() == c | |||||
def test_content_data_missing(): | |||||
c = Content( | |||||
length=42, status='visible', | |||||
sha1=b'foo', sha1_git=b'bar', sha256=b'baz', blake2s256=b'qux') | |||||
with pytest.raises(MissingData): | |||||
c.with_data() | |||||
def test_directory_model_id_computation(): | def test_directory_model_id_computation(): | ||||
dir_dict = dict(directory_example) | dir_dict = dict(directory_example) | ||||
del dir_dict['id'] | del dir_dict['id'] | ||||
dir_id = hash_to_bytes(directory_identifier(dir_dict)) | dir_id = hash_to_bytes(directory_identifier(dir_dict)) | ||||
for dir_model in [Directory(**dir_dict), Directory.from_dict(dir_dict)]: | for dir_model in [Directory(**dir_dict), Directory.from_dict(dir_dict)]: | ||||
assert dir_model.id == dir_id | assert dir_model.id == dir_id | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |