def test_registration(self):
        """
        Registration creates a new inactive account and a new profile
        with activation key, populates the correct account data and
        sends an activation email.

        """
        resp = self.client.post(reverse('registration_register'),
                                data={
                                    'username': '******',
                                    'email': '*****@*****.**',
                                    'password1': 'secret',
                                    'password2': 'secret'
                                })
        self.assertRedirects(resp, reverse('registration_complete'))

        new_user = UserModel().objects.get(username='******')

        self.failUnless(new_user.check_password('secret'))
        self.assertEqual(new_user.email, '*****@*****.**')

        # New user must not be active.
        self.failIf(new_user.is_active)

        # A registration profile was created, and an activation email
        # was sent.
        self.assertEqual(RegistrationProfile.objects.count(), 1)
        self.assertEqual(len(mail.outbox), 1)
    def test_registration(self):
        """
        Registration creates a new account and logs the user in.

        """
        resp = self.client.post(reverse('registration_register'),
                                data={
                                    'username': '******',
                                    'email': '*****@*****.**',
                                    'password1': 'secret',
                                    'password2': 'secret'
                                })
        new_user = UserModel().objects.get(username='******')
        self.assertEqual(302, resp.status_code)
        self.failUnless(reverse('registration_complete') in resp['Location'])

        self.failUnless(new_user.check_password('secret'))
        self.assertEqual(new_user.email, '*****@*****.**')

        # New user must be active.
        self.failUnless(new_user.is_active)

        # New user must be logged in.
        resp = self.client.get(reverse('registration_register'))
        self.failUnless(resp.context['user'].is_authenticated())
    def test_registration_no_sites(self):
        """
        Registration still functions properly when
        ``django.contrib.sites`` is not installed; the fallback will
        be a ``RequestSite`` instance.

        """
        resp = self.client.post(reverse('registration_register'),
                                data={
                                    'username': '******',
                                    'email': '*****@*****.**',
                                    'password1': 'secret',
                                    'password2': 'secret'
                                })
        self.assertEqual(302, resp.status_code)

        new_user = UserModel().objects.get(username='******')

        self.failUnless(new_user.check_password('secret'))
        self.assertEqual(new_user.email, '*****@*****.**')

        self.failIf(new_user.is_active)

        self.assertEqual(RegistrationProfile.objects.count(), 1)
        self.assertEqual(len(mail.outbox), 1)