def test_substitution_error(self): def substitute(s): chars = list(s) chars[2] = identifier.XDIGITS[ (identifier.XDIGITS.index(chars[2]) + 1) % len(identifier.XDIGITS)] return ''.join(chars) cid = identifier.for_collection() identifier.check(cid) cid2 = substitute(cid) with self.assertRaises(identifier.IdentifierException): identifier.check(cid2) did = identifier.for_definition(cid) identifier.check(did) did2 = substitute(did) with self.assertRaises(identifier.IdentifierException): identifier.check(did2)
def test_transposition_error(self): def transpose(s): chars = list(s) for i in range(-3, -(len(s)+1), -1): if not chars[i] == chars[i+1]: chars[i], chars[i+1] = chars[i+1], chars[i] return ''.join(chars) cid = identifier.for_collection() identifier.check(cid) cid2 = transpose(cid) with self.assertRaises(identifier.IdentifierException): identifier.check(cid2) did = identifier.for_definition(cid) identifier.check(did) did2 = transpose(did) with self.assertRaises(identifier.IdentifierException): identifier.check(did2)
def test_generate_definition_id(self): cid = identifier.for_collection() did = identifier.for_definition(cid) self.assertTrue(did.startswith(cid)) self.assertEqual(len(did), 11)