Skip to content

Commit

Permalink
test: fix DraftFormTest setup (#7828)
Browse files Browse the repository at this point in the history
* test: fix DraftFormTest setup

Tests were failing when the doc factories started
producing pks >= 10 because of an incorrect test
data structure.

* chore: improve comments
  • Loading branch information
jennifer-richards authored Aug 15, 2024
1 parent 00d6143 commit bb0b342
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ietf/ipr/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,12 +943,14 @@ class DraftFormTests(TestCase):
def setUp(self):
super().setUp()
self.disclosure = IprDisclosureBaseFactory()
self.draft = WgDraftFactory()
self.draft = WgDraftFactory.create_batch(10)[-1]
self.rfc = RfcFactory()

def test_revisions_valid(self):
post_data = {
"document": str(self.draft.pk),
# n.b., "document" is a SearchableDocumentField, which is a multiple choice field limited
# to a single choice. Its value must be an array of pks with one element.
"document": [str(self.draft.pk)],
"disclosure": str(self.disclosure.pk),
}
# The revisions field is just a char field that allows descriptions of the applicable
Expand All @@ -960,7 +962,7 @@ def test_revisions_valid(self):
self.assertTrue(DraftForm(post_data | {"revisions": "01,03, 05"}).is_valid())
self.assertTrue(DraftForm(post_data | {"revisions": "all but 01"}).is_valid())
# RFC instead of draft - allow empty / missing revisions
post_data["document"] = str(self.rfc.pk)
post_data["document"] = [str(self.rfc.pk)]
self.assertTrue(DraftForm(post_data).is_valid())
self.assertTrue(DraftForm(post_data | {"revisions": ""}).is_valid())

Expand All @@ -971,7 +973,9 @@ def test_revisions_invalid(self):
null_char_error_msg = "Null characters are not allowed."

post_data = {
"document": str(self.draft.pk),
# n.b., "document" is a SearchableDocumentField, which is a multiple choice field limited
# to a single choice. Its value must be an array of pks with one element.
"document": [str(self.draft.pk)],
"disclosure": str(self.disclosure.pk),
}
self.assertFormError(
Expand All @@ -987,7 +991,7 @@ def test_revisions_invalid(self):
)
# RFC instead of draft still validates the revisions field
self.assertFormError(
DraftForm(post_data | {"document": str(self.rfc.pk), "revisions": "1\x00"}),
DraftForm(post_data | {"document": [str(self.rfc.pk)], "revisions": "1\x00"}),
"revisions",
null_char_error_msg,
)

0 comments on commit bb0b342

Please sign in to comment.