Skip to content

Commit

Permalink
feat(corpus_importer): Improve error message for appellate purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Jan 25, 2025
1 parent 1b184ae commit 1218b96
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cl/corpus_importer/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2217,8 +2217,13 @@ def update_rd_metadata(

rd = RECAPDocument.objects.get(pk=rd_pk)
if pdf_bytes is None:
if r_msg:
# Send a specific message all the way from Juriscraper
if r_msg and "An attachment page was returned instead" in r_msg:
msg = (
"This PACER document is part of an attachment page. "
"Our system currently lacks the metadata for this attachment. "
"Please purchase the attachment page and try again."
)
elif r_msg:
msg = f"{r_msg}: {court_id=}, {rd_pk=}"
else:
msg = (
Expand Down
31 changes: 31 additions & 0 deletions cl/recap/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,37 @@ def test_handle_failed_purchases(
self.fq.message,
)

@mock.patch(
"cl.recap.tasks.download_pacer_pdf_by_rd",
return_value=(
None,
"Unable to download PDF. An attachment page was returned instead.",
),
)
def test_add_custom_message_for_attachment_pages(
self, mock_download_method, mock_court_accessible, mock_get_cookies
):
"""
Checks if a custom message is added when the download_pacer_pdf_by_rd
function returns an error indicating an attachment page was found
instead of a PDF.
"""
self.appellate_rd.is_available = False
self.appellate_rd.save()

self.assertFalse(self.appellate_rd.is_available)
fetch_pacer_doc_by_rd(self.appellate_rd.pk, self.appellate_fq.pk)

self.appellate_fq.refresh_from_db()
self.assertEqual(self.appellate_fq.status, PROCESSING_STATUS.FAILED)

error_msg = (
"This PACER document is part of an attachment page. "
"Our system currently lacks the metadata for this attachment. "
"Please purchase the attachment page and try again."
)
self.assertEqual(error_msg, self.appellate_fq.message)


@mock.patch(
"cl.recap.tasks.is_pacer_court_accessible",
Expand Down

0 comments on commit 1218b96

Please sign in to comment.