diff --git a/PKG-INFO b/PKG-INFO index 5f502f918fd66bc348e587d820162e76bbe76daf..953d410becc8cea925c44c425a7975adf99615b2 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: swh.model -Version: 0.6.5 +Version: 0.6.6 Summary: Software Heritage data model Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Author: Software Heritage developers diff --git a/swh.model.egg-info/PKG-INFO b/swh.model.egg-info/PKG-INFO index 5f502f918fd66bc348e587d820162e76bbe76daf..953d410becc8cea925c44c425a7975adf99615b2 100644 --- a/swh.model.egg-info/PKG-INFO +++ b/swh.model.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: swh.model -Version: 0.6.5 +Version: 0.6.6 Summary: Software Heritage data model Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Author: Software Heritage developers diff --git a/swh/model/model.py b/swh/model/model.py index dd73bf99b6a8f52aca76cee43028f1ebf4e9d424..c1c20a55e8c39d1336c8e82521702087570063bd 100644 --- a/swh/model/model.py +++ b/swh/model/model.py @@ -40,6 +40,7 @@ SHA1_SIZE = 20 # TODO: Limit this to 20 bytes Sha1Git = bytes +Sha1 = bytes KT = TypeVar("KT") @@ -624,6 +625,8 @@ class Content(BaseContent): content = super().to_dict() if content["data"] is None: del content["data"] + if content["ctime"] is None: + del content["ctime"] return content @classmethod @@ -696,6 +699,8 @@ class SkippedContent(BaseContent): content = super().to_dict() if content["origin"] is None: del content["origin"] + if content["ctime"] is None: + del content["ctime"] return content @classmethod diff --git a/swh/model/tests/test_hypothesis_strategies.py b/swh/model/tests/test_hypothesis_strategies.py index 7493c480983b3ee4394b9299e42ec497c1f700aa..e1ab9b73aae2cfa48b137cd26d14ed1a29a6359c 100644 --- a/swh/model/tests/test_hypothesis_strategies.py +++ b/swh/model/tests/test_hypothesis_strategies.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019 The Software Heritage developers +# Copyright (C) 2019-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -123,11 +123,15 @@ def test_dicts_generation_blacklist(obj_type_and_obj): @given(objects()) def test_model_to_dicts(obj_type_and_obj): - (obj_type, object_) = obj_type_and_obj + _, object_ = obj_type_and_obj + object_type = object_.object_type obj_dict = object_.to_dict() assert_nested_dict(obj_dict) - if obj_type == "content": - COMMON_KEYS = set(DEFAULT_ALGORITHMS) | {"length", "status", "ctime"} + if object_type in ("content", "skipped_content"): + COMMON_KEYS = set(DEFAULT_ALGORITHMS) | {"length", "status"} + if object_.ctime is not None: + COMMON_KEYS |= {"ctime"} + if obj_dict["status"] == "visible": assert set(obj_dict) == COMMON_KEYS | {"data"} elif obj_dict["status"] == "absent": @@ -136,9 +140,9 @@ def test_model_to_dicts(obj_type_and_obj): assert set(obj_dict) == COMMON_KEYS | {"data"} else: assert False, obj_dict - elif obj_type == "release": + elif object_type == "release": assert obj_dict["target_type"] in target_types - elif obj_type == "snapshot": + elif object_type == "snapshot": for branch in obj_dict["branches"].values(): assert branch is None or branch["target_type"] in target_types