Esempio n. 1
0
def process_short_url(short_url, return_json=False):
    try:
        id_number = shorten_utils.get_id_from_short_url(short_url)
        query = 'select long_url from entries where id=(?)'
        cur = g.db.execute(query, [id_number])
        long_url = cur.fetchone()[0]
        print long_url

        if return_json:
            return json.dumps(long_url)
        else:
            return redirect(long_url, code=302)
    except:
        abort(404)
Esempio n. 2
0
 def test_util_functions(self):
     id_number = 1
     short_url = get_short_url_from_id(id_number)
     self.assertEqual(get_short_url_from_id(id_number), get_short_url_from_id(get_id_from_short_url(short_url)))
     self.assertEqual(get_id_from_short_url(short_url), get_id_from_short_url(get_short_url_from_id(id_number)))