Esempio n. 1
0
 def test_base7(self):
     base7 = BaseConverter('cjdhel3', sign='g')
     self.assertEqual(base7.encode(1234), 'hejd')
     self.assertEqual(base7.decode('hejd'), 1234)
     self.assertEqual(base7.encode(-1234), 'ghejd')
     self.assertEqual(base7.decode('ghejd'), -1234)
Esempio n. 2
0
 def test_exception(self):
     with self.assertRaises(ValueError):
         BaseConverter('abc', sign='a')
     self.assertIsInstance(BaseConverter('abc', sign='d'), BaseConverter)
Esempio n. 3
0
 def test_base11(self):
     base11 = BaseConverter('0123456789-', sign='$')
     self.assertEqual(base11.encode(1234), '-22')
     self.assertEqual(base11.decode('-22'), 1234)
     self.assertEqual(base11.encode(-1234), '$-22')
     self.assertEqual(base11.decode('$-22'), -1234)
Esempio n. 4
0
 def test_base20(self):
     base20 = BaseConverter('0123456789abcdefghij')
     self.assertEqual(base20.encode(1234), '31e')
     self.assertEqual(base20.decode('31e'), 1234)
     self.assertEqual(base20.encode(-1234), '-31e')
     self.assertEqual(base20.decode('-31e'), -1234)
Esempio n. 5
0
 def test_base20(self):
     base20 = BaseConverter('0123456789abcdefghij')
     self.assertEqual(base20.encode(1234), '31e')
     self.assertEqual(base20.decode('31e'), 1234)
     self.assertEqual(base20.encode(-1234), '-31e')
     self.assertEqual(base20.decode('-31e'), -1234)
Esempio n. 6
0
 def test_base7(self):
     base7 = BaseConverter('cjdhel3', sign='g')
     self.assertEqual(base7.encode(1234), 'hejd')
     self.assertEqual(base7.decode('hejd'), 1234)
     self.assertEqual(base7.encode(-1234), 'ghejd')
     self.assertEqual(base7.decode('ghejd'), -1234)
 def test_repr(self):
     base7 = BaseConverter('cjdhel3', sign='g')
     self.assertEqual(repr(base7), '<BaseConverter: base7 (cjdhel3)>')
Esempio n. 8
0
 def test_base11(self):
     base11 = BaseConverter('0123456789-', sign='$')
     self.assertEqual(base11.encode(1234), '-22')
     self.assertEqual(base11.decode('-22'), 1234)
     self.assertEqual(base11.encode(-1234), '$-22')
     self.assertEqual(base11.decode('$-22'), -1234)
Esempio n. 9
0
 def test_exception(self):
     self.assertRaises(ValueError, BaseConverter, 'abc', sign='a')
     self.assertTrue(
         isinstance(BaseConverter('abc', sign='d'), BaseConverter))
Esempio n. 10
0
from django.utils.baseconv import BaseConverter

# symbols allowed in URL's:
# '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._~'

BASE_SYMBOLS = 'abcdefghijklmnopqrstuvwxyz0123456789'
converter = BaseConverter(BASE_SYMBOLS)
Esempio n. 11
0
 def test_repr(self):
     base7 = BaseConverter("cjdhel3", sign="g")
     self.assertEqual(repr(base7), "<BaseConverter: base7 (cjdhel3)>")
Esempio n. 12
0
 def test_exception(self):
     with self.assertRaises(ValueError):
         BaseConverter("abc", sign="a")
     self.assertIsInstance(BaseConverter("abc", sign="d"), BaseConverter)
Esempio n. 13
0
 def test_base7(self):
     base7 = BaseConverter("cjdhel3", sign="g")
     self.assertEqual(base7.encode(1234), "hejd")
     self.assertEqual(base7.decode("hejd"), 1234)
     self.assertEqual(base7.encode(-1234), "ghejd")
     self.assertEqual(base7.decode("ghejd"), -1234)
Esempio n. 14
0
 def test_base20(self):
     base20 = BaseConverter("0123456789abcdefghij")
     self.assertEqual(base20.encode(1234), "31e")
     self.assertEqual(base20.decode("31e"), 1234)
     self.assertEqual(base20.encode(-1234), "-31e")
     self.assertEqual(base20.decode("-31e"), -1234)
Esempio n. 15
0
 def test_base11(self):
     base11 = BaseConverter("0123456789-", sign="$")
     self.assertEqual(base11.encode(1234), "-22")
     self.assertEqual(base11.decode("-22"), 1234)
     self.assertEqual(base11.encode(-1234), "$-22")
     self.assertEqual(base11.decode("$-22"), -1234)