JBAS-449 SIP test scripts and sample config
authorBill Erickson <berickxx@gmail.com>
Fri, 6 Feb 2015 19:14:48 +0000 (14:14 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
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 <berickxx@gmail.com>
Conflicts:
.gitignore

Conflicts:
.gitignore

.gitignore
KCLS/test-scripts/sip/README.asciidoc [new file with mode: 0644]
KCLS/test-scripts/sip/pysip2-client.ini.example [new file with mode: 0644]
KCLS/test-scripts/sip/sip-checkout-checkin.py [new file with mode: 0755]
KCLS/test-scripts/sip/sip-read-only.py [new file with mode: 0755]

index bfcf501..fd8a391 100644 (file)
@@ -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 (file)
index 0000000..44700e5
--- /dev/null
@@ -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 (file)
index 0000000..55f308a
--- /dev/null
@@ -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 (executable)
index 0000000..b9faac1
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/python3
+# -----------------------------------------------------------------------
+# Copyright (C) 2015 King County Library System
+# Bill Erickson <berickxx@gmail.com>
+# 
+# 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 (executable)
index 0000000..c498eaa
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/python3
+# -----------------------------------------------------------------------
+# Copyright (C) 2015 King County Library System
+# Bill Erickson <berickxx@gmail.com>
+# 
+# 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()