From 1c1d1eaff8edf944c28e940df2b60e2b54550a6e Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Tue, 4 Jun 2024 10:44:31 -0300 Subject: [PATCH] Fix ODL License status document checks (PP-1331) (#1885) * ODL logging is making loans fail when the response code is 201. * Fix log message * Fix status code * Code review feedback. --- src/palace/manager/api/odl.py | 4 ++-- tests/manager/api/test_odl.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/palace/manager/api/odl.py b/src/palace/manager/api/odl.py index b6e95a2fb5..413b62dfdb 100644 --- a/src/palace/manager/api/odl.py +++ b/src/palace/manager/api/odl.py @@ -330,7 +330,7 @@ def get_license_status_document(self, loan: Loan) -> dict[str, Any]: ) response = self._get(url) - if response.status_code != 200: + if not (200 <= response.status_code < 300): header_string = ", ".join( {f"{k}: {v}" for k, v in response.headers.items()} ) @@ -341,7 +341,7 @@ def get_license_status_document(self, loan: Loan) -> dict[str, Any]: ) self.log.error( f"Error getting License Status Document for loan ({loan.id}): Url '{url}' returned " - f"status code {response.status_code}. Expected 200. Response headers: {header_string}. " + f"status code {response.status_code}. Expected 2XX. Response headers: {header_string}. " f"Response content: {response_string}." ) raise BadResponseException(url, "License Status Document request failed.") diff --git a/tests/manager/api/test_odl.py b/tests/manager/api/test_odl.py index 582726141d..f2664c69f0 100644 --- a/tests/manager/api/test_odl.py +++ b/tests/manager/api/test_odl.py @@ -52,10 +52,10 @@ class TestODLAPI: def test_get_license_status_document_success( self, odl_api_test_fixture: ODLAPITestFixture ) -> None: - # With a new loan. + # With a new loan. New loan returns a 201 status. loan, _ = odl_api_test_fixture.license.loan_to(odl_api_test_fixture.patron) odl_api_test_fixture.api.queue_response( - 200, content=json.dumps(dict(status="ready")) + 201, content=json.dumps(dict(status="ready")) ) odl_api_test_fixture.api.get_license_status_document(loan) requested_url = odl_api_test_fixture.api.requests[0][0] @@ -101,7 +101,7 @@ def test_get_license_status_document_success( == notification_url ) - # With an existing loan. + # With an existing loan. Existing loan returns a 200 status. loan, _ = odl_api_test_fixture.license.loan_to(odl_api_test_fixture.patron) loan.external_identifier = odl_api_test_fixture.db.fresh_str() @@ -139,7 +139,7 @@ def test_get_license_status_document_errors( odl_api_test_fixture.api.get_license_status_document, loan, ) - assert "returned status code 403. Expected 200." in caplog.text + assert "returned status code 403. Expected 2XX." in caplog.text assert "just junk ..." in caplog.text def test_checkin_success(