def setUp(self):
     factory = RequestFactory()
     request = factory.get(reverse('registration_register'))
     SessionMiddleware().process_request(request)
     self.user = RegisterView().register(request, email='*****@*****.**')
     self.user.set_unusable_password()
     self.activation_key = user_to_activation_key(self.user)
class RegisterTests(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.req = self.factory.get(reverse('registration_register'))
        SessionMiddleware().process_request(self.req)
        self.b = RegisterView()

    def test_register_no_email(self):
        with self.assertRaises(ValueError):
            self.b.register(self.req)

    def test_unusable_password(self):
        u = self.b.register(self.req, email='*****@*****.**')
        self.assertFalse(u.has_usable_password())

    def test_signal_sent(self):
        signal_user = set()
        def user_registered_signal_handler(sender, request, user, **kwargs):
            signal_user.add(user)
        user_registered.connect(
            user_registered_signal_handler)
        u = self.b.register(self.req, email='*****@*****.**')
        self.assertIn(u, signal_user)

    def test_logged_in(self):
        signal_user = set()
        def login_signal_handler(sender, request, user, **kwargs):
            signal_user.add(user)
        user_logged_in.connect(login_signal_handler)
        u = self.b.register(self.req, email='*****@*****.**')
        self.assertIn(u, signal_user)

    def test_email_sent(self):
        self.b.register(self.req, email='*****@*****.**')
        self.assertEqual(len(mail.outbox), 1)
class ActivateTests(TestCase):
    def setUp(self):
        factory = RequestFactory()
        request = factory.get(reverse('registration_register'))
        SessionMiddleware().process_request(request)
        self.user = RegisterView().register(request, email='*****@*****.**')
        self.user.set_unusable_password()
        self.activation_key = user_to_activation_key(self.user)

    def test_form(self):
        response = self.client.get(reverse('registration_activate', args=(self.activation_key, )))
        self.assertEqual(response.status_code, 200)
        self.assertIn('form', response.context)

    def test_valid_form(self):
        self.assertFalse(self.user.has_usable_password())
        response = self.client.post(reverse('registration_activate', args=(self.activation_key, )), {
            'activation_key': self.activation_key,
            'username': '******',
            'password': '******'
        })
        self.assertRedirects(response, reverse('registration_activation_complete'))
        user = User.objects.get(username='******')
        self.assertTrue(user.has_usable_password())
 def setUp(self):
     self.factory = RequestFactory()
     self.req = self.factory.get(reverse('registration_register'))
     SessionMiddleware().process_request(self.req)
     self.b = RegisterView()
up your own URL patterns for these views instead.

"""
from django.conf.urls import patterns, url, include
from django.views.generic.base import TemplateView
from registration_email_only.backends.views import ActivateView, RegisterView


urlpatterns = patterns('',
                       url(r'^activate/complete/$',
                           TemplateView.as_view(template_name='registration/activation_complete.html'),
                           name='registration_activation_complete'),
                       # Activation keys get matched by \w+ instead of a more specific
                       # regex because a bad activation key should still get to the
                       # view; that way it can return a sensible "invalid key" message
                       # instead of a confusing 404.
                       url(r'^activate/(?P<activation_key>[\w-]+)/$',
                           ActivateView.as_view(),
                           name='registration_activate'),
                       url(r'^register/$',
                           RegisterView.as_view(),
                           name='registration_register'),
                       url(r'^register/complete/$',
                           TemplateView.as_view(template_name='registration/registration_complete.html'),
                           name='registration_complete'),
                       url(r'^register/closed/$',
                           TemplateView.as_view(template_name='registration/registration_closed.html'),
                           name='registration_disallowed'),
                       (r'', include('registration.auth_urls')),
                       )