Commits

James Bennett committed d8800d9

Start adding a (failing) test of the registration view.

Comments (0)

Files changed (2)

registration/tests.py

 from django.contrib.auth.models import User
 from django.core import mail
 from django.core.exceptions import ImproperlyConfigured
+from django.core.urlresolvers import reverse
 from django.test import TestCase
 
 from registration import forms
         controls whether registration is permitted.
         
         """
+        old_allowed = getattr(settings, 'REGISTRATION_OPEN', True)
+        settings.REGISTRATION_OPEN = True
         self.failUnless(self.backend.registration_allowed({}))
         settings.REGISTRATION_OPEN = False
         self.failIf(self.backend.registration_allowed({}))
+        settings.REGISTRATION_OPEN = old_allowed
 
     def test_form_class(self):
         """
         self.assertRaises(ImproperlyConfigured, get_backend)
 
         settings.REGISTRATION_BACKEND = old_backend
+
+
+class RegistrationViewTests(TestCase):
+    """
+    Test the registration views.
     
+    """
+    urls = 'registration.backends.default.urls'
+    
+    def setUp(self):
+        """
+        Set ``REGISTRATION_BACKEND`` to the default backend, and store
+        the original value to be restored later.
+        
+        """
+        self.old_backend = getattr(settings, 'REGISTRATION_BACKEND', None)
+        settings.REGISTRATION_BACKEND = 'registration.backends.default.DefaultBackend'
+
+    def tearDown(self):
+        """
+        Retore the original value of ``REGISTRATION_BACKEND``.
+        
+        """
+        settings.REGISTRATION_BACKEND = self.old_backend
+
+    def test_registration_view(self):
+        """
+        Call the ``register`` view and ensure that it properly
+        validates data and creates a new user.
+        
+        """
+        response = self.client.post(reverse('registration_register'),
+                                    data={ 'username': 'alice',
+                                           'email': 'alice@example.com',
+                                           'password1': 'swordfish',
+                                           'password2': 'swordfish' })
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(len(mail.outbox), 1)

registration/views.py

     
     """
     backend = get_backend()
-    if not backend.registration_disallowed(request):
+    if not backend.registration_allowed(request):
         return redirect(disallowed_url)
     if form_class is None:
         form_class = backend.get_form_class(request)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.