Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Fixes bug 1097058 - Prevent survey activation without questions
Browse files Browse the repository at this point in the history
  • Loading branch information
bugzPDX committed Nov 26, 2014
1 parent ad8853c commit cb2d715
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion airmozilla/manage/forms.py
Expand Up @@ -439,16 +439,23 @@ class Meta:

def __init__(self, *args, **kwargs):
super(SurveyEditForm, self).__init__(*args, **kwargs)
self.fields['active'].validators.append(self.validate_active)
self.fields['events'].required = False
self.fields['events'].queryset = (
self.fields['events'].queryset.order_by('title')
)

def validate_active(self, value):
if value and not self.instance.question_set.count():
raise forms.ValidationError(
"Survey must have at least one question in order to be active"
)


class SurveyNewForm(BaseModelForm):
class Meta:
model = Survey
fields = ('name', 'active')
fields = ('name', )


class LocationEditForm(BaseModelForm):
Expand Down
13 changes: 13 additions & 0 deletions airmozilla/manage/tests/views/test_surveys.py
Expand Up @@ -120,6 +120,19 @@ def test_edit_survey(self):
response = self.client.get(url)
eq_(response.status_code, 200)
ok_('value="Name"' in response.content)
# check for error trying to activate with no questions
response = self.client.post(url, {
'active': True
})
eq_(response.status_code, 200)
ok_("Survey must have at least one question in order to be active"
in response.content
)
# add a question and check for successful activation
Question.objects.create(
survey=survey,
question={},
)
response = self.client.post(url, {
'name': 'New Name',
'active': True
Expand Down

0 comments on commit cb2d715

Please sign in to comment.