Skip to content

Commit

Permalink
test(RECAPDocument): add validation tests for attachment_number in cl…
Browse files Browse the repository at this point in the history
…ean method

- Added tests to verify that attachments must have an attachment_number.
- Ensured main PACER documents do not have an attachment_number.
- Checked that appropriate ValidationErrors are raised with correct messages.
- Confirmed that valid scenarios save without errors.
  • Loading branch information
elisa-a-v committed Nov 18, 2024
1 parent cf1ce0d commit 2b6684c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions cl/search/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,60 @@ def test_cannot_create_duplicate(self) -> None:
)


class RECAPDocumentValidationTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.docket_entry = DocketEntryWithParentsFactory()

def test_attachment_with_attachment_number(self):
"""Attachments with attachment_number should not raise ValidationError."""
document = RECAPDocument.objects.create(
docket_entry=self.docket_entry,
document_type=RECAPDocument.ATTACHMENT,
attachment_number=1,
)
self.assertIsNotNone(document.id)

def test_attachment_without_attachment_number(self):
"""Attachments without attachment_number should raise ValidationError."""
with self.assertRaises(ValidationError) as cm:
RECAPDocument.objects.create(
docket_entry=self.docket_entry,
document_type=RECAPDocument.ATTACHMENT,
attachment_number=None,
)
# Assert that the error message is as expected
self.assertIn("attachment_number", cm.exception.message_dict)
self.assertEqual(
cm.exception.message_dict["attachment_number"],
["attachment_number cannot be null for an attachment."],
)

def test_main_document_with_attachment_number(self):
"""Main PACER documents with attachment_number should raise ValidationError."""
with self.assertRaises(ValidationError) as cm:
RECAPDocument.objects.create(
docket_entry=self.docket_entry,
document_type=RECAPDocument.PACER_DOCUMENT,
attachment_number=1,
)
# Assert that the error message is as expected
self.assertIn("attachment_number", cm.exception.message_dict)
self.assertEqual(
cm.exception.message_dict["attachment_number"],
["attachment_number must be null for a main PACER document."],
)

def test_main_document_without_attachment_number(self):
"""Main PACER documents without attachment_number should not raise ValidationError."""
document = RECAPDocument.objects.create(
docket_entry=self.docket_entry,
document_type=RECAPDocument.PACER_DOCUMENT,
attachment_number=None,
)
self.assertIsNotNone(document.id)


class IndexingTest(EmptySolrTestCase):
"""Are things indexed properly?"""

Expand Down

0 comments on commit 2b6684c

Please sign in to comment.