Ejemplo n.º 1
0
    def test_registration_social(self):
        """Verify the registration process works with the social flow.

        When a user logs in for the first time using an unknown social
        account, she has to fill out the registration form before she is
        let in.
        """
        response = self.social_testing_login()
        # A registration form is displayed to the user.
        self.assertRedirects(response, '/account/register/')
        # The registration form is supposed to be filled in with values
        # retrieved from the auth provider.
        self.assertContains(
            response,
            b'<input id="id_username" maxlength="30" name="username" type="text" value="koniiiik" />',
            html=True,
        )
        self.assertContains(
            response,
            b'<input id="id_first_name" maxlength="30" name="first_name" type="text" value="Colleague" />',
            html=True,
        )
        self.assertContains(
            response,
            b'<input id="id_last_name" maxlength="30" name="last_name" type="text" value="Knuk" />',
            html=True,
        )
        # The type of an EmailInput has changed in 1.6, which means we
        # need to render it manually here. Also, EmailField.max_length
        # changed in 1.8.
        expected = EmailField().widget.render('email', '*****@*****.**', {
            'maxlength': models.EmailField().max_length,
            'id': 'id_email'
        })
        self.assertContains(
            response,
            expected.encode('utf-8'),
            html=True,
        )
        # Submit the registration form...
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'first_name': 'Colleague',
            'last_name': 'Knuk',
        }
        response = self.client.post('/account/register/', data,
                                    follow=True)
        # The redirect chain continues through the social:complete view
        # and lands at the LOGIN_URL destination.
        self.assertIn(tuple(response.redirect_chain),
                      [(('http://testserver/account/complete/test1/', 302),
                        ('http://testserver/account/', 302)),
                       (('/account/complete/test1/', 302),
                        ('/account/', 302))])
        # The resulting page shows the user logged in and with a social
        # association.
        self.assertIn(b'Logged in as', response.content)
        self.assertIn(b'<a href="/account/" class="navbar-link">koniiiik</a>', response.content)
        self.assertIn(b'Testing UID #1', response.content)
Ejemplo n.º 2
0
    def test_registration_social(self):
        """Verify the registration process works with the social flow.

        When a user logs in for the first time using an unknown social
        account, she has to fill out the registration form before she is
        let in.
        """
        response = self.social_testing_login()
        # A registration form is displayed to the user.
        self.assertRedirects(response, '/account/register/')
        # The registration form is supposed to be filled in with values
        # retrieved from the auth provider.
        self.assertContains(
            response,
            b'<input id="id_username" maxlength="30" name="username" type="text" value="koniiiik" />',
            html=True,
        )
        self.assertContains(
            response,
            b'<input id="id_first_name" maxlength="30" name="first_name" type="text" value="Colleague" />',
            html=True,
        )
        self.assertContains(
            response,
            b'<input id="id_last_name" maxlength="30" name="last_name" type="text" value="Knuk" />',
            html=True,
        )
        # The type of an EmailInput has changed in 1.6, which means we
        # need to render it manually here.
        expected = EmailField().widget.render('email', '*****@*****.**', {
            'maxlength': 75,
            'id': 'id_email'
        })
        self.assertContains(
            response,
            expected.encode('utf-8'),
            html=True,
        )
        # Submit the registration form...
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'first_name': 'Colleague',
            'last_name': 'Knuk',
        }
        response = self.client.post('/account/register/', data, follow=True)
        # The redirect chain continues through the social:complete view
        # and lands at the LOGIN_URL destination.
        self.assertEqual(response.redirect_chain,
                         [('http://testserver/account/complete/test1/', 302),
                          ('http://testserver/account/', 302)])
        # The resulting page shows the user logged in and with a social
        # association.
        self.assertIn(b'Logged in as', response.content)
        self.assertIn(b'<a href="/account/" class="navbar-link">koniiiik</a>',
                      response.content)
        self.assertIn(b'Testing UID #1', response.content)