Commits

James Bennett  committed 1a29e24

Add a test for success_url.

  • Participants
  • Parent commits 8329720

Comments (0)

Files changed (3)

File registration/test_urls.py

                            direct_to_template,
                            {'template': 'registration/registration_closed.html'},
                            name='registration_test_custom_disallowed'),
+                       # Test the 'register' view with custom redirect
+                       # on successful registration.
+                       url(r'^register-with-success_url/$',
+                           register,
+                           {'success_url': 'registration_test_custom_success_url'},
+                           name='registration_test_register_success_url'
+                           ),
+                       # Pattern for custom redirect set above.
+                       url(r'^custom-success/$',
+                           direct_to_template,
+                           {'template': 'registration/test_template_name.html'},
+                           name='registration_test_custom_success_url'),
                        )

File registration/tests/views.py

 
         settings.REGISTRATION_OPEN = old_allowed
 
+    def test_registration_success_url(self):
+        """
+        Passing ``success_url`` to the ``register`` view will result
+        in a redirect to that URL when registration is successful.
+        
+        """
+        success_redirect = 'http://testserver%s' % reverse('registration_test_custom_success_url')
+        response = self.client.post(reverse('registration_test_register_success_url'),
+                                    data={'username': 'alice',
+                                          'email': 'alice@example.com',
+                                          'password1': 'swordfish',
+                                          'password2': 'swordfish'})
+        self.assertRedirects(response, success_redirect)
+
     def test_valid_activation(self):
         """
         Test that the ``activate`` view properly handles a valid

File registration/views.py

                 to, args, kwargs = backend.post_registration_redirect(request, new_user)
                 return redirect(to, *args, **kwargs)
             else:
-                redirect(success_url)
+                return redirect(success_url)
     else:
         form = form_class()