This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
/
test.py
75 lines (54 loc) · 2.07 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
sys.path.insert(0, os.path.abspath('../../lib'))
from test_oauth_client import TestOAuthClient
from oauth import OAuthToken
import time
# This is a quick, gross little interactive script for testing our OAuth API.
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
SERVER_URL = ""
REQUEST_TOKEN = None
ACCESS_TOKEN = None
def get_request_token():
global REQUEST_TOKEN
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
client.start_fetch_request_token()
print "After logging in and authorizing, input token key and secret..."
request_token_key = raw_input("request token: ")
request_token_secret = raw_input("request token secret: ")
REQUEST_TOKEN = OAuthToken(request_token_key, request_token_secret)
def get_access_token():
global ACCESS_TOKEN
print "Fetching access token..."
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = client.fetch_access_token(REQUEST_TOKEN)
def get_api_resource():
resource_url = raw_input("Resource relative url (/api/v1/playlists): ") or "/api/v1/playlists"
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
start = time.time()
response = client.access_resource(resource_url, ACCESS_TOKEN)
end = time.time()
print "\n"
print response
print "\nTime: %ss\n" % (end - start)
def run_tests():
global CONSUMER_KEY, CONSUMER_SECRET, SERVER_URL
CONSUMER_KEY = raw_input("consumer key (anyone): ") or "anyone"
CONSUMER_SECRET = raw_input("consumer secret (anyone): ") or "anyone"
SERVER_URL = raw_input("server base url (http://local.kamenstestapp.appspot.com:8084): ") or "http://local.kamenstestapp.appspot.com:8084"
get_request_token()
if not REQUEST_TOKEN:
print "Did not get request token."
return
get_access_token()
if not ACCESS_TOKEN:
print "Did not get access token."
return
while(True):
try:
get_api_resource()
except Exception, e:
print "Error: %s" % e
def main():
run_tests()
if __name__ == "__main__":
main()