Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_hypothesis_strategies.py
# 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 | # 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 datetime | import datetime | ||||
import attr | import attr | ||||
import iso8601 | import iso8601 | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
@given(object_dicts(blacklist_types=("release", "content"))) | @given(object_dicts(blacklist_types=("release", "content"))) | ||||
def test_dicts_generation_blacklist(obj_type_and_obj): | def test_dicts_generation_blacklist(obj_type_and_obj): | ||||
assert obj_type_and_obj[0] not in ("release", "content") | assert obj_type_and_obj[0] not in ("release", "content") | ||||
@given(objects()) | @given(objects()) | ||||
def test_model_to_dicts(obj_type_and_obj): | 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() | obj_dict = object_.to_dict() | ||||
assert_nested_dict(obj_dict) | assert_nested_dict(obj_dict) | ||||
if obj_type == "content": | if object_type in ("content", "skipped_content"): | ||||
COMMON_KEYS = set(DEFAULT_ALGORITHMS) | {"length", "status", "ctime"} | COMMON_KEYS = set(DEFAULT_ALGORITHMS) | {"length", "status"} | ||||
if object_.ctime is not None: | |||||
COMMON_KEYS |= {"ctime"} | |||||
vlorentz: If we are removing None ctime keys for contents, we should do it for skipped_contents too. | |||||
Done Inline Actionsi was wondering. ardumont: i was wondering.
ack. | |||||
if obj_dict["status"] == "visible": | if obj_dict["status"] == "visible": | ||||
assert set(obj_dict) == COMMON_KEYS | {"data"} | assert set(obj_dict) == COMMON_KEYS | {"data"} | ||||
elif obj_dict["status"] == "absent": | elif obj_dict["status"] == "absent": | ||||
assert set(obj_dict) == COMMON_KEYS | {"reason"} | assert set(obj_dict) == COMMON_KEYS | {"reason"} | ||||
elif obj_dict["status"] == "hidden": | elif obj_dict["status"] == "hidden": | ||||
assert set(obj_dict) == COMMON_KEYS | {"data"} | assert set(obj_dict) == COMMON_KEYS | {"data"} | ||||
else: | else: | ||||
assert False, obj_dict | assert False, obj_dict | ||||
elif obj_type == "release": | elif object_type == "release": | ||||
assert obj_dict["target_type"] in target_types | assert obj_dict["target_type"] in target_types | ||||
elif obj_type == "snapshot": | elif object_type == "snapshot": | ||||
for branch in obj_dict["branches"].values(): | for branch in obj_dict["branches"].values(): | ||||
assert branch is None or branch["target_type"] in target_types | assert branch is None or branch["target_type"] in target_types | ||||
@given(contents()) | @given(contents()) | ||||
def test_content_aware_datetime(cont): | def test_content_aware_datetime(cont): | ||||
assert cont.ctime is None or cont.ctime.tzinfo is not None | assert cont.ctime is None or cont.ctime.tzinfo is not None | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |
If we are removing None ctime keys for contents, we should do it for skipped_contents too.