Пример #1
0
def test_login_link_not_migrated(switch_is_active):
    request = RequestFactory().get('/en-US/foo')
    switch_is_active.return_value = False
    assert helpers.login_link({'request':
                               request}) == ('{}?to=%2Fen-US%2Ffoo'.format(
                                   reverse('users.login')))
    switch_is_active.assert_called_with('fxa-migrated')
Пример #2
0
def test_unicode_next_path():
    path = u'/en-US/føø/bãr'
    request = RequestFactory().get(path)
    request.session = {}
    url = helpers.login_link({'request': request})
    state = urlparse.parse_qs(urlparse.urlparse(url).query)['state'][0]
    next_path = urlsafe_b64decode(state.split(':')[1] + '===')
    assert next_path.decode('utf-8') == path
Пример #3
0
def test_unicode_next_path():
    path = u'/en-US/føø/bãr'
    request = RequestFactory().get(path)
    request.session = {}
    url = helpers.login_link({'request': request})
    state = urlparse.parse_qs(urlparse.urlparse(url).query)['state'][0]
    next_path = urlsafe_b64decode(state.split(':')[1] + '===')
    assert next_path.decode('utf-8') == path
Пример #4
0
def barometer(context, collection):
    """Shows a barometer for a collection."""
    c = dict(context.items())
    request = c['request']

    user_vote = None  # Non-zero if logged in and voted.

    if request.user.is_authenticated():
        # TODO: Use reverse when bandwagon is on Zamboni.
        up_action = collection.upvote_url()
        down_action = collection.downvote_url()
        up_title = _('Add a positive vote for this collection')
        down_title = _('Add a negative vote for this collection')
        cancel_title = _('Remove my vote for this collection')

        if 'collection_votes' in context:
            user_vote = context['collection_votes'].get(collection.id)
        else:
            votes = request.user.votes.filter(collection=collection)
            if votes:
                user_vote = votes[0]

    else:
        up_action = down_action = login_link(c)
        login_title = _('Log in to vote for this collection')
        up_title = down_title = cancel_title = login_title

    up_class = 'upvotes'
    down_class = 'downvotes'
    cancel_class = 'cancel_vote'

    total_votes = collection.upvotes + collection.downvotes

    if total_votes:
        up_ratio = int(
            math.ceil(round(100 * collection.upvotes / total_votes, 2)))
        down_ratio = 100 - up_ratio

        up_width = max(up_ratio - 1, 0)
        down_width = max(down_ratio - 1, 0)

    if user_vote:
        if user_vote.vote > 0:
            up_class += ' voted'
        else:
            down_class += ' voted'
    else:
        cancel_class += ' hidden'

    c.update(locals())
    c.update({'c': collection})
    return c
Пример #5
0
def barometer(context, collection):
    """Shows a barometer for a collection."""
    c = dict(context.items())
    request = c['request']

    user_vote = None  # Non-zero if logged in and voted.

    if request.user.is_authenticated():
        # TODO: Use reverse when bandwagon is on Zamboni.
        up_action = collection.upvote_url()
        down_action = collection.downvote_url()
        up_title = _('Add a positive vote for this collection')
        down_title = _('Add a negative vote for this collection')
        cancel_title = _('Remove my vote for this collection')

        if 'collection_votes' in context:
            user_vote = context['collection_votes'].get(collection.id)
        else:
            votes = request.user.votes.filter(collection=collection)
            if votes:
                user_vote = votes[0]

    else:
        up_action = down_action = login_link(c)
        login_title = _('Log in to vote for this collection')
        up_title = down_title = cancel_title = login_title

    up_class = 'upvotes'
    down_class = 'downvotes'
    cancel_class = 'cancel_vote'

    total_votes = collection.upvotes + collection.downvotes

    if total_votes:
        up_ratio = int(
            math.ceil(round(100 * collection.upvotes / total_votes, 2)))
        down_ratio = 100 - up_ratio

        up_width = max(up_ratio - 1, 0)
        down_width = max(down_ratio - 1, 0)

    if user_vote:
        if user_vote.vote > 0:
            up_class += ' voted'
        else:
            down_class += ' voted'
    else:
        cancel_class += ' hidden'

    c.update(locals())
    c.update({'c': collection})
    return c
Пример #6
0
def test_login_link_not_migrated(switch_is_active):
    request = RequestFactory().get('/en-US/foo')
    switch_is_active.return_value = False
    assert helpers.login_link({'request': request}) == (
        '{}?to=%2Fen-US%2Ffoo'.format(reverse('users.login')))
    switch_is_active.assert_called_with('fxa-migrated')
Пример #7
0
def test_login_link_migrated(switch_is_active):
    switch_is_active.return_value = True
    assert helpers.login_link({'request': mock.MagicMock()}) == (
        'http://auth.ca')
    switch_is_active.assert_called_with('fxa-migrated')
Пример #8
0
def test_login_link():
    request = RequestFactory().get('/en-US/firefox/addons')
    assert helpers.login_link({'request': request}) == (
        'http://auth.ca')
Пример #9
0
def test_login_link():
    request = RequestFactory().get('/en-US/firefox/addons')
    assert helpers.login_link({'request': request}) == ('http://auth.ca')
Пример #10
0
def test_login_link_migrated(switch_is_active):
    switch_is_active.return_value = True
    assert helpers.login_link({'request':
                               mock.MagicMock()}) == ('http://auth.ca')
    switch_is_active.assert_called_with('fxa-migrated')