Find file
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (57 sloc) 1.81 KB
This is a py.test script
Example usage on Unix:
bitly-api-python $ BITLY_ACCESS_TOKEN=<accesstoken> nosetests
or 'export' the two environment variables prior to running nosetests
import os
import sys
import bitly_api
def get_connection():
"""Create a Connection base on username and access token credentials"""
if BITLY_ACCESS_TOKEN not in os.environ:
raise ValueError("Environment variable '{}' required".format(BITLY_ACCESS_TOKEN))
access_token = os.getenv(BITLY_ACCESS_TOKEN)
bitly = bitly_api.Connection(access_token=access_token)
return bitly
def testApi():
bitly = get_connection()
data = bitly.shorten('')
assert data is not None
assert data['long_url'] == ''
assert data['hash'] is not None
def testExpand():
bitly = get_connection()
data = bitly.expand(hash='test1_random_fjslfjieljfklsjflkas')
assert data is not None
assert len(data) == 1
assert data[0]['error'] == 'NOT_FOUND'
def testReferrer():
bitly = get_connection()
data = bitly.referrers(hash='a')
assert data is not None
assert len(data) > 1
def testProDomain():
bitly = get_connection()
test_data = {
'': False,
'': True,
'': False,
'': False,
'': True,
for domain in test_data:
result = bitly.pro_domain(domain)
assert result == test_data[domain], domain
except bitly_api.BitlyError as e:
assert str(e) == test_data[domain]
def testUserInfo():
bitly = get_connection()
data = bitly.user_info()
assert data is not None
assert 'login' in data