示例#1
0
def test_recent_revisions_all_locales(trans_edit_revision, client):
    """The ?all_locales parameter returns mixed locales (bug 869301)."""
    feed_url = reverse('wiki.feeds.recent_revisions', locale='en-US',
                       kwargs={'format': 'rss'})
    resp = client.get(feed_url, {'all_locales': ''},
                      HTTP_HOST='example.com',
                      HTTP_X_FORWARDED_PROTO='https')
    assert resp.status_code == 200
    feed = pq(resp.content)
    items = feed.find('item')
    assert len(items) == 4

    # Test that links use host domain
    actual_links = [pq(item).find('link').text() for item in items]
    actual_domains = [urlparse(link).netloc for link in actual_links]
    assert actual_domains == ['example.com'] * 4

    # Test that links are a mix of en-US and translated documents
    trans_doc = trans_edit_revision.document
    root_doc = trans_doc.parent
    expected_paths = [
        root_doc.get_absolute_url(),
        trans_doc.get_absolute_url(),
        root_doc.get_absolute_url(),
        trans_doc.get_absolute_url(),
    ]
    actual_paths = [urlparse(link).path for link in actual_links]
    assert expected_paths == actual_paths
示例#2
0
    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.failUnlessEqual(parsed.netloc, 'www.gravatar.com')
        self.failUnlessEqual(parsed.path, '/avatar/' + gravatar_hash)
        self.failUnlessEqual(
            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.failUnlessEqual(parsed.netloc, 'www.gravatar.com')
        self.failUnlessEqual(parsed.path, '/avatar/' + gravatar_hash)
        self.failUnlessEqual(
            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'
示例#3
0
def test_recent_documents_feed_filter_by_locale(locale, trans_edit_revision,
                                                client):
    """The recent documents feed can be filtered by locale."""
    feed_url = reverse('wiki.feeds.recent_documents', locale=locale,
                       kwargs={'format': 'json'})
    resp = client.get(feed_url)
    assert resp.status_code == 200
    data = json.loads(resp.content)
    assert len(data) == 1
    path = urlparse(data[0]['link']).path
    assert path.startswith('/' + locale + '/')
示例#4
0
文件: test_feeds.py 项目: Elchi3/kuma
def test_recent_revisions_feed_filter_by_locale(locale, trans_edit_revision,
                                                client):
    """The recent revisions feed can be filtered by locale."""
    feed_url = reverse('wiki.feeds.recent_revisions', locale=locale,
                       kwargs={'format': 'json'})
    resp = client.get(feed_url)
    assert resp.status_code == 200
    assert_shared_cache_header(resp)
    data = json.loads(resp.content)
    assert len(data) == 2
    for item in data:
        path = urlparse(item['link']).path
        assert path.startswith('/' + locale + '/')
示例#5
0
文件: __init__.py 项目: yfdyh000/kuma
    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
示例#6
0
    def test_get_gravatar(self):
        template = 's=%(size)s&d=%(type)s'

        # Check the defaults.
        parsed = urlparse(get_gravatar('*****@*****.**'))
        self.failUnlessEqual(
            parse_qs(parsed.query),
            parse_qs(template % {'size': 80, 'type': 'identicon'})
        )

        # Check different size
        parsed = urlparse(get_gravatar('*****@*****.**', size=200))
        self.failUnlessEqual(
            parse_qs(parsed.query),
            parse_qs(template % {'size': 200, 'type': 'identicon'})
        )

        # Check different default
        parsed = urlparse(get_gravatar('*****@*****.**', default='404'))
        self.failUnlessEqual(
            parse_qs(parsed.query),
            parse_qs(template % {'size': 80, 'type': '404'})
        )
示例#7
0
def test_l10n_updates_include_campaign(trans_doc, create_revision,
                                       edit_revision, client):
    """Translation URLs include GA campaign data."""
    feed_url = reverse('wiki.feeds.l10n_updates', locale=trans_doc.locale,
                       kwargs={'format': 'rss'})
    resp = client.get(feed_url)
    assert resp.status_code == 200
    feed = pq(resp.content)
    items = feed.find('item')
    assert len(items) == 1
    desc_text = pq(items).find('description').text()
    desc_html = pq(desc_text)  # Description is encoded HTML
    links = desc_html.find('a')
    assert len(links) == 3
    for link in links:
        href = link.attrib['href']
        querystring = parse_qs(urlparse(href).query)
        assert querystring['utm_campaign'] == ['feed']
        assert querystring['utm_medium'] == ['rss']
        assert querystring['utm_source'] == ['developer.mozilla.org']
 def process_request(self, request):
     try:
         parsed = urlparse.urlparse(request.build_absolute_uri())
         host = parsed.hostname.split(':')[0]
         urlconf = None
         try:
             urlconf = settings.MULTISITE_CMS_URLS[host]
         except KeyError:
             for domain, hosts in settings.MULTISITE_CMS_ALIASES.items():
                 if host in hosts:
                     urlconf = settings.MULTISITE_CMS_URLS[domain]
                     break
         if not urlconf:
             urlconf = settings.MULTISITE_CMS_URLS[settings.MULTISITE_CMS_FALLBACK]
         request.urlconf = urlconf
         # sets urlconf for current thread, so that code that does not know
         # about the request (e.g MyModel.get_absolute_url()) get the correct
         # urlconf.
         set_urlconf(urlconf)
     except KeyError:
         # use default urlconf (settings.ROOT_URLCONF)
         set_urlconf(None)
 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}
示例#10
0
 def path(self):
     """Path portion of URL"""
     return urlparse(self.url).path
示例#11
0
 def domain(self):
     """Protocol + domain portion of URL"""
     url_bits = urlparse(self.url)
     return "%s://%s" % (url_bits.scheme, url_bits.netloc)
示例#12
0
 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
示例#13
0
 def get_initial(self):
     initial = super().get_initial().copy()
     next_url = self.request.GET["next"]
     parsed_url = urlparse(next_url)
     initial["next_path"] = parsed_url.path
     return initial