Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IntegrityError and make CoC agreement required #2593

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 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 Expand Up @@ -257,6 +262,7 @@ def clean_eventbrite_url(self):
eventbrite_url = self.cleaned_data.get("eventbrite_url", "")
if eventbrite_url and "eventbrite" not in urlparse(eventbrite_url).hostname:
raise ValidationError("Must be an Eventbrite URL.")
return eventbrite_url

def clean(self):
super().clean()
Expand Down
18 changes: 18 additions & 0 deletions amy/extforms/tests/test_training_request_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setUp(self):
self.data = {
"review_process": "preapproved",
"member_code": "coolprogrammers",
"eventbrite_url": "https://www.eventbrite.com/e/711576483417",
"personal": "John",
"family": "Smith",
"email": "[email protected]",
Expand Down Expand Up @@ -510,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."]
)