Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_identifiers.py
Show First 20 Lines • Show All 763 Lines • ▼ Show 20 Lines | def test_persistent_identifier(self): | ||||
_content = {'sha1_git': _content_id} | _content = {'sha1_git': _content_id} | ||||
for full_type, _hash, expected_persistent_id, version, _meta in [ | for full_type, _hash, expected_persistent_id, version, _meta in [ | ||||
(SNAPSHOT, _snapshot_id, | (SNAPSHOT, _snapshot_id, | ||||
'swh:1:snp:c7c108084bc0bf3d81436bf980b46e98bd338453', | 'swh:1:snp:c7c108084bc0bf3d81436bf980b46e98bd338453', | ||||
None, {}), | None, {}), | ||||
(RELEASE, _release_id, | (RELEASE, _release_id, | ||||
'swh:2:rel:22ece559cc7cc2364edc5e5593d63ae8bd229f9f', | 'swh:2:rel:22ece559cc7cc2364edc5e5593d63ae8bd229f9f', | ||||
2, {}), | 2, {}), | ||||
(REVISION, _revision_id, | (REVISION, _revision_id, | ||||
douardda: There might be a good reason for this, but I find it very suspicious to have to change these… | |||||
Not Done Inline ActionsI don't know if different pid versions are accepted. According to the parse_persistent_identifier function, the pid version must be 1 DanSeraf: I don't know if different pid versions are accepted. According to the… | |||||
Not Done Inline ActionsIt looks like these tests were testing hypothetical identifiers in schema version 2, that cannot really exist right now. With proper validation they cannot be created anymore, and that's correct AFAICT. zack: It looks like these tests were testing hypothetical identifiers in schema version 2, that… | |||||
'swh:1:rev:309cf2674ee7a0749978cf8265ab91a60aea0f7d', | 'swh:1:rev:309cf2674ee7a0749978cf8265ab91a60aea0f7d', | ||||
None, {}), | None, {}), | ||||
(DIRECTORY, _directory_id, | (DIRECTORY, _directory_id, | ||||
'swh:1:dir:d198bc9d7a6bcf6db04f476d29314f157507d505', | 'swh:1:dir:d198bc9d7a6bcf6db04f476d29314f157507d505', | ||||
None, {}), | None, {}), | ||||
(CONTENT, _content_id, | (CONTENT, _content_id, | ||||
'swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2', | 'swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2', | ||||
1, {}), | 1, {}), | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | def test_parse_persistent_identifier_parsing_error(self): | ||||
'Wrong format: Identifier should be a valid hash'), | 'Wrong format: Identifier should be a valid hash'), | ||||
('swh:1:snp:foo', | ('swh:1:snp:foo', | ||||
'Wrong format: Identifier should be a valid hash') | 'Wrong format: Identifier should be a valid hash') | ||||
]: | ]: | ||||
with self.assertRaisesRegex( | with self.assertRaisesRegex( | ||||
ValidationError, _error): | ValidationError, _error): | ||||
identifiers.parse_persistent_identifier(pid) | identifiers.parse_persistent_identifier(pid) | ||||
def test_persistentid_class_validation_error(self): | |||||
for _ns, _version, _type, _id, _error in [ | |||||
('foo', 1, CONTENT, 'abc8bc9d7a6bcf6db04f476d29314f157507d505', | |||||
'Wrong format: only supported namespace is \'swh\''), | |||||
('swh', 2, DIRECTORY, 'def8bc9d7a6bcf6db04f476d29314f157507d505', | |||||
'Wrong format: only supported version is 1'), | |||||
('swh', 1, 'foo', 'fed8bc9d7a6bcf6db04f476d29314f157507d505', | |||||
'Wrong input: Supported types are'), | |||||
('swh', 1, SNAPSHOT, 'gh6959356d30f1a4e9b7f6bca59b9a336464c03d', | |||||
'Unexpected characters') | |||||
]: | |||||
with self.assertRaisesRegex( | |||||
ValidationError, _error): | |||||
PersistentId( | |||||
namespace=_ns, | |||||
scheme_version=_version, | |||||
object_type=_type, | |||||
object_id=_id | |||||
) | |||||
class OriginIdentifier(unittest.TestCase): | class OriginIdentifier(unittest.TestCase): | ||||
def setUp(self): | def setUp(self): | ||||
self.origin = { | self.origin = { | ||||
'url': 'https://github.com/torvalds/linux', | 'url': 'https://github.com/torvalds/linux', | ||||
} | } | ||||
def test_content_identifier(self): | def test_content_identifier(self): | ||||
self.assertEqual(identifiers.origin_identifier(self.origin), | self.assertEqual(identifiers.origin_identifier(self.origin), | ||||
'b63a575fe3faab7692c9f38fb09d4bb45651bb0f') | 'b63a575fe3faab7692c9f38fb09d4bb45651bb0f') |
There might be a good reason for this, but I find it very suspicious to have to change these expected values here.