django.utils.six.moves.urllib_parse.parse_qs

Here are the examples of the python api django.utils.six.moves.urllib_parse.parse_qs taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

Example 1

Project: django-userena
Source File: tests_models.py
View license
    def test_get_mugshot_url_with_gravatar(self):
        """
        Test if the correct mugshot is returned when the user makes use of gravatar.

        """
        profile = Profile.objects.get(pk=1)

        gravatar_hash = hashlib.md5(profile.user.email.encode('utf-8')).hexdigest()

        # Test with the default settings
        mugshot_url = profile.get_mugshot_url()
        parsed = urlparse(mugshot_url)

        self.assertEqual(parsed.netloc, 'www.gravatar.com')
        self.assertEqual(parsed.path, '/avatar/' + gravatar_hash)
        self.assertEqual(
            parse_qs(parsed.query),
            parse_qs('s=%(size)s&d=%(default)s' % {
                'size': userena_settings.USERENA_MUGSHOT_SIZE,
                'default': userena_settings.USERENA_MUGSHOT_DEFAULT
            })
        )

        # Change userena settings
        userena_settings.USERENA_MUGSHOT_SIZE = 180
        userena_settings.USERENA_MUGSHOT_DEFAULT = '404'

        # and test again
        mugshot_url = profile.get_mugshot_url()
        parsed = urlparse(mugshot_url)

        self.assertEqual(parsed.netloc, 'www.gravatar.com')
        self.assertEqual(parsed.path, '/avatar/' + gravatar_hash)
        self.assertEqual(
            parse_qs(parsed.query),
            parse_qs('s=%(size)s&d=%(default)s' % {
                'size': userena_settings.USERENA_MUGSHOT_SIZE,
                'default': userena_settings.USERENA_MUGSHOT_DEFAULT
            })
        )

        # Settings back to default
        userena_settings.USERENA_MUGSHOT_SIZE = 80
        userena_settings.USERENA_MUGSHOT_DEFAULT = 'identicon'

Example 2

Project: django-userena
Source File: tests_utils.py
View license
    def test_get_gravatar(self):
        template = 's=%(size)s&d=%(type)s'

        # Check the defaults.
        parsed = urlparse(get_gravatar('[email protected]'))
        self.assertEqual(
            parse_qs(parsed.query),
            parse_qs(template % {'size': 80, 'type': 'identicon'})
        )

        # Check different size
        parsed = urlparse(get_gravatar('[email protected]', size=200))
        self.assertEqual(
            parse_qs(parsed.query),
            parse_qs(template % {'size': 200, 'type': 'identicon'})
        )

        # Check different default
        parsed = urlparse(get_gravatar('[email protected]', default='404'))
        self.assertEqual(
            parse_qs(parsed.query),
            parse_qs(template % {'size': 80, 'type': '404'})
        )

Example 3

Project: kuma
Source File: __init__.py
View license
    def github_login(
            self, token_data=None, profile_data=None, email_data=None,
            process='login'):
        """
        Mock a login to GitHub and return the response.

        Keyword Arguments:
        token_data - OAuth token data, or None for default
        profile_data - GitHub profile data, or None for default
        email_data - GitHub email data, or None for default
        process - 'login', 'connect', or 'redirect'
        """
        login_url = reverse('github_login',
                            locale=settings.WIKI_DEFAULT_LANGUAGE)
        callback_url = reverse('github_callback', unprefixed=True)

        # Ensure GitHub is setup as an auth provider
        self.ensure_github_app()

        # Start the login process
        # Store state in the session, and redirect the user to GitHub
        login_response = self.client.get(login_url, {'process': process})
        assert login_response.status_code == 302
        location = urlparse(login_response['location'])
        query = parse_qs(location.query)
        assert callback_url in query['redirect_uri'][0]
        state = query['state'][0]

        # Callback from GitHub, mock follow-on GitHub responses
        with requests_mock.Mocker() as mock_requests:
            # The callback view will make requests back to Github:
            # The OAuth2 authentication token (or error)
            mock_requests.post(
                GitHubOAuth2Adapter.access_token_url,
                json=token_data or self.github_token_data,
                headers={'content-type': 'application/json'})
            # The authenticated user's profile data
            mock_requests.get(
                GitHubOAuth2Adapter.profile_url,
                json=profile_data or self.github_profile_data)
            # The user's emails, which could be an empty list
            if email_data is None:
                email_data = self.github_email_data
            mock_requests.get(GitHubOAuth2Adapter.emails_url, json=email_data)

            # Simulate the callback from Github
            data = {'code': 'github_code', 'state': state}
            response = self.client.get(callback_url, data, follow=True)

        return response

Example 4

Project: kuma
Source File: __init__.py
View license
    def github_login(
            self, token_data=None, profile_data=None, email_data=None,
            process='login'):
        """
        Mock a login to GitHub and return the response.

        Keyword Arguments:
        token_data - OAuth token data, or None for default
        profile_data - GitHub profile data, or None for default
        email_data - GitHub email data, or None for default
        process - 'login', 'connect', or 'redirect'
        """
        login_url = reverse('github_login',
                            locale=settings.WIKI_DEFAULT_LANGUAGE)
        callback_url = reverse('github_callback', unprefixed=True)

        # Ensure GitHub is setup as an auth provider
        self.ensure_github_app()

        # Start the login process
        # Store state in the session, and redirect the user to GitHub
        login_response = self.client.get(login_url, {'process': process})
        assert login_response.status_code == 302
        location = urlparse(login_response['location'])
        query = parse_qs(location.query)
        assert callback_url in query['redirect_uri'][0]
        state = query['state'][0]

        # Callback from GitHub, mock follow-on GitHub responses
        with requests_mock.Mocker() as mock_requests:
            # The callback view will make requests back to Github:
            # The OAuth2 authentication token (or error)
            mock_requests.post(
                GitHubOAuth2Adapter.access_token_url,
                json=token_data or self.github_token_data,
                headers={'content-type': 'application/json'})
            # The authenticated user's profile data
            mock_requests.get(
                GitHubOAuth2Adapter.profile_url,
                json=profile_data or self.github_profile_data)
            # The user's emails, which could be an empty list
            if email_data is None:
                email_data = self.github_email_data
            mock_requests.get(GitHubOAuth2Adapter.emails_url, json=email_data)

            # Simulate the callback from Github
            data = {'code': 'github_code', 'state': state}
            response = self.client.get(callback_url, data, follow=True)

        return response