From 2a5c931a353bb19d37e1132570f5ee39d0db2c99 Mon Sep 17 00:00:00 2001 From: SueG Date: Mon, 26 Jun 2017 18:59:35 -0400 Subject: [PATCH] issue#29_nautilus_feedback_to_ui (#31) * adding lims error message to driver and unit tests for changes made (#27) * adding lims error message to driver and unit tests for changes made * adding SER : Serum, back into driver * updating version * adding lims error message to driver and unit tests for changes made (#27) * adding lims error message to driver and unit tests for changes made * adding SER : Serum, back into driver * adding error from Nautilus API to Html * adding error message when there is an issue rendering information to the bioRepo UI from LIMS system * adding info to changelog * update unit tests --- CHANGELOG.md | 1 + ehb_datasources/drivers/nautilus/driver.py | 43 +++++++++++++------ .../nautilus/templates/sample_display.html | 7 +++ .../tests/unit_tests/test_nautilus_driver.py | 18 ++++---- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a691948..21aa160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ 1.0.4 * fixing issue8 - driver execption: adding additional nautilius issue mappings * added additional nautlis mappings - 'SER': 'Serum' + * added nautlis error messages to biorepository UI 1.0.3 ----- diff --git a/ehb_datasources/drivers/nautilus/driver.py b/ehb_datasources/drivers/nautilus/driver.py index 3cc114f..2ac6d91 100644 --- a/ehb_datasources/drivers/nautilus/driver.py +++ b/ehb_datasources/drivers/nautilus/driver.py @@ -3,6 +3,7 @@ import json import logging import os +import codecs from collections import OrderedDict import urllib.request, urllib.parse, urllib.error @@ -24,18 +25,17 @@ class ehbDriver(Driver, RequestHandler): NAU_REC_EXT_REF = 'ext-ref' VALID_NAU_ELEM_IDENTIFIERS = [NAU_REC_ID, NAU_REC_NAME, NAU_REC_EXT_REF] NAU_ERROR_MAP = { - '0': 'UNKNOWN ERROR', - '1': 'Unable to login into LIMS', - '2': 'Username not provided', - '3': 'Password not provided', - '4': 'Request type not provided', - '5': 'Request body not provided', - '6': 'Malformed Request', - '7': 'Unsupported request type', - '8': 'Form data is not valid', - '100': 'NAU socket service not found', - '101': 'NAU invalid authorization header' - + '0': 'UNKNOWN ERROR.', + '1': 'Unable to communicate with Laboratory System because of expired or incorrect credentials.', + '2': 'Username not provided.', + '3': 'Password not provided.', + '4': 'Request type not provided.', + '5': 'Request body not provided.', + '6': 'Malformed Request.', + '7': 'Unsupported request type.', + '8': 'Form data is not valid.', + '100': 'NAU socket service not found.', + '101': 'NAU invalid authorization header.' } def __init__(self, url, user, password, secure): @@ -136,8 +136,17 @@ def get_sample_data(self, *args, **kwargs): try: return json.loads(response)[0] except KeyError: - log.error('Error retrieving sample data') - return {"error": "Unable to retrieve sample data"} + try: # grab error number and process error + responseDict = json.loads(response) + status = responseDict['error'] + errorMsg = self.NAU_ERROR_MAP.get(status, 'UNKNOWN ERROR') + log.error(errorMsg) + return {"error": errorMsg} + except TypeError: + pass + except KeyError: + log.error('Error retrieving sample data') + return {"error": "Unable to retrieve sample data"} def extract_aliquots(self, sample_data): aliquots = [] @@ -278,6 +287,12 @@ def subRecordSelectionForm(self, form_url='', record_id='', *args, c = { 'aliquots': aliquots, } + try: # grab error message + errorMsg = (sdg['error']) + c = {'error': errorMsg} + log.error(errorMsg) + except: + pass html = t.render(c) return html diff --git a/ehb_datasources/drivers/nautilus/templates/sample_display.html b/ehb_datasources/drivers/nautilus/templates/sample_display.html index 930e2dc..a841c46 100644 --- a/ehb_datasources/drivers/nautilus/templates/sample_display.html +++ b/ehb_datasources/drivers/nautilus/templates/sample_display.html @@ -11,8 +11,15 @@ {{alq.label}}{% if alq.is_received %} -- Collected On: {{alq.U_COLLECT_DATE_TIME}} -- Received On: {{alq.U_RECEIVED_DATE_TIME}}{% endif %}{{alq.NAME}}{{alq.STATUS|safe}} {% endfor %} + + +{% if error %} + +{% endif %}

diff --git a/ehb_datasources/tests/unit_tests/test_nautilus_driver.py b/ehb_datasources/tests/unit_tests/test_nautilus_driver.py index 2d2ac8a..b4d31c1 100644 --- a/ehb_datasources/tests/unit_tests/test_nautilus_driver.py +++ b/ehb_datasources/tests/unit_tests/test_nautilus_driver.py @@ -243,15 +243,15 @@ def test_process_new_record_form_no_sdg(driver, mocker): examples = (('expected_error_message', 'status_error_num', 'test_comment'), [ # keeping comments blank because 'error message' in this case is sufficient. # Keeping here for best practices in the future. - ('Username not provided', "2", ''), - ('Password not provided', "3", ''), - ('Request type not provided', "4", ''), - ('Request body not provided', "5", ''), - ('Malformed Request', "6", ''), - ('Unsupported request type', "7", ''), - ('Form data is not valid', "8", ''), - ('NAU socket service not found', "100", ''), - ('NAU invalid authorization header', "101", '') + ('Username not provided.', "2", ''), + ('Password not provided.', "3", ''), + ('Request type not provided.', "4", ''), + ('Request body not provided.', "5", ''), + ('Malformed Request.', "6", ''), + ('Unsupported request type.', "7", ''), + ('Form data is not valid.', "8", ''), + ('NAU socket service not found.', "100", ''), + ('NAU invalid authorization header.', "101", '') ])