Skip to content

Commit

Permalink
[#2585] make CoC question required
Browse files Browse the repository at this point in the history
  • Loading branch information
elichad committed Nov 28, 2023
1 parent 62536b9 commit 8a1cb70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions amy/extforms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class TrainingRequestForm(forms.ModelForm):

helper = BootstrapHelper(wider_labels=True, add_cancel_button=False)

code_of_conduct_agreement = forms.BooleanField(
required=True,
label=TrainingRequest._meta.get_field("code_of_conduct_agreement").verbose_name,
)

class Meta:
model = TrainingRequest
fields = (
Expand Down
17 changes: 17 additions & 0 deletions amy/extforms/tests/test_training_request_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,20 @@ def test_eventbrite_url_validation__valid(self):
# Assert
self.assertEqual(rv.status_code, 200)
self.assertNotContains(rv, self.INVALID_EVENTBRITE_URL_ERROR)

def test_coc_agreement_required(self):
"""Should error if CoC checkbox is not ticked."""
# Arrange
self.setUpMembership()
data = {"code_of_conduct_agreement": "false"}

# Act
rv = self.client.post(reverse("training_request"), data=data)
errors = dict(rv.context["form"].errors)

# Assert
self.assertEqual(rv.status_code, 200)
self.assertIn("code_of_conduct_agreement", errors)
self.assertListEqual(
errors["code_of_conduct_agreement"], ["This field is required."]
)

0 comments on commit 8a1cb70

Please sign in to comment.