Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_identifiers.py
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def test_gen_swhid(content): | ||||
swh_object_type = CONTENT | swh_object_type = CONTENT | ||||
sha1_git = content["sha1_git"] | sha1_git = content["sha1_git"] | ||||
expected_swhid = "swh:1:cnt:" + sha1_git | expected_swhid = "swh:1:cnt:" + sha1_git | ||||
assert gen_swhid(swh_object_type, sha1_git) == expected_swhid | assert gen_swhid(swh_object_type, sha1_git) == expected_swhid | ||||
assert ( | assert ( | ||||
gen_swhid(swh_object_type, sha1_git, metadata={"foo": "bar"}) | gen_swhid(swh_object_type, sha1_git, metadata={"origin": "test"}) | ||||
== expected_swhid + ";foo=bar" | == expected_swhid + ";origin=test" | ||||
) | ) | ||||
assert ( | assert ( | ||||
gen_swhid(swh_object_type, sha1_git, metadata={"foo": None}) == expected_swhid | gen_swhid(swh_object_type, sha1_git, metadata={"origin": None}) | ||||
== expected_swhid | |||||
) | ) | ||||
with pytest.raises(BadInputExc) as e: | with pytest.raises(BadInputExc) as e: | ||||
gen_swhid("foo", sha1_git) | gen_swhid("foo", sha1_git) | ||||
assert e.match("Invalid object") | assert e.match("Invalid object") | ||||
with pytest.raises(BadInputExc) as e: | with pytest.raises(BadInputExc) as e: | ||||
gen_swhid(swh_object_type, "not a valid id") | gen_swhid(swh_object_type, "not a valid id") | ||||
▲ Show 20 Lines • Show All 580 Lines • Show Last 20 Lines |