From: Bill Erickson Date: Fri, 6 Feb 2015 19:14:48 +0000 (-0500) Subject: JBAS-449 SIP test scripts and sample config X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6f5a9a357b4e604e57a073a6507f8a6dcde367d1;p=working%2FEvergreen.git JBAS-449 SIP test scripts and sample config sip-read-only.py -- item info, patron info, and patron status messages sip-checkout-checkin.py -- checkout out and back in copes pysip2-client.ini.example -- sample configuration file README.asciidoc -- usage Signed-off-by: Bill Erickson Conflicts: .gitignore Conflicts: .gitignore --- diff --git a/.gitignore b/.gitignore index bfcf501cf7..fd8a391f4d 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,5 @@ Open-ILS/web/js/ui/default/staff/build/ Open-ILS/web/js/ui/default/staff/node_modules/ Open-ILS/web/js/ui/default/staff/bower_components/ Open-ILS/web/js/ui/default/common/build/ +KCLS/test-scripts/sip/pysip2-client.ini Open-ILS/web/eg2/ diff --git a/KCLS/test-scripts/sip/README.asciidoc b/KCLS/test-scripts/sip/README.asciidoc new file mode 100644 index 0000000000..44700e5b0f --- /dev/null +++ b/KCLS/test-scripts/sip/README.asciidoc @@ -0,0 +1,24 @@ += SIP Test Scripts + +== Edit configuration file + + * Make a local copy of the configuration file and edit the + variables along the top of the file (sip server address, etc.) + +[source,sh] +------------------------------------------------------------------------ +cp pysip2-client.ini.example pysip2-client.ini +------------------------------------------------------------------------ + +== + + * Clone the python SIP client library and run one of the scripts + +[source,sh] +------------------------------------------------------------------------ +cd $SOMEWHERE +git clone https://github.com/berick/pysip2.git +cd $EVERGREEN/KCLS/test-scripts/sip +PYTHONPATH=$SOMEWHERE/pysip2/src ./sip-read-only.py +------------------------------------------------------------------------ + diff --git a/KCLS/test-scripts/sip/pysip2-client.ini.example b/KCLS/test-scripts/sip/pysip2-client.ini.example new file mode 100644 index 0000000000..55f308a8a0 --- /dev/null +++ b/KCLS/test-scripts/sip/pysip2-client.ini.example @@ -0,0 +1,38 @@ +[client] +server=testing-sip01.eg.kcls.org +port=6001 +institution=kcls +# SIP login username +username=USERNAME +# SIP login password +password=PASSWORD +# Physical location (org unit code) +location_code=PR + +[loggers] +keys=root + +[handlers] +keys=consoleHandler + +[formatters] +keys=simpleFormatter + +[logger_root] +level=DEBUG +handlers=consoleHandler + +[handler_consoleHandler] +class=StreamHandler +level=DEBUG +formatter=simpleFormatter +args=(sys.stdout,) + +[formatter_simpleFormatter] +format=%(asctime)s %(levelname)s: %(message)s + +[test-data] +item_info_barcodes=2096622929,2094495716,2094346257,2085657597,2080769314,2079986663,2066827730,2054862103,2043256946 +patron_info_barcodes=0013043898,0013041520,0013041504,0013041736,0013041751,0013043088,0013043302,0035383082,0036215069,0038966917 +checkout_copies=2096622929 +checkout_patron=0013043898 diff --git a/KCLS/test-scripts/sip/sip-checkout-checkin.py b/KCLS/test-scripts/sip/sip-checkout-checkin.py new file mode 100755 index 0000000000..b9faac1326 --- /dev/null +++ b/KCLS/test-scripts/sip/sip-checkout-checkin.py @@ -0,0 +1,73 @@ +#!/usr/bin/python3 +# ----------------------------------------------------------------------- +# Copyright (C) 2015 King County Library System +# Bill Erickson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# ----------------------------------------------------------------------- +import sys, logging, logging.config, getopt, configparser +import pysip2.client + +logging.config.fileConfig('pysip2-client.ini') +config = configparser.ConfigParser() +config.read('pysip2-client.ini') + +server = config['client']['server'] +port = config['client']['port'] +institution = config['client']['institution'] +username = config['client']['username'] +password = config['client']['password'] +location_code = config['client']['location_code'] + +client = pysip2.client.Client(server, int(port)) +client.default_institution = institution + +logging.info("connecting to " + server) +try: + client.connect() +except Error as err: + logging.error("Unable to connect to server %s : %s" % (server, str(err))) + sys.exit(1) + +logging.info("logging in as " + username) +if not client.login(username, password, location_code): + logging.error("Login failed for %s @ %s" % (username, server)) + sys.exit(1) + +checkout_copies = config['test-data'].get('checkout_copies', '').split(',') +checkout_patron = config['test-data'].get('checkout_patron') + +if checkout_patron is not None: + for copy in checkout_copies: + + # checkout + resp = client.checkout_request(copy, checkout_patron) + if resp.get_fixed_field_by_name('ok').value == '1': + # checkout OK + logging.info("checkout %s succeeded" % copy) + + else: + # checkout failed + logging.info("checkout %s failed" % copy) + logging.info("failed checkout response: \n" + repr(resp)) + + # checkin + resp = client.checkin_request(copy, location_code) + if resp.get_fixed_field_by_name('ok').value == '1': + # checkin OK + logging.info("checkin %s succeeded" % copy) + else: + # checkin failed + logging.info("checkin %s failed") + logging.info("failed checkin response: \n" + repr(resp)) + +client.disconnect() +client.log_summary() diff --git a/KCLS/test-scripts/sip/sip-read-only.py b/KCLS/test-scripts/sip/sip-read-only.py new file mode 100755 index 0000000000..c498eaaa14 --- /dev/null +++ b/KCLS/test-scripts/sip/sip-read-only.py @@ -0,0 +1,83 @@ +#!/usr/bin/python3 +# ----------------------------------------------------------------------- +# Copyright (C) 2015 King County Library System +# Bill Erickson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# ----------------------------------------------------------------------- + +# ----------------------------------------------------------------------- +# Sends a series of read-only requests (item info, patron info, etc.) +# to the configured SIP server. It does not send any requests which +# modify data on the server (checkouts, etc.) +# ----------------------------------------------------------------------- +import sys, logging, logging.config, getopt, configparser +import pysip2.client + +logging.config.fileConfig('pysip2-client.ini') +config = configparser.ConfigParser() +config.read('pysip2-client.ini') + +server = config['client']['server'] +port = config['client']['port'] +institution = config['client']['institution'] +username = config['client']['username'] +password = config['client']['password'] +location_code = config['client']['location_code'] + +client = pysip2.client.Client(server, int(port)) +client.default_institution = institution + +logging.info("connecting to " + server) +try: + client.connect() +except Error as err: + logging.error("Unable to connect to server %s : %s" % (server, str(err))) + sys.exit(1) + +logging.info("logging in as " + username) +if not client.login(username, password, location_code): + logging.error("Login failed for %s @ %s" % (username, server)) + sys.exit(1) + +stat = client.sc_status() +if stat.fixed_fields[0].value == 'Y': + logging.info("SIP server is online") +else: + logging.info("Status message reports SIP server is NOT online") + +# item information requests +for barcode in config['test-data']['item_info_barcodes'].split(','): + resp = client.item_info_request(barcode) + logging.info("item info completed for %s => %s" % ( + resp.get_field_by_code('AB').value, + resp.get_field_by_code('AJ').value + )) + +# patron information requests +for barcode in config['test-data']['patron_info_barcodes'].split(','): + + resp = client.patron_info_request(barcode) + logging.info("patron info completed for [valid=%s] %s => %s" % ( + resp.get_field_by_code('BL').value, + resp.get_field_by_code('AA').value, + resp.get_field_by_code('AE').value, + )) + + resp = client.patron_status_request(barcode) + logging.info("patron stat completed for [valid=%s] %s => %s" % ( + resp.get_field_by_code('BL').value, + resp.get_field_by_code('AA').value, + resp.get_field_by_code('AE').value + )) + +client.disconnect() +client.log_summary()