Skip to content

Commit

Permalink
Merge pull request #4086 from freelawproject/4084-adds-logic-to-check…
Browse files Browse the repository at this point in the history
…-court-from-rd

feat(recap): Refines validate method in the PacerFetchQueue serializer
  • Loading branch information
mlissner authored May 29, 2024
2 parents 596b59b + fc7984f commit 7aac706
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
20 changes: 14 additions & 6 deletions cl/recap/api_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,21 @@ def validate(self, attrs):
"pk", flat=True
)

if attrs.get("court") or attrs.get("docket"):
if (
attrs.get("court")
or attrs.get("docket")
or attrs.get("recap_document")
):
# this check ensures the docket is not an appellate record.
court_id = (
attrs["court"].pk
if attrs.get("court")
else attrs["docket"].court_id
)
if attrs.get("recap_document"):
rd = attrs["recap_document"]
court_id = rd.docket_entry.docket.court_id
else:
court_id = (
attrs["court"].pk
if attrs.get("court")
else attrs["docket"].court_id
)
if court_id not in valid_court_ids:
raise ValidationError(f"Invalid court id: {court_id}")

Expand Down
24 changes: 23 additions & 1 deletion cl/recap/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ def test_recap_fetch_validate_pacer_case_id(self, mock):
)

def test_recap_fetch_validate_court(self, mock):
"""Can we properly validate the court_id"""
"""Can we properly validate the court_id?"""

appellate_docket = DocketFactory(
source=Docket.RECAP,
Expand Down Expand Up @@ -883,6 +883,28 @@ def test_recap_fetch_validate_court(self, mock):
"Invalid court id: ca11",
)

def test_recap_fetch_validate_court_of_rd(self, mock) -> None:
"""Can we validate the court when fetching a PDF?"""
rd = RECAPDocumentFactory.create(
docket_entry=DocketEntryWithParentsFactory(
docket__court=self.court_appellate
),
)

del self.fetch_attributes["docket_id"]
self.fetch_attributes["request_type"] = REQUEST_TYPE.PDF
self.fetch_attributes["recap_document"] = rd.pk

serialized_fq = PacerFetchQueueSerializer(
data=self.fetch_attributes,
context={"request": self.request},
)
serialized_fq.is_valid()
self.assertIn(
serialized_fq.errors["non_field_errors"][0],
"Invalid court id: ca11",
)

def test_key_serialization_with_client_code(self, mock) -> None:
"""Does the API have the fields we expect?"""
self.fetch_attributes["client_code"] = "pauledgecomb"
Expand Down

0 comments on commit 7aac706

Please sign in to comment.