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

Commit

Permalink
make 0.99 the default, if it exists (bug 879093)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy McKay committed Jun 18, 2013
1 parent c516af5 commit 0251006
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 12 additions & 8 deletions mkt/developers/forms_payments.py
Expand Up @@ -90,10 +90,8 @@ def __init__(self, *args, **kw):
self.initial['free_platforms'].append('free-%s' % platform)
self.initial['paid_platforms'].append('paid-%s' % platform)

if (not self.initial.get('price') and
len(self.fields['price'].choices) > 1):
# Tier 0 (Free) should not be the default selection.
self.initial['price'] = self._initial_price().pk
if not self.initial.get('price'):
self.initial['price'] = self._initial_price_id()

self.fields['price'].choices = self.group_tier_choices()

Expand Down Expand Up @@ -133,15 +131,21 @@ def group_tier_choices(self):

return price_choices

def _initial_price(self):
return Price.objects.active().exclude(price='0.00')[0]
def _initial_price_id(self):
"""Sets the inital price tier if available."""
try:
return Price.objects.active().get(price='0.99').id
except Price.DoesNotExist:
log.warning('Could not find a price tier 0.99 to set as default.')
return None

def _make_premium(self):
if self.addon.premium:
return self.addon.premium

log.info('New AddonPremium object for addon %s' % self.addon.pk)
return AddonPremium(addon=self.addon, price=self._initial_price())
return AddonPremium(addon=self.addon,
price_id=self._initial_price_id())

def is_paid(self):
return self.addon.premium_type in amo.ADDON_PREMIUMS
Expand Down Expand Up @@ -206,7 +210,7 @@ def save(self):
# Toggle free apps to paid by giving them a premium object.

premium = self._make_premium()
premium.price = self._initial_price()
premium.price_id = self._initial_price_id()
premium.save()

self.addon.premium_type = amo.ADDON_PREMIUM
Expand Down
9 changes: 9 additions & 0 deletions mkt/developers/tests/test_forms_payments.py
Expand Up @@ -220,6 +220,15 @@ def test_can_change_devices_for_packaged_app(self):

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

def test_initial(self):
form = forms_payments.PremiumForm(**self.kwargs)
eq_(form._initial_price_id(), Price.objects.get(price='0.99').pk)

def test_initial_not_there(self):
Price.objects.get(price='0.99').update(active=False)
form = forms_payments.PremiumForm(**self.kwargs)
eq_(form._initial_price_id(), None)


class TestPaidRereview(amo.tests.TestCase):
fixtures = fixture('webapp_337141') + ['market/prices']
Expand Down

0 comments on commit 0251006

Please sign in to comment.