def test_get_node_public_key(self):
     """Test get_node_public_key."""
     node = FakeNode()
     node.public_uuid = uuid.UUID(int=12)
     self.assertEqual(
         get_node_public_key(node),
         encode_base62(node.public_uuid.int, padded_to=22))
 def test_get_public_url(self):
     """Test get_public_url function."""
     node = FakeNode()
     self.assertIsNone(get_public_file_url(node))
     # using a short value here to make sure padding works
     node.public_uuid = uuid.UUID(int=12)
     key = encode_base62(node.public_uuid.int, padded_to=22)
     self.assertEqual(get_public_file_url(node),
                      '%s/%s' % (settings.PUBLIC_URL_PREFIX, key))
 def test_get_public_url(self):
     """Test get_public_url function."""
     node = FakeNode()
     self.assertIsNone(get_public_file_url(node))
     # using a short value here to make sure padding works
     node.public_uuid = uuid.UUID(int=12)
     key = encode_base62(node.public_uuid.int, padded_to=22)
     self.assertEqual(
         get_public_file_url(node),
         '%s/%s' % (settings.PUBLIC_URL_PREFIX, key))
 def test_encode_base62(self):
     """Tests for encode_base62."""
     self.assertEqual('1', encode_base62(1))
     self.assertEqual('A', encode_base62(10))
     self.assertEqual('a', encode_base62(36))
     self.assertEqual('10', encode_base62(62))
     self.assertEqual('100', encode_base62(62 * 62))
     self.assertEqual('00100', encode_base62(62 * 62, padded_to=5))
     # Only non-negative values a can be encoded.
     self.assertRaises(Base62Error, encode_base62, -42)
     self.assertRaises(Base62Error, encode_base62, 0)
     self.assertRaises(Base62Error, encode_base62, 62, padded_to=1)
 def test_encode_base62(self):
     """Tests for encode_base62."""
     self.assertEqual('1', encode_base62(1))
     self.assertEqual('A', encode_base62(10))
     self.assertEqual('a', encode_base62(36))
     self.assertEqual('10', encode_base62(62))
     self.assertEqual('100', encode_base62(62 * 62))
     self.assertEqual('00100', encode_base62(62 * 62, padded_to=5))
     # Only non-negative values a can be encoded.
     self.assertRaises(Base62Error, encode_base62, -42)
     self.assertRaises(Base62Error, encode_base62, 0)
     self.assertRaises(Base62Error, encode_base62, 62, padded_to=1)
    def test_decode_base62(self):
        """Tests for decode_base62."""
        self.assertEqual(1, decode_base62('1'))
        self.assertEqual(10, decode_base62('A'))
        self.assertEqual(36, decode_base62('a'))
        self.assertEqual(62, decode_base62('10'))
        self.assertEqual(62 * 62, decode_base62('100'))
        self.assertEqual(62 * 62, decode_base62('000100', allow_padding=True))

        # The empty string is not allowed.
        self.assertRaises(Base62Error, decode_base62, '')
        # zero-prefixed strings are not allowed
        self.assertRaises(Base62Error, decode_base62, '05')
        # Bad characters are also not allowed:
        self.assertRaises(Base62Error, decode_base62, '#!abc')
        # Try with a value to large for a UUID
        val = encode_base62(1 << 128, padded_to=22)
        self.assertRaises(Base62Error, decode_base62, val)
    def test_decode_base62(self):
        """Tests for decode_base62."""
        self.assertEqual(1, decode_base62('1'))
        self.assertEqual(10, decode_base62('A'))
        self.assertEqual(36, decode_base62('a'))
        self.assertEqual(62, decode_base62('10'))
        self.assertEqual(62 * 62, decode_base62('100'))
        self.assertEqual(62 * 62, decode_base62('000100', allow_padding=True))

        # The empty string is not allowed.
        self.assertRaises(Base62Error, decode_base62, '')
        # zero-prefixed strings are not allowed
        self.assertRaises(Base62Error, decode_base62, '05')
        # Bad characters are also not allowed:
        self.assertRaises(Base62Error, decode_base62, '#!abc')
        # Try with a value to large for a UUID
        val = encode_base62(1 << 128, padded_to=22)
        self.assertRaises(Base62Error, decode_base62, val)
Esempio n. 8
0
 def base62_public_id(self):
     """The base-62 version of the public id."""
     return utils.encode_base62(self.public_uuid.int, padded_to=22)
Esempio n. 9
0
 def base62_public_id(self):
     """The base-62 version of the public id."""
     return utils.encode_base62(self.public_uuid.int, padded_to=22)
Esempio n. 10
0
 def test_get_node_public_key(self):
     """Test get_node_public_key."""
     node = FakeNode()
     node.public_uuid = uuid.UUID(int=12)
     self.assertEqual(get_node_public_key(node),
                      encode_base62(node.public_uuid.int, padded_to=22))