summaryrefslogtreecommitdiffstats
path: root/proxy/code/scripts/test-consumerapi.py
blob: 88962451927b92f6e51aef0f1955cc8d3cfc8a30 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python

import httplib, urllib
import sys
import simplejson as json

# POST new user
print("create consumer")
#info = {"parent":"","type":"system","metadata":{"arch":"i386","cpu":"intel"}}
info = {"parent":"","type":"system", "metadata":{"entry":[{"key":"arch","value":"i386"},{"key":"cpu","value":"Intel"}]}}
params = {"owneruuid":"","info":info}
headers = {"Content-type":"application/json",
           "Accept": "application/json"}
conn = httplib.HTTPConnection("localhost", 8080)
conn.request("POST", '/candlepin/consumer/', json.dumps(params), headers)
response = conn.getresponse()
print("Status: %d Response: %s" % (response.status, response.reason))
rsp = response.read()
print("created consumer: %s" % rsp)
conn.close()

# GET list of consumers
response = urllib.urlopen('http://localhost:8080/candlepin/consumer/')
rsp = response.read()
print("list of consumers: %s" % rsp)

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

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

#print("delete consumer")
#conn = httplib.HTTPConnection("localhost", 8080)
#conn.request("DELETE", '/candlepin/consumer/')
#response = conn.getresponse()
#
#print("Status: %d Response: %s" % (response.status, response.reason))
#conn.close()

#print("delete product from consumer")
#conn.request("DELETE", '/candlepin/consumer/%s/product/%s' % ())