diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py --- a/swh/model/tests/test_identifiers.py +++ b/swh/model/tests/test_identifiers.py @@ -927,37 +927,6 @@ }, ) - def test_parse_swhid_parsing_error(self): - for swhid in [ - ("swh:1:cnt"), - ("swh:1:"), - ("swh:"), - ("swh:1:cnt:"), - ("foo:1:cnt:abc8bc9d7a6bcf6db04f476d29314f157507d505"), - ("swh:2:dir:def8bc9d7a6bcf6db04f476d29314f157507d505"), - ("swh:1:foo:fed8bc9d7a6bcf6db04f476d29314f157507d505"), - ("swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;" "malformed"), - ("swh:1:snp:gh6959356d30f1a4e9b7f6bca59b9a336464c03d"), - ("swh:1:snp:foo"), - ]: - with self.assertRaises(ValidationError): - identifiers.parse_swhid(swhid) - - def test_persistentid_class_validation_error(self): - for _ns, _version, _type, _id in [ - ("foo", 1, CONTENT, "abc8bc9d7a6bcf6db04f476d29314f157507d505"), - ("swh", 2, DIRECTORY, "def8bc9d7a6bcf6db04f476d29314f157507d505"), - ("swh", 1, "foo", "fed8bc9d7a6bcf6db04f476d29314f157507d505"), - ("swh", 1, SNAPSHOT, "gh6959356d30f1a4e9b7f6bca59b9a336464c03d"), - ]: - with self.assertRaises(ValidationError): - SWHID( - namespace=_ns, - scheme_version=_version, - object_type=_type, - object_id=_id, - ) - class OriginIdentifier(unittest.TestCase): def setUp(self): @@ -1077,6 +1046,42 @@ normalize_timestamp(dict_input) +@pytest.mark.parametrize( + "invalid_swhid", + [ + "swh:1:cnt", + "swh:1:", + "swh:", + "swh:1:cnt:", + "foo:1:cnt:abc8bc9d7a6bcf6db04f476d29314f157507d505", + "swh:2:dir:def8bc9d7a6bcf6db04f476d29314f157507d505", + "swh:1:foo:fed8bc9d7a6bcf6db04f476d29314f157507d505", + "swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;malformed", + "swh:1:snp:gh6959356d30f1a4e9b7f6bca59b9a336464c03d", + "swh:1:snp:foo", + ], +) +def test_parse_swhid_parsing_error(invalid_swhid): + with pytest.raises(ValidationError): + identifiers.parse_swhid(invalid_swhid) + + +@pytest.mark.parametrize( + "ns,version,type,id", + [ + ("foo", 1, CONTENT, "abc8bc9d7a6bcf6db04f476d29314f157507d505",), + ("swh", 2, DIRECTORY, "def8bc9d7a6bcf6db04f476d29314f157507d505",), + ("swh", 1, "foo", "fed8bc9d7a6bcf6db04f476d29314f157507d505",), + ("swh", 1, SNAPSHOT, "gh6959356d30f1a4e9b7f6bca59b9a336464c03d",), + ], +) +def test_SWHID_class_validation_error(ns, version, type, id): + with pytest.raises(ValidationError): + SWHID( + namespace=ns, scheme_version=version, object_type=type, object_id=id, + ) + + def test_swhid_hash(): object_id = "94a9ed024d3859793618152ea559a168bbcbb5e2"