change token when id changes and allow premium without a developer profile (bug 686696)

This commit is contained in:
Andy McKay 2011-09-14 16:16:52 -07:00
Родитель cbb3c6399b
Коммит 3cc4f97392
3 изменённых файлов: 42 добавлений и 25 удалений

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

@ -893,6 +893,13 @@ class PremiumForm(happyforms.Form):
def save(self):
if self.cleaned_data['paypal_id']:
if (self.addon.paypal_id != self.cleaned_data['paypal_id']
and self.addon.premium
and self.addon.premium.paypal_permissions_token):
# If a user changes their paypal id, then we need
# to nuke the token.
self.addon.premium.paypal_permissions_token = ''
self.addon.premium.save()
self.addon.paypal_id = self.cleaned_data['paypal_id']
self.addon.support_email = self.cleaned_data['support_email']
self.addon.save()

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

@ -3,7 +3,7 @@
{% set title = _('Manage Payments') %}
{% block title %}{{ dev_page_title(title, addon) }}{% endblock %}
{% set can_edit = check_addon_ownership(request, addon) and addon.has_full_profile() %}
{% set can_edit = check_addon_ownership(request, addon) %}
{% block bodyclass %}
{{ super() }}{% if not can_edit %} no-edit{% endif %}
{% endblock %}
@ -15,16 +15,6 @@
<h2>{{ title }}</h2>
</header>
<section class="primary payments devhub-form" role="main">
{% if not addon.has_full_profile() %}
<div class="notification-box warning">
<h2>
{% trans url=url('devhub.addons.profile', addon.slug) %}
Payments are only available for add-ons with a <a href="{{ url }}">completed developer profile</a>.
{% endtrans %}
</h2>
</div>
{% endif %}
{% set contrib = addon.takes_contributions and addon.has_full_profile() or errors %}
{% if contrib and not errors %}
<div id="status-bar">
@ -59,7 +49,13 @@
<li>{{ _('Choose when and how users are asked to contribute') }}</li>
<li>{{ _('Receive contributions in your PayPal account or send them to an organization of your choice') }}</li>
</ul>
{% if addon.status != amo.STATUS_PUBLIC %}
{% if not addon.has_full_profile() %}
<p class="error">
{% trans url=url('devhub.addons.profile', addon.slug) %}
Contributions are only available for add-ons with a <a href="{{ url }}">completed developer profile</a>.
{% endtrans %}
</p>
{% elif addon.status != amo.STATUS_PUBLIC %}
<p class="error">
{% trans %}
Contributions are only available for fully reviewed add-ons.

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

@ -563,10 +563,8 @@ class TestEditPayments(amo.tests.TestCase):
def test_no_future(self):
self.get_addon().update(the_future=None)
res = self.client.get(self.url)
box = pq(res.content)('div.notification-box h2')
assert 'no-edit' in res.content
eq_(len(box), 1)
eq_('completed developer profile' in box.text(), True)
err = pq(res.content)('p.error')
eq_('completed developer profile' in err.text(), True)
@mock.patch('addons.models.Addon.upsell')
def test_with_upsell_no_contributions(self, upsell):
@ -749,7 +747,7 @@ class TestMarketplace(amo.tests.TestCase):
res = self.client.get(self.url)
eq_(res.status_code, 200)
doc = pq(res.content)
eq_(len(doc('.error')), 1)
eq_(len(doc('.error')), 2)
def setup_premium(self):
self.price = Price.objects.create(price='0.99')
@ -852,20 +850,20 @@ class TestMarketplace(amo.tests.TestCase):
@mock.patch('paypal.get_permissions_token', lambda x, y: x.upper())
def test_permissions_token(self):
self.setup_premium()
eq_(self.addon.addonpremium.paypal_permissions_token, '')
eq_(self.addon.premium.paypal_permissions_token, '')
url = reverse('devhub.addons.acquire_refund_permission',
args=[self.addon.slug])
data = {'request_token': 'foo', 'verification_code': 'bar'}
self.client.get('%s?%s' % (url, urlencode(data)))
self.addon = Addon.objects.get(pk=self.addon.pk)
eq_(self.addon.addonpremium.paypal_permissions_token, 'FOO')
eq_(self.addon.premium.paypal_permissions_token, 'FOO')
@mock.patch('paypal.get_permissions_token', lambda x, y: x.upper())
def test_permissions_token_no_premium(self):
self.setup_premium()
# They could hit this URL before anything else, we need to cope
# with AddonPremium not being there.
self.addon.addonpremium.delete()
self.addon.premium.delete()
url = reverse('devhub.addons.acquire_refund_permission',
args=[self.addon.slug])
data = {'request_token': 'foo', 'verification_code': 'bar'}
@ -904,6 +902,9 @@ class TestMarketplace(amo.tests.TestCase):
eq_(Addon.objects.get(pk=self.addon.pk).premium.price.pk,
self.price.pk)
def get_addon(self):
return Addon.objects.get(pk=self.addon.pk)
def test_wizard_step_3(self):
url = reverse('devhub.market.3', args=[self.addon.slug])
self.other_addon = Addon.objects.create(type=amo.ADDON_EXTENSION)
@ -915,14 +916,13 @@ class TestMarketplace(amo.tests.TestCase):
'text': 'some upsell',
}
eq_(self.client.post(url, data).status_code, 302)
eq_(Addon.objects.get(pk=self.addon.pk).upsold.free,
self.other_addon)
eq_(self.get_addon().upsold.free, self.other_addon)
def test_wizard_step_4_failed(self):
url = reverse('devhub.market.4', args=[self.addon.slug])
assert not Addon.objects.get(pk=self.addon.pk).is_premium()
assert not self.get_addon().is_premium()
eq_(self.client.post(url, {}).status_code, 302)
assert not Addon.objects.get(pk=self.addon.pk).is_premium()
assert not self.get_addon().is_premium()
def test_wizard_step_4(self):
self.setup_premium()
@ -930,7 +930,21 @@ class TestMarketplace(amo.tests.TestCase):
self.addon.update(premium_type=amo.ADDON_FREE)
url = reverse('devhub.market.4', args=[self.addon.slug])
eq_(self.client.post(url, {}).status_code, 302)
assert Addon.objects.get(pk=self.addon.pk).is_premium()
assert self.get_addon().is_premium()
def test_changing_paypal_id(self):
self.setup_premium()
self.addon.premium.update(paypal_permissions_token='foo')
data = self.get_data()
data['paypal_id'] = 'e@e.com'
self.client.post(self.url, data)
eq_(self.get_addon().premium.paypal_permissions_token, '')
def test_not_changing_paypal_id(self):
self.setup_premium()
self.addon.premium.update(paypal_permissions_token='foo')
self.client.post(self.url, self.get_data())
assert self.get_addon().premium.paypal_permissions_token
class TestDelete(amo.tests.TestCase):