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 attr | |||||
import copy | import copy | ||||
from hypothesis import given | from hypothesis import given | ||||
from swh.model.model import Content | from swh.model.model import Content | ||||
from swh.model.hypothesis_strategies import objects, origins, origin_visits | from swh.model.hypothesis_strategies import objects, origins, origin_visits | ||||
Show All 25 Lines | def test_todict_origins(origin): | ||||
assert type(origin)(url=origin.url) == type(origin).from_dict(obj) | assert type(origin)(url=origin.url) == type(origin).from_dict(obj) | ||||
@given(origin_visits()) | @given(origin_visits()) | ||||
def test_todict_origin_visits(origin_visit): | def test_todict_origin_visits(origin_visit): | ||||
obj = origin_visit.to_dict() | obj = origin_visit.to_dict() | ||||
assert 'type' not in obj['origin'] | assert 'type' not in obj['origin'] | ||||
origin_visit.origin.type = None | origin2 = attr.evolve(origin_visit.origin, type=None) | ||||
assert origin_visit == type(origin_visit).from_dict(obj) | origin_visit2 = attr.evolve(origin_visit, origin=origin2) | ||||
assert origin_visit2 == type(origin_visit).from_dict(obj) | |||||
def test_content_get_hash(): | def test_content_get_hash(): | ||||
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) | ||||
for (hash_name, hash_) in hashes.items(): | for (hash_name, hash_) in hashes.items(): | ||||
assert c.get_hash(hash_name) == hash_ | assert c.get_hash(hash_name) == hash_ |