Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_model.py
Show First 20 Lines • Show All 409 Lines • ▼ Show 20 Lines | def test_skipped_content_origin_is_str(skipped_content_d): | ||||
skipped_content_d["origin"] = "http://path/to/origin" | skipped_content_d["origin"] = "http://path/to/origin" | ||||
assert SkippedContent.from_dict(skipped_content_d) | assert SkippedContent.from_dict(skipped_content_d) | ||||
skipped_content_d["origin"] = Origin(url="http://path/to/origin") | skipped_content_d["origin"] = Origin(url="http://path/to/origin") | ||||
with pytest.raises(ValueError, match="origin"): | with pytest.raises(ValueError, match="origin"): | ||||
SkippedContent.from_dict(skipped_content_d) | SkippedContent.from_dict(skipped_content_d) | ||||
# Revision | |||||
def test_revision_extra_headers(): | |||||
rev_dict = revision_example.copy() | |||||
rev_dict.pop("id") | |||||
rev = Revision.from_dict(rev_dict) | |||||
rev_dict = attr.asdict(rev, recurse=False) | |||||
rev_model = Revision(**rev_dict) | |||||
assert rev_model.metadata is None | |||||
assert rev_model.extra_headers == () | |||||
rev_dict["metadata"] = { | |||||
"something": "somewhere", | |||||
"some other thing": "stranger", | |||||
} | |||||
rev_model = Revision(**rev_dict) | |||||
assert rev_model.metadata == rev_dict["metadata"] | |||||
assert rev_model.extra_headers == () | |||||
extra_headers = ( | |||||
("header1", "value1"), | |||||
("header2", 42), | |||||
("header3", b"should I?\u0000"), | |||||
("header1", "again"), | |||||
) | |||||
# check the bw-compat init hook does the job | |||||
rev_dict["metadata"]["extra_headers"] = extra_headers | |||||
rev_model = Revision(**rev_dict) | |||||
assert "extra_headers" not in rev_model.metadata | |||||
assert rev_model.extra_headers == extra_headers | |||||
# check Revision.extra_headers converter does the job | |||||
rev_dict["metadata"]["extra_headers"] = [list(x) for x in extra_headers] | |||||
rev_model = Revision(**rev_dict) | |||||
assert "extra_headers" not in rev_model.metadata | |||||
olasd: Shouldn't these two tests be split out to separate unit tests? | |||||
Done Inline Actionscould do that, sure douardda: could do that, sure | |||||
assert rev_model.extra_headers == extra_headers | |||||
def test_revision_extra_headers_from_dict(): | |||||
rev_dict = revision_example.copy() | |||||
rev_dict.pop("id") | |||||
rev_model = Revision.from_dict(rev_dict) | |||||
assert rev_model.metadata is None | |||||
assert rev_model.extra_headers == () | |||||
rev_dict["metadata"] = { | |||||
"something": "somewhere", | |||||
"some other thing": "stranger", | |||||
} | |||||
rev_model = Revision.from_dict(rev_dict) | |||||
assert rev_model.metadata == rev_dict["metadata"] | |||||
assert rev_model.extra_headers == () | |||||
extra_headers = ( | |||||
("header1", "value1"), | |||||
("header2", 42), | |||||
("header3", b"should I?\u0000"), | |||||
("header1", "again"), | |||||
) | |||||
# check the bw-compat init hook does the job | |||||
rev_dict["metadata"]["extra_headers"] = extra_headers | |||||
rev_model = Revision.from_dict(rev_dict) | |||||
assert "extra_headers" not in rev_model.metadata | |||||
assert rev_model.extra_headers == extra_headers | |||||
# check Revision.extra_headers converter does the job | |||||
rev_dict["metadata"]["extra_headers"] = [list(x) for x in extra_headers] | |||||
rev_model = Revision.from_dict(rev_dict) | |||||
assert "extra_headers" not in rev_model.metadata | |||||
assert rev_model.extra_headers == extra_headers | |||||
# ID computation | # ID computation | ||||
def test_directory_model_id_computation(): | def test_directory_model_id_computation(): | ||||
dir_dict = directory_example.copy() | dir_dict = directory_example.copy() | ||||
del dir_dict["id"] | del dir_dict["id"] | ||||
dir_id = hash_to_bytes(directory_identifier(dir_dict)) | dir_id = hash_to_bytes(directory_identifier(dir_dict)) | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |
Shouldn't these two tests be split out to separate unit tests?