diff --git a/swh/model/model.py b/swh/model/model.py --- a/swh/model/model.py +++ b/swh/model/model.py @@ -384,6 +384,10 @@ raise ValueError('{} is not a valid hash name.'.format(hash_name)) return getattr(self, hash_name) + def hashes(self) -> Dict[str, bytes]: + """Returns a dictionary {hash_name: hash_value}""" + return {algo: getattr(self, algo) for algo in DEFAULT_ALGORITHMS} + @attr.s(frozen=True) class Content(BaseContent): diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py --- a/swh/model/tests/test_model.py +++ b/swh/model/tests/test_model.py @@ -62,6 +62,13 @@ assert c.get_hash(hash_name) == hash_ +def test_content_hashes(): + hashes = dict( + sha1=b'foo', sha1_git=b'bar', sha256=b'baz', blake2s256=b'qux') + c = Content(length=42, status='visible', **hashes) + assert c.hashes() == hashes + + def test_directory_model_id_computation(): dir_dict = dict(directory_example) del dir_dict['id']