Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Ignore non-applicable values in premium form (bug 822806)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbasta committed Jan 16, 2013
1 parent 47d33ff commit f495921
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
15 changes: 4 additions & 11 deletions mkt/developers/forms_payments.py
Expand Up @@ -128,22 +128,15 @@ def refresh_data():
# IT CANNOT BE CHANGED!
# TODO: Remove this when packaged apps land for all WebRT
# platforms.

prefix = (is_toggling or
'paid' if self.is_paid() else 'free')
platforms = refresh_data()
self.cleaned_data.update(**platforms)
del self.cleaned_data[
'paid_platforms' if prefix == 'free' else
'free_platforms']

self.cleaned_data = super(PremiumForm, self).clean()

elif not is_toggling:
self.cleaned_data = super(PremiumForm, self).clean()
if (self._errors.get('free_platforms') or
self._errors.get('paid_platforms')):
# If a platform wasn't selected, raise an error.
if not self.cleaned_data[
'%s_platforms' % ('paid' if self.is_paid() else 'free')]:

self._add_error('none')
refresh_data()

return self.cleaned_data
Expand Down
18 changes: 15 additions & 3 deletions mkt/developers/tests/test_forms_payments.py
Expand Up @@ -27,7 +27,8 @@ def setUp(self):
self.addon = Addon.objects.get(pk=337141)
AddonDeviceType.objects.create(
addon=self.addon, device_type=amo.DEVICE_GAIA.id)
self.platforms = {'free_platforms': ['free-firefoxos']}
self.platforms = {'free_platforms': ['free-firefoxos'],
'paid_platforms': ['paid-firefoxos']}

self.price = Price.objects.create(price='0.99')
self.user = UserProfile.objects.get(email='steamcube@mozilla.com')
Expand Down Expand Up @@ -116,8 +117,8 @@ def test_update_wo_initial_price(self):
eq_(self.addon.premium.price.pk, price.pk)

def test_update_new_with_acct(self):
# This was the situation for a new app that was
# getting linked to an existing bank account.
# This was the situation for a new app that was getting linked to an
# existing bank account.
self.addon.update(premium_type=amo.ADDON_PREMIUM)
self.platforms.update(price=self.price.pk)
form = forms_payments.PremiumForm(self.platforms, **self.kwargs)
Expand Down Expand Up @@ -149,6 +150,17 @@ def test_cannot_change_devices_for_packaged_app(self):
self.assertSetEqual(self.addon.device_types, old_devices)
self.assertSetEqual(form.get_devices(), old_devices)

def test_can_change_devices_for_hosted_app(self):
# Specify the free and paid. It shouldn't fail because you can't change
# payment types without explicitly specifying that.
self.platforms = {'free_platforms': ['free-desktop'],
'paid_platforms': ['paid-firefoxos']} # Ignored.
form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
assert form.is_valid(), form.errors
form.save()

self.assertSetEqual(self.addon.device_types, [amo.DEVICE_DESKTOP])


class TestPaidRereview(amo.tests.TestCase):
fixtures = fixture('webapp_337141') + ['market/prices']
Expand Down
4 changes: 3 additions & 1 deletion mkt/developers/tests/test_views_payments.py
Expand Up @@ -139,7 +139,9 @@ def get_postdata(self, base):
extension = {'regions': self.get_region_list(),
'other_regions': 'on',
'free_platforms': ['free-%s' % dt.class_name for dt in
self.webapp.device_types]}
self.webapp.device_types],
'paid_platforms': ['paid-%s' % dt.class_name for dt in
self.webapp.device_types],}
base.update(extension)
return base

Expand Down

0 comments on commit f495921

Please sign in to comment.