Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_identifiers.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import binascii | import binascii | ||||
import datetime | import datetime | ||||
import unittest | import unittest | ||||
from swh.model import hashutil, identifiers | from swh.model import hashutil, identifiers | ||||
from swh.model.exceptions import ValidationError | from swh.model.exceptions import ValidationError | ||||
from swh.model.identifiers import (CONTENT, DIRECTORY, | from swh.model.identifiers import (CONTENT, DIRECTORY, | ||||
PERSISTENT_IDENTIFIER_TYPES, RELEASE, | PID_TYPES, RELEASE, | ||||
REVISION, SNAPSHOT, PersistentId) | REVISION, SNAPSHOT, PersistentId) | ||||
class UtilityFunctionsIdentifier(unittest.TestCase): | class UtilityFunctionsIdentifier(unittest.TestCase): | ||||
def setUp(self): | def setUp(self): | ||||
self.str_id = 'c2e41aae41ac17bd4a650770d6ee77f62e52235b' | self.str_id = 'c2e41aae41ac17bd4a650770d6ee77f62e52235b' | ||||
self.bytes_id = binascii.unhexlify(self.str_id) | self.bytes_id = binascii.unhexlify(self.str_id) | ||||
self.bad_type_id = object() | self.bad_type_id = object() | ||||
▲ Show 20 Lines • Show All 849 Lines • ▼ Show 20 Lines | def test_parse_persistent_identifier_parsing_error(self): | ||||
'Wrong format: There should be 4 mandatory values'), | 'Wrong format: There should be 4 mandatory values'), | ||||
('swh:1:', | ('swh:1:', | ||||
'Wrong format: There should be 4 mandatory values'), | 'Wrong format: There should be 4 mandatory values'), | ||||
('swh:', | ('swh:', | ||||
'Wrong format: There should be 4 mandatory values'), | 'Wrong format: There should be 4 mandatory values'), | ||||
('swh:1:cnt:', | ('swh:1:cnt:', | ||||
'Wrong format: Identifier should be present'), | 'Wrong format: Identifier should be present'), | ||||
('foo:1:cnt:abc8bc9d7a6bcf6db04f476d29314f157507d505', | ('foo:1:cnt:abc8bc9d7a6bcf6db04f476d29314f157507d505', | ||||
'Wrong format: Supported namespace is \'swh\''), | 'Wrong format: only supported namespace is \'swh\''), | ||||
('swh:2:dir:def8bc9d7a6bcf6db04f476d29314f157507d505', | ('swh:2:dir:def8bc9d7a6bcf6db04f476d29314f157507d505', | ||||
'Wrong format: Supported version is 1'), | 'Wrong format: only supported version is 1'), | ||||
('swh:1:foo:fed8bc9d7a6bcf6db04f476d29314f157507d505', | ('swh:1:foo:fed8bc9d7a6bcf6db04f476d29314f157507d505', | ||||
'Wrong format: Supported types are %s' % ( | 'Wrong format: Supported types are %s' % ( | ||||
', '.join(PERSISTENT_IDENTIFIER_TYPES))), | ', '.join(PID_TYPES))), | ||||
('swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;' | ('swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;' | ||||
'malformed', | 'malformed', | ||||
'Contextual data is badly formatted, form key=val expected'), | 'Contextual data is badly formatted, form key=val expected'), | ||||
('swh:1:snp:gh6959356d30f1a4e9b7f6bca59b9a336464c03d', | ('swh:1:snp:gh6959356d30f1a4e9b7f6bca59b9a336464c03d', | ||||
'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') | ||||
]: | ]: | ||||
Show All 14 Lines |