django.utils.six.moves.urllib_parse.urlparse

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

10 Examples 7

Example 1

Project: browsercompat
Source File: test_helpers.py
View license
    def mock_context(self, url):
        mock_request = mock.Mock(spec_set=['path', 'GET'])
        url_parts = urlparse(url)
        mock_request.path = url_parts.path
        mock_request.GET = OrderedDict(parse_qsl(url_parts.query))
        return {'request': mock_request}

Example 2

Project: browsercompat
Source File: test_helpers.py
View license
    def mock_context(self, url):
        mock_request = mock.Mock(spec_set=['path', 'GET'])
        url_parts = urlparse(url)
        mock_request.path = url_parts.path
        mock_request.GET = OrderedDict(parse_qsl(url_parts.query))
        return {'request': mock_request}

Example 3

Project: yournextrepresentative
Source File: agreement.py
View license
    def get_initial(self):
        initial = super(AskForCopyrightAssigment, self).get_initial().copy()
        next_url = self.request.GET['next']
        parsed_url = urlparse(next_url)
        initial['next_path'] = parsed_url.path
        return initial

Example 4

Project: yournextrepresentative
Source File: agreement.py
View license
    def get_initial(self):
        initial = super(AskForCopyrightAssigment, self).get_initial().copy()
        next_url = self.request.GET['next']
        parsed_url = urlparse(next_url)
        initial['next_path'] = parsed_url.path
        return initial

Example 5

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 6

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 7

Project: browsercompat
Source File: models.py
View license
    def domain(self):
        """Protocol + domain portion of URL."""
        url_bits = urlparse(self.url)
        return '%s://%s' % (url_bits.scheme, url_bits.netloc)

Example 8

Project: browsercompat
Source File: models.py
View license
    def domain(self):
        """Protocol + domain portion of URL."""
        url_bits = urlparse(self.url)
        return '%s://%s' % (url_bits.scheme, url_bits.netloc)

Example 9

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 10

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