cope with install_type on the postback (bug 837257)
This commit is contained in:
Родитель
7eae98b3b4
Коммит
4c8a170857
|
@ -11,6 +11,7 @@ import amo.models
|
|||
from amo.decorators import write
|
||||
from amo.utils import get_locale_from_lang, memoize_key
|
||||
from constants.payments import PROVIDER_CURRENCIES
|
||||
from mkt.constants import apps
|
||||
from stats.models import Contribution
|
||||
from users.models import UserProfile
|
||||
|
||||
|
@ -173,9 +174,16 @@ def create_addon_purchase(sender, instance, **kw):
|
|||
data = {'addon': instance.addon, 'user': instance.user}
|
||||
purchase, created = AddonPurchase.objects.safer_get_or_create(**data)
|
||||
purchase.update(type=amo.CONTRIB_PURCHASE)
|
||||
from mkt.webapps.models import Installed # Circular import.
|
||||
from mkt.webapps.models import Installed # Circular import
|
||||
# Ensure that devs have the correct installed object found
|
||||
# or created.
|
||||
#
|
||||
is_dev = instance.addon.has_author(instance.user,
|
||||
(amo.AUTHOR_ROLE_OWNER, amo.AUTHOR_ROLE_DEV))
|
||||
install_type = (apps.INSTALL_TYPE_DEVELOPER if is_dev
|
||||
else apps.INSTALL_TYPE_USER)
|
||||
Installed.objects.safer_get_or_create(user=instance.user,
|
||||
addon=instance.addon)
|
||||
addon=instance.addon, install_type=install_type)
|
||||
|
||||
elif instance.type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]:
|
||||
purchases = AddonPurchase.objects.filter(addon=instance.addon,
|
||||
|
|
|
@ -8,9 +8,10 @@ from nose.tools import eq_
|
|||
|
||||
import amo
|
||||
import amo.tests
|
||||
from addons.models import Addon
|
||||
from addons.models import Addon, AddonUser
|
||||
from market.models import (AddonPremium, PreApprovalUser, Price, PriceCurrency,
|
||||
Refund)
|
||||
from mkt.constants import apps
|
||||
from stats.models import Contribution
|
||||
from users.models import UserProfile
|
||||
|
||||
|
@ -226,7 +227,20 @@ class TestContribution(ContributionMixin, amo.tests.TestCase):
|
|||
self.create(amo.CONTRIB_REFUND)
|
||||
eq_(self.addon.addonpurchase_set.filter(user=other).count(), 1)
|
||||
|
||||
def test_user_installed(self):
|
||||
def set_role(self, role):
|
||||
AddonUser.objects.create(addon=self.addon, user=self.user, role=role)
|
||||
self.create(amo.CONTRIB_PURCHASE)
|
||||
installed = self.user.installed_set.filter(addon=self.addon)
|
||||
eq_(installed.count(), 1)
|
||||
eq_(installed[0].install_type, apps.INSTALL_TYPE_DEVELOPER)
|
||||
|
||||
def test_user_dev(self):
|
||||
self.set_role(amo.AUTHOR_ROLE_DEV)
|
||||
|
||||
def test_user_owner(self):
|
||||
self.set_role(amo.AUTHOR_ROLE_OWNER)
|
||||
|
||||
def test_user_installed_dev(self):
|
||||
self.create(amo.CONTRIB_PURCHASE)
|
||||
eq_(self.user.installed_set.filter(addon=self.addon).count(), 1)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче