Skip to content
Snippets Groups Projects
Commit 0547a516 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

identifiers: Add to_dict method to SWHID class

parent 52ef52ea
No related branches found
Tags v0.0.67
1 merge request!287identifiers: Add to_dict method to SWHID class
......@@ -723,6 +723,9 @@ class SWHID:
def check_object_id(self, attribute, value):
validate_sha1(value) # can raise if invalid hash
def to_dict(self) -> Dict[str, Any]:
return attr.asdict(self)
def __str__(self) -> str:
o = _object_type_map.get(self.object_type)
assert o
......@@ -856,4 +859,4 @@ def parse_persistent_identifier(persistent_id: str) -> PersistentId:
.. deprecated:: 0.3.8
Use :func:`swh.model.identifiers.parse_swhid` instead
"""
return PersistentId(**attr.asdict(parse_swhid(persistent_id)))
return PersistentId(**parse_swhid(persistent_id).to_dict())
......@@ -915,6 +915,16 @@ class SnapshotIdentifier(unittest.TestCase):
)
actual_result = identifiers.parse_swhid(swhid)
self.assertEqual(actual_result, expected_result)
self.assertEqual(
expected_result.to_dict(),
{
"namespace": "swh",
"scheme_version": _version,
"object_type": _type,
"object_id": _hash,
"metadata": _metadata,
},
)
def test_parse_swhid_parsing_error(self):
for swhid in [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment