Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     """Check if the form is valid and then pass it on to our form handling functions."""
     form = NewsletterSignupForm(request.POST)
     if not form.is_valid():
         return self.form_invalid(request, form)
     else:
         return self.form_valid(request, form)
Ejemplo n.º 2
0
 def test_post_view(self, mock_subscribe):
     """Posting an email to the list should add that email to our MailChimp list."""
     form = NewsletterSignupForm({
         'email': '*****@*****.**',
         'list': settings.MAILCHIMP_LIST_DEFAULT
     })
     ok_(form.is_valid(), 'The form should validate.')
     response = http_post_response(self.url, self.view, form.data)
     mock_subscribe.assert_called_with(form.data['email'], form.data['list'])
     eq_(response.status_code, 302, 'Should redirect upon successful submission.')
Ejemplo n.º 3
0
 def test_post_other_list(self, mock_subscribe):
     """Posting to a list other than the default should optionally subscribe to the default."""
     form = NewsletterSignupForm({
         'email': '*****@*****.**',
         'default': True,
         'list': 'other'
     })
     ok_(form.is_valid(), 'The form should validate.')
     response = http_post_response(self.url, self.view, form.data)
     mock_subscribe.assert_any_call(form.data['email'], form.data['list'])
     mock_subscribe.assert_any_call(form.data['email'], settings.MAILCHIMP_LIST_DEFAULT)
     eq_(response.status_code, 302, 'Should redirect upon successful submission.')