Exemplo n.º 1
0
 def testRegression(self):
     subject = Base62Util()
     for i in range(5000):
         self.assertEqual(subject.toDec(subject.toBase(i)), str(i))
Exemplo n.º 2
0
import os
import jinja2
import webapp2

from lib.base62 import (Base62Util)

from google.appengine.ext import ndb

JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__) + "/templates"),
    extensions=['jinja2.ext.autoescape'],
    autoescape=False)

URL_SHORTNER_NAME = 'url_shortener'  # key to thendb data store
baseUtil = Base62Util()  # a utility class for encoding


def urldb_key(url_shortener=URL_SHORTNER_NAME):
    """
        We use url_shortener as the key, Entry as the value to hold urls
    """
    return ndb.Key('Entry', url_shortener)


class Entry(ndb.Model):
    """
        A table to store the original url and its mapping to shorened form
    """
    url = ndb.StringProperty(indexed=False)
    shortened = ndb.StringProperty(indexed=False)
Exemplo n.º 3
0
 def testSample(self):
     subject = Base62Util()
     self.assertEqual('sXDVELneo', subject.toBase(6323566249246720))
     self.assertEqual('mw0iXTwjK', subject.toBase(4916191365693440))
Exemplo n.º 4
0
 def testDecmialToBase62SimpleCase(self):
     subject = Base62Util()
     self.assertEqual('64', subject.toDec('12'))
Exemplo n.º 5
0
 def testDecmialToBase62Basic(self):
     subject = Base62Util()
     self.assertEqual('50', subject.toDec('O'))
Exemplo n.º 6
0
 def testBase62ToDecmialSimpleCase(self):
     subject = Base62Util()
     self.assertEqual('12', subject.toBase(64))
Exemplo n.º 7
0
 def testBase62ToDecmialBasic(self):
     subject = Base62Util()
     self.assertEqual('O', subject.toBase(50))