Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_model.py
Show All 39 Lines | from swh.model.model import ( | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
Release, | Release, | ||||
Revision, | Revision, | ||||
SkippedContent, | SkippedContent, | ||||
Snapshot, | Snapshot, | ||||
Timestamp, | Timestamp, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
from swh.model.tests.swh_model_data import TEST_OBJECTS | |||||
from swh.model.tests.test_identifiers import ( | from swh.model.tests.test_identifiers import ( | ||||
content_example, | content_example, | ||||
directory_example, | directory_example, | ||||
metadata_example, | metadata_example, | ||||
origin_example, | origin_example, | ||||
release_example, | release_example, | ||||
revision_example, | revision_example, | ||||
snapshot_example, | snapshot_example, | ||||
Show All 17 Lines | def test_todict_inverse_fromdict(objtype_and_obj): | ||||
# Check from_dict() does not change the input dict | # Check from_dict() does not change the input dict | ||||
assert obj_as_dict == obj_as_dict_copy | assert obj_as_dict == obj_as_dict_copy | ||||
# Check the composition of from_dict and to_dict is the identity | # Check the composition of from_dict and to_dict is the identity | ||||
assert obj_as_dict == type(obj).from_dict(obj_as_dict).to_dict() | assert obj_as_dict == type(obj).from_dict(obj_as_dict).to_dict() | ||||
@pytest.mark.parametrize("object_type, objects", TEST_OBJECTS.items()) | |||||
def test_swh_model_todict_fromdict(object_type, objects): | |||||
"""checks model objects in swh_model_data are in correct shape""" | |||||
assert objects | |||||
for obj in objects: | |||||
# Check the composition of from_dict and to_dict is the identity | |||||
obj_as_dict = obj.to_dict() | |||||
assert obj == type(obj).from_dict(obj_as_dict) | |||||
assert obj_as_dict == type(obj).from_dict(obj_as_dict).to_dict() | |||||
def test_unique_key(): | def test_unique_key(): | ||||
url = "http://example.org/" | url = "http://example.org/" | ||||
date = datetime.datetime.now(tz=datetime.timezone.utc) | date = datetime.datetime.now(tz=datetime.timezone.utc) | ||||
id_ = b"42" * 10 | id_ = b"42" * 10 | ||||
assert Origin(url=url).unique_key() == {"url": url} | assert Origin(url=url).unique_key() == {"url": url} | ||||
assert OriginVisit(origin=url, date=date, type="git").unique_key() == { | assert OriginVisit(origin=url, date=date, type="git").unique_key() == { | ||||
"origin": url, | "origin": url, | ||||
"date": str(date), | "date": str(date), | ||||
▲ Show 20 Lines • Show All 1,033 Lines • Show Last 20 Lines |