summaryrefslogtreecommitdiffstats
path: root/proxy/code/scripts/test-userapi.py
blob: fc4c8f7063520f9483e76db84fed9bfae6b58cdd (plain)
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
#!/usr/bin/python

import httplib, urllib
import sys
import simplejson as json

# POST new user
params = urllib.urlencode({"login":"testapi","password":"sw3etnothings"})
headers = {"Content-type":"application/json",
           "Accept": "application/json"}
conn = httplib.HTTPConnection("localhost", 8080)
print("params: %s" % json.dumps(params))
conn.request("POST", '/candlepin/user/', params, headers)
response = conn.getresponse()
print("Status: %d Response: %s" % (response.status, response.reason))
rsp = response.read()
conn.close()


# GET testapi user
response = urllib.urlopen('http://localhost:8080/candlepin/user/testapi')
rsp = response.read()
print("get: %s" % rsp)

# GET list of users
response = urllib.urlopen('http://localhost:8080/candlepin/user/')
rsp = response.read()
users = json.loads(rsp)
print("list of users ----------------")
for user in users['user']:
    print(user)