def test_init_app(): app = Flask(__name__) su = ShortUrl() su.init_app(app) a = 21 b = su.encode(a) c = su.enbase(b) d = su.debase(c) e = su.decode(d) assert a == e assert b == d assert c == su.encode_url(a) assert a == su.decode_url(c)
def test_shorturl(): app = Flask(__name__) su = ShortUrl(app) for a in range(0, 200000, 37): b = su.encode(a) c = su.enbase(b) d = su.debase(c) e = su.decode(d) assert a == e assert b == d assert c == su.encode_url(a) assert a == su.decode_url(c)
def test_flask_ctx(): app = Flask(__name__) DEFAULT_ALPHABET = 'mn6j2c4rv8bpygw95z7hsdaetxuk3fq' app.config.setdefault('SHORT_URL_ALPHABET', DEFAULT_ALPHABET) app.config.setdefault('SHORT_URL_MIN_LENGTH', 5) app.config.setdefault('SHORT_URL_BLOCK_SIZE', 24) su = ShortUrl() with app.test_request_context(): a = 21 b = su.encode(a) c = su.enbase(b) d = su.debase(c) e = su.decode(d) assert a == e assert b == d assert c == su.encode_url(a) assert a == su.decode_url(c)
from flask_wtf import Form from wtforms import StringField from wtforms.validators import DataRequired, length, regexp import datetime from flask_shorturl import ShortUrl from flask.ext.pymongo import PyMongo from flask_pymongo import DESCENDING from flask.ext.qrcode import QRcode from urllib import parse app = Flask(__name__) app.config['SECRET_KEY'] = os.urandom(24) app.config['MONGO_DBNAME'] = 'links' mongo = PyMongo(app) su = ShortUrl(app) QRcode(app) class MyForm(Form): name = StringField('Enter your Long URL', validators=[ DataRequired(message=u'this field is required'), length(max=2000, message=u'maximum URL length of 2000 characters'), length(min=10, message=u'minimum URL length of 10 characters'), regexp(r"(https?://|ftp://)", message=u'please enter a valid URL to \ shorten') ]) @app.route('/', methods=('GET', 'POST')) def home():
def test_no_ctx(): su = ShortUrl() su.encode(21)