예제 #1
0
 def test_secret_short_url(self):
     secret_key = 123
     data = shorten(self.long_url, secret_key=secret_key)
     assert data['is_protected'] is True
     assert data['secret_key'] == str(secret_key)
     with self.assertRaises(URLAuthFailed):
         unshorten(data['short_code'])
         unshorten(data['short_code'], secret_key='safe')
     udata = unshorten(data['short_code'], secret_key='123')
     assert udata['long_url'] == data['long_url']
예제 #2
0
 def test_custom_short_url(self):
     short_code = 'test'
     data = shorten(self.long_url, short_code=short_code)
     assert data['short_code'] == short_code
     assert data['is_custom'] is True
     udata = unshorten(short_url=short_code)
     assert udata['long_url'] == self.long_url
예제 #3
0
 def test_custom_short_url(self):
     from pygmy.app.link import shorten, unshorten
     short_code = 'test'
     data = shorten(self.long_url, short_code=short_code)
     assert data['short_code'] == short_code
     assert data['is_custom'] is True
     udata = unshorten(short_url=short_code)
     assert udata['long_url'] == self.long_url
예제 #4
0
 def get(self):
     secret = request.headers.get('secret_key')
     short_url = request.args.get('url')
     try:
         long_url = unshorten(short_url,
                              secret_key=secret,
                              query_by_code=True,
                              request=request)
         result = self.schema.dump(long_url)
     except LinkExpired:
         return jsonify(dict(error="Link has expired")), 410
     except URLAuthFailed:
         return jsonify(dict(error="Secret key not provided")), 403
     except URLNotFound:
         return jsonify(dict(error="URL Not Found Or Expired")), 404
     return jsonify(result.data), 200
예제 #5
0
 def test_short_url_unshorten(self):
     data = shorten(self.long_url)
     udata = unshorten(data['short_code'])
     assert isinstance(udata, dict)
     assert udata['long_url'] == self.long_url
예제 #6
0
 def test_short_url_unshorten(self):
     from pygmy.app.link import shorten, unshorten
     data = shorten(self.long_url)
     udata = unshorten(data['short_code'])
     assert isinstance(udata, dict)
     assert udata['long_url'] == self.long_url