Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9696411
D2958.id11446.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D2958.id11446.diff
View Options
diff --git a/swh/web/client/__init__.py b/swh/web/client/__init__.py
--- a/swh/web/client/__init__.py
+++ b/swh/web/client/__init__.py
@@ -1 +1 @@
-from .client import WebAPIClient # NoQA: F401
+from .client import WebAPIClient, typify # NoQA: F401
diff --git a/swh/web/client/client.py b/swh/web/client/client.py
--- a/swh/web/client/client.py
+++ b/swh/web/client/client.py
@@ -67,7 +67,10 @@
def to_pid(object_type, s):
return PID(object_type=object_type, object_id=s)
- def to_date(s):
+ # The date attribute is optional for Revision and Release object
+ def to_date(s: Optional[str], optional: Optional[bool] = False) -> datetime:
+ if optional and s is None:
+ return None
return dateutil.parser.parse(s)
def obj_type_of_entry_type(s):
@@ -89,12 +92,12 @@
data["id"] = to_pid(obj_type, data["id"])
data["directory"] = to_pid(DIRECTORY, data["directory"])
for key in ("date", "committer_date"):
- data[key] = to_date(data[key])
+ data[key] = to_date(data[key], optional=True)
for parent in data["parents"]:
parent["id"] = to_pid(REVISION, parent["id"])
elif obj_type == RELEASE:
data["id"] = to_pid(obj_type, data["id"])
- data["date"] = to_date(data["date"])
+ data["date"] = to_date(data["date"], optional=True)
data["target"] = to_pid(data["target_type"], data["target"])
elif obj_type == DIRECTORY:
dir_pid = None
diff --git a/swh/web/client/tests/test_web_api_client.py b/swh/web/client/tests/test_web_api_client.py
--- a/swh/web/client/tests/test_web_api_client.py
+++ b/swh/web/client/tests/test_web_api_client.py
@@ -10,6 +10,9 @@
import pytest
+from swh.model.identifiers import REVISION
+
+from swh.web.client import typify
from swh.web.client.auth import AuthenticationError
from swh.model.identifiers import parse_persistent_identifier as parse_pid
@@ -220,3 +223,17 @@
assert visits[0]["snapshot"] is None
snapshot_pid = 'swh:1:snp:456550ea74af4e2eecaa406629efaaf0b9b5f976'
assert visits[7]["snapshot"] == parse_pid(snapshot_pid)
+
+
+def test_typify_minimal_revision():
+ revision_data = {
+ 'id': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+ 'directory': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+ 'date': None,
+ 'committer_date': None,
+ 'parents': []
+ }
+ revision_typed = typify(revision_data, REVISION)
+ pid = "swh:1:rev:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ assert revision_typed['id'] == parse_pid(pid)
+ assert revision_typed['date'] is None
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 17, 8:01 PM (1 w, 16 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221595
Attached To
D2958: client: support optional date in Revision and Release
Event Timeline
Log In to Comment