blob: 1b5c41b49f4deec84187d905e9a557cb2c6c8e12 [file] [log] [blame]
Scott Baker33ad9ad2014-10-07 00:10:41 -07001import json
2import os
3import requests
4import sys
5
6from operator import itemgetter, attrgetter
7
8REST_API="http://node43.princeton.vicci.org:8000/plstackapi/"
9USERS_API = REST_API + "users/"
10
11username = sys.argv[1]
12password = sys.argv[2]
13
14opencloud_auth=(username, password)
15
16admin_auth=("scott@onlab.us", "letmein")
17
18print "users I can see:"
19r = requests.get(USERS_API + "?email=%s" % username, auth=opencloud_auth)
20for user in r.json():
21 print " ", user["email"]
22
23myself = r.json()[0]
24
25if myself["phone"] == "123":
26 myself["phone"] = "456"
27else:
28 myself["phone"] = "123"
29
30r = requests.put(USERS_API + str(myself["id"]) +"/", data=myself, auth=opencloud_auth)
31if r.status_code == 200:
32 print "I updated my phone to", myself["phone"]
33else:
34 print "I failed to update my phone"
35
36if myself["is_admin"] == True:
37 myself["is_admin"] = False
38else:
39 myself["is_admin"] = True
40
41r = requests.put(USERS_API + str(myself["id"]) +"/", data=myself, auth=opencloud_auth)
42if r.status_code == 200:
43 print "I updated my is_admin to", myself["is_admin"]
44else:
45 print "I failed to update my is_admin"
46
47r = requests.get(USERS_API + "?email=jhh@cs.arizona.edu", auth=opencloud_auth)
48if len(r.json())>0:
49 print "I was able to read jhh@cs.arizona.edu"
50else:
51 print "I was not able to read jhh@cs.arizona.edu"
52
53# get john's record using admin, so we can try to update it
54r = requests.get(USERS_API + "?email=jhh@cs.arizona.edu", auth=admin_auth)
55if len(r.json())>0:
56 print "Admin was able to read jhh@cs.arizona.edu"
57 jhh = r.json()[0]
58else:
59 print "ADmin was not able to read jhh@cs.arizona.edu"
60 jhh = None
61
62if jhh:
63 # try to update john's user record
64 r = requests.put(USERS_API + str(jhh["id"]) + "/", data=jhh, auth=opencloud_auth)
65 if r.status_code == 200:
66 print "I was able to update user", str(jhh["id"])
67 else:
68 print "I was not able to update user", str(jhh["id"])
69
70
71
72