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 |
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
.
Installed on DEV. Test below confirms that the
client.lookup()
method behaves correctly in all three
expected conditions:
A CDR ID is passed for a PDQ document on the Drupal server
A CDR ID is passed that is not found on the Drupal server
A server-side failure occurs
from cdrapi.publishing import DrupalClient
from cdrapi.settings import Tier
from cdrapi.users import Session
= "cdroperator"
USER = Tier().passwords[USER]
PASS = Session.create_session(USER, password=PASS)
SESSION
= DrupalClient(SESSION)
client = client.list()
catalog if catalog:
= catalog.pop()
entry 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")
= DrupalClient(SESSION, base="https://very-bogus-site.comical")
client 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