Scott Baker | 438ea11 | 2014-10-07 00:10:41 -0700 | [diff] [blame] | 1 | import json |
| 2 | import os |
| 3 | import requests |
| 4 | import sys |
| 5 | |
| 6 | from operator import itemgetter, attrgetter |
| 7 | |
Scott Baker | 5101d4d | 2015-02-04 15:19:16 -0800 | [diff] [blame] | 8 | REST_API="http://node43.princeton.vicci.org:8000/xos/" |
Scott Baker | 438ea11 | 2014-10-07 00:10:41 -0700 | [diff] [blame] | 9 | USERS_API = REST_API + "users/" |
| 10 | |
| 11 | username = sys.argv[1] |
| 12 | password = sys.argv[2] |
| 13 | |
| 14 | opencloud_auth=(username, password) |
| 15 | |
| 16 | admin_auth=("scott@onlab.us", "letmein") |
| 17 | |
| 18 | print "users I can see:" |
| 19 | r = requests.get(USERS_API + "?email=%s" % username, auth=opencloud_auth) |
| 20 | for user in r.json(): |
| 21 | print " ", user["email"] |
| 22 | |
| 23 | myself = r.json()[0] |
| 24 | |
| 25 | if myself["phone"] == "123": |
| 26 | myself["phone"] = "456" |
| 27 | else: |
| 28 | myself["phone"] = "123" |
| 29 | |
| 30 | r = requests.put(USERS_API + str(myself["id"]) +"/", data=myself, auth=opencloud_auth) |
| 31 | if r.status_code == 200: |
| 32 | print "I updated my phone to", myself["phone"] |
| 33 | else: |
| 34 | print "I failed to update my phone" |
| 35 | |
| 36 | if myself["is_admin"] == True: |
| 37 | myself["is_admin"] = False |
| 38 | else: |
| 39 | myself["is_admin"] = True |
| 40 | |
| 41 | r = requests.put(USERS_API + str(myself["id"]) +"/", data=myself, auth=opencloud_auth) |
| 42 | if r.status_code == 200: |
| 43 | print "I updated my is_admin to", myself["is_admin"] |
| 44 | else: |
| 45 | print "I failed to update my is_admin" |
| 46 | |
| 47 | r = requests.get(USERS_API + "?email=jhh@cs.arizona.edu", auth=opencloud_auth) |
| 48 | if len(r.json())>0: |
| 49 | print "I was able to read jhh@cs.arizona.edu" |
| 50 | else: |
| 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 |
| 54 | r = requests.get(USERS_API + "?email=jhh@cs.arizona.edu", auth=admin_auth) |
| 55 | if len(r.json())>0: |
| 56 | print "Admin was able to read jhh@cs.arizona.edu" |
| 57 | jhh = r.json()[0] |
| 58 | else: |
| 59 | print "ADmin was not able to read jhh@cs.arizona.edu" |
| 60 | jhh = None |
| 61 | |
| 62 | if 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 | |