Exemplo n.º 1
0
 def test_clickmeta(self):
     from pygmy.app.link import shorten, unshorten, link_stats
     data = shorten(self.long_url)
     assert isinstance(data, dict) is True
     assert link_stats(data['short_code'] + 'abc+') is None
     stats = link_stats(data['short_code'] + '+')
     assert stats is not None
Exemplo n.º 2
0
def resolve(code):
    """Resolve the short url. code=301 PERMANENT REDIRECTION"""
    # TODO not needed
    user_email = APITokenAuth.get_jwt_identity()
    secret_key = request.headers.get('secret_key')
    try:
        # check if link is not a secret link
        long_url = resolve_short(code.strip('+'), secret_key=secret_key)
        if code.startswith('+') or code.endswith('+'):
            stats = link_stats(code)
            response = jsonify(stats)
            if stats is None:
                response = jsonify({'error': 'URL not found or disabled'}), 404
        else:
            long_url = resolve_short(code.strip('+'),
                                     request=request,
                                     secret_key=secret_key)
            response = redirect(long_url, code=301)
    except LinkExpired:
        response = jsonify(dict(error="Link has expired")), 404
    except URLAuthFailed:
        response = jsonify({'error': 'Access to URL forbidden'}), 403
    except (URLNotFound, AssertionError):
        response = jsonify({'error': 'URL not found or disabled'}), 404
    return response
Exemplo n.º 3
0
def resolve_stats(code):
    """Show the stats for the short url"""
    try:
        stats = link_stats(code)
        response = jsonify(stats)
        if stats is None:
            response = jsonify({'error': 'URL not found or disabled'}), 404
    except LinkExpired:
        response = jsonify(dict(error="Link has expired")), 404
    except URLAuthFailed:
        response = jsonify({'error': 'Access to URL forbidden'}), 403
    except (URLNotFound, AssertionError):
        response = jsonify({'error': 'URL not found or disabled'}), 404
    return response
Exemplo n.º 4
0
 def test_clickmeta(self):
     data = shorten(self.long_url)
     self.assertTrue(isinstance(data, dict) is True)
     self.assertIsNone(link_stats(data['short_code'] + 'abc+'))
     stats = link_stats(data['short_code'] + '+')
     self.assertIsNotNone(stats)
Exemplo n.º 5
0
 def test_clickmeta(self):
     data = shorten(self.long_url)
     assert isinstance(data, dict) is True
     assert link_stats(data['short_code'] + 'abc+') is None
     stats = link_stats(data['short_code'] + '+')
     assert stats is not None