CDR Tickets

Issue Number 4810
Summary Detect failure when looking up Drupal node ID for PDQ summary
Created 2020-04-14 07:22:12
Issue Type Bug
Submitted By Kline, Bob (NIH/NCI) [C]
Assigned To Kline, Bob (NIH/NCI) [C]
Status Closed
Resolved 2020-04-20 18:40:20
Resolution Fixed
Path /home/bkline/backups/jira/ocecdr/issue.260155
Description

The DrupalClient.lookup() method currently returns None if response.ok is False. It should instead check response.status_code and return None if the code is 404. Otherwise if response.ok is False an exception should be raised, logging the ID which was being looked up, the HTTP code, and the value of response.reason.

Comment entered 2020-04-20 18:40:20 by Kline, Bob (NIH/NCI) [C]

Installed on DEV. Test below confirms that the client.lookup() method behaves correctly in all three expected conditions:

  1. A CDR ID is passed for a PDQ document on the Drupal server

  2. A CDR ID is passed that is not found on the Drupal server

  3. A server-side failure occurs

from cdrapi.publishing import DrupalClient
from cdrapi.settings import Tier
from cdrapi.users import Session

USER = "cdroperator"
PASS = Tier().passwords[USER]
SESSION = Session.create_session(USER, password=PASS)

client = DrupalClient(SESSION)
catalog = client.list()
if catalog:
    entry = catalog.pop()
    assert(client.lookup(entry.cdr_id) == entry.nid)
    print("    Lookup of a known CDR document's node ID: OK")
else:
    print(f"             No PDQ content on {client.base}: FAIL")
assert(client.lookup(999999999) is None)
print("       Lookup of a bogus CDR ID returns None: OK")
client = DrupalClient(SESSION, base="https://very-bogus-site.comical")
try:
    client.lookup(entry.cdr_id)
    print("Failure to connect to bogus URL not detected: FAIL")
except Exception as e:
    print("    Failure to connect to bogus URL detected: OK")
$ ./test-lookup.py
    Lookup of a known CDR document's node ID: OK
       Lookup of a bogus CDR ID returns None: OK
    Failure to connect to bogus URL detected: OK

Elapsed: 0:00:00.001425