summaryrefslogtreecommitdiffstats
path: root/proxy/code/scripts/test-testapi.py
blob: 518ecf56609cf580d18e19a7362338647e830077 (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
#!/usr/bin/python

import httplib, urllib
import sys
import simplejson as json

if len(sys.argv) < 1:
    print("please supply a message")
    sys.exit(1)

print("------------ TESTING json create")
parent = {"name":"parentname","uuid":"parentuuid","stringList":["string3", "string4"]}
params = {"name":"now","uuid":"thiswork","stringList":["string1", "string2"],"parent":parent}
print(type(params['stringList']))
headers = {"Content-type":"application/json",
           "Accept": "application/json"}
conn = httplib.HTTPConnection("localhost", 8080)
print("creating object with %s" % params)
conn.request("POST", '/candlepin/test/', json.dumps(params), headers)
response = conn.getresponse()
print("Status: %d Response: %s" % (response.status, response.reason))
rsp = response.read()
conn.close()
print("------------ TESTING json get")
response = urllib.urlopen("http://localhost:8080/candlepin/test/")
rsp = response.read()
print("testjsonobject get: %s" % rsp)