James Bennett committed c282e34

More tests for get_backend().

Comments (0)

Files changed (2)


     Return an instance of the registration backend for use on this
     site, as determined by the ``REGISTRATION_BACKEND`` setting. Raise
     ``django.core.exceptions.ImproperlyConfigured`` if the specified
-    backend cannot be located.
+    backend cannot be located, or if no backend is specified.
+    if not hasattr(settings, 'REGISTRATION_BACKEND') or not settings.REGISTRATION_BACKEND:
+        raise ImproperlyConfigured('Error loading registration backend: no backend specified (have you provided a value for the REGISTRATION_BACKEND setting?)')
     i = settings.REGISTRATION_BACKEND.rfind('.')
     module, attr = settings.REGISTRATION_BACKEND[:i], settings.REGISTRATION_BACKEND[i+1:]


 from django.conf import settings
 from django.contrib.auth.models import User
 from django.core import mail
+from django.core.exceptions import ImproperlyConfigured
 from django.test import TestCase
 from registration import forms
         self.failUnless(isinstance(get_backend(), DefaultBackend))
         settings.REGISTRATION_BACKEND = old_backend
+    def test_backend_error(self):
+        """
+        Test that an invalid or nonexistent value for the
+        ``REGISTRATION_BACKEND`` setting raises the correct exception.
+        """
+        from registration import get_backend
+        old_backend = getattr(settings, 'REGISTRATION_BACKEND', None)
+        settings.REGISTRATION_BACKEND = None
+        self.assertRaises(ImproperlyConfigured, get_backend)
+        # Test nonexistent module
+        settings.REGISTRATION_BACKEND = 'registration.backends.doesnotexist.NonExistentBackend'
+        self.assertRaises(ImproperlyConfigured, get_backend)
+        settings.REGISTRATION_BACKEND = old_backend