This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
/
test_api.py
67 lines (54 loc) · 1.61 KB
/
test_api.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
import urllib
import urllib2
import hashlib
import hmac
import binascii
import requests
import json
KEY = " ahFkZXZ-amVycnktc2VydmljZXIPCxIJQXBwQWNjZXNzGAEM"
SECRET = "b9ff1467f31746fab63e2f8ba4d79059"
BASE_PATH = "/api/v1/"
BASE_URL = "http://localhost:9092" + BASE_PATH
def _sign(method, url, params):
params["_key"] = KEY
encoded = urllib.urlencode(params)
query = "&".join((method.upper(), url, encoded))
encoded += "&_signature=" + urllib.quote(binascii.b2a_base64(
hmac.new(SECRET, query, hashlib.sha256).digest()))
return encoded
def verify_access():
params = {"yay": "other", "second": "yes"}
url = BASE_URL + "verify_access"
full_request = url + "?" + _sign("GET", url, params)
print full_request
req = urllib2.urlopen(full_request)
print req.read()
return req
def get_permission_state():
params = {"device_id": "web", "user_id": None}
url = BASE_URL + "permission_state"
full_request = url + "?" + _sign("GET", url, params)
print full_request
req = urllib2.urlopen(full_request)
print req.read()
return req
def post_log_entry():
data = [
{"action": "upload_photo"},
{"action": "run_app", "quantity": 4},
{"action": "share_picture"}
]
params = {
"device_id": "ASD90384KDOHDKS",
"entries": json.dumps(data)
}
url = BASE_URL + "logger"
req = requests.post(url, data=_sign("POST", url, params))
print req.content
print req.status_code
import pdb
pdb.set_trace()
if __name__ == "__main__":
verify_access()
get_permission_state()
post_log_entry()