SIP Fines/fees retrieval test
authorBill Erickson <berickxx@gmail.com>
Mon, 13 May 2019 14:42:44 +0000 (10:42 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 13 May 2019 14:43:13 +0000 (10:43 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/test-scripts/sip/sip-fines.py [new file with mode: 0755]

diff --git a/KCLS/test-scripts/sip/sip-fines.py b/KCLS/test-scripts/sip/sip-fines.py
new file mode 100755 (executable)
index 0000000..3a58195
--- /dev/null
@@ -0,0 +1,64 @@
+#!/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 Exception 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")
+
+# patron information requests
+for barcode in config['test-data']['patron_info_barcodes'].split(','):
+
+    resp = client.patron_info_request(barcode, summary = '   Y      ')
+    logging.info(repr(resp))
+
+client.disconnect()
+client.log_summary()