This commit is contained in:
Andy McKay 2012-04-19 16:21:59 -07:00
Родитель 74e251461c
Коммит 14fad862b6
2 изменённых файлов: 32 добавлений и 13 удалений

Просмотреть файл

@ -85,6 +85,12 @@ def contribution_type(type):
@register.function
def user_data(amo_user):
return {'anonymous': amo_user.is_anonymous(),
'pre_auth': False if amo_user.is_anonymous()
else amo_user.has_preapproval_key()}
anonymous, currency, pre_auth = amo_user.is_anonymous(), 'USD', False
if not anonymous:
preapproval = amo_user.get_preapproval()
if preapproval:
pre_auth = bool(preapproval.paypal_key)
currency = preapproval.currency if preapproval.currency else 'USD'
return {'anonymous': anonymous, 'pre_auth': pre_auth,
'currency': currency}

Просмотреть файл

@ -6,7 +6,9 @@ from django.contrib.auth.models import AnonymousUser
import mock
from nose.tools import eq_
import amo.tests
from amo.urlresolvers import reverse
from market.models import PreApprovalUser
from users.helpers import emaillink, user_link, users_list, user_data
from users.models import UserProfile, RequestUser
@ -89,15 +91,26 @@ def test_user_data():
eq_(u['pre_auth'], False)
@mock.patch('users.models.RequestUser.has_preapproval_key')
def test_user_data_approved(has_preapproval_key):
has_preapproval_key.return_value = True
u = user_data(RequestUser(username='foo', pk=1))
eq_(u['anonymous'], False)
eq_(u['pre_auth'], True)
class TestUserData(amo.tests.TestCase):
def test_user_data_approved(self):
up = UserProfile.objects.create(email='aq@a.com', username='foo')
PreApprovalUser.objects.create(user=up, paypal_key='asd')
u = user_data(RequestUser.objects.get(pk=up.pk))
eq_(u['anonymous'], False)
eq_(u['pre_auth'], True)
eq_(u['currency'], 'USD')
def test_anonymous_user_data():
u = user_data(AnonymousUser())
eq_(u['anonymous'], True)
eq_(u['pre_auth'], False)
def test_anonymous_user_data(self):
u = user_data(AnonymousUser())
eq_(u['anonymous'], True)
eq_(u['pre_auth'], False)
eq_(u['currency'], 'USD')
def test_preapproval_user_data(self):
up = UserProfile.objects.create(email='aq@a.com', username='foo')
PreApprovalUser.objects.create(user=up, paypal_key='asd', currency='EUR')
u = user_data(RequestUser.objects.get(pk=up.pk))
eq_(u['anonymous'], False)
eq_(u['pre_auth'], True)
eq_(u['currency'], 'EUR')