LP1776736 Record merge marc edit repairs
[Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / acq_fund.py
1 #!/usr/bin/python
2 import sys
3 import oils.system, oils.utils.utils
4 import osrf.net_obj, osrf.ses
5
6 # ---------------------------------------------------------------
7 # Usage: python acq_fund_source.py <user> <password> <workstation> 
8 # ---------------------------------------------------------------
9
10 oils.system.System.connect(config_file='/openils/conf/opensrf_core.xml', config_context='config.opensrf')
11 auth_info = oils.utils.utils.login(sys.argv[1], sys.argv[2], 'staff', sys.argv[3])
12 authtoken = auth_info['payload']['authtoken']
13
14 ses = osrf.ses.ClientSession('open-ils.acq')
15 ses.connect() # not required, but faster for batches of request
16
17 # XXX This loop assumes the existence of orgs with IDs 1-6 and a USD currency
18 ids = []
19 for i in range(0,5):
20     fund_source = osrf.net_obj.NetworkObject.acqfs()
21     fund_source.name("test-fund_source-%d" % i)
22     fund_source.owner(i+1)
23     fund_source.currency_type('USD')
24     req = ses.request('open-ils.acq.funding_source.create', authtoken, fund_source)
25     id = req.recv().content()
26     print 'created fund_source ' + str(id)
27     ids.append(id)
28
29 req = ses.request('open-ils.acq.funding_source.org.retrieve', authtoken, 1, {"children":1})
30 resp = req.recv().content()
31 for fund_source in resp:
32     print 'fetched fund_source ' + str(fund_source.name())
33
34 for i in ids:
35     req = ses.request('open-ils.acq.funding_source.delete', authtoken, i)
36     print 'delete returned ' + str(req.recv().content())
37
38
39 ses.disconnect() # only required if a connect() call was made
40
41