Esempio n. 1
0
 def setUp(self):
     self.addon = Addon.objects.get(pk=337141)
     self.bundle = Bundle(data={'app': self.addon.pk})
     self.profile = UserProfile.objects.get(pk=2519)
     self.resource = ReceiptResource()
Esempio n. 2
0
 def setUp(self):
     self.addon = Addon.objects.get(pk=337141)
     self.bundle = Bundle(data={'app': self.addon.pk})
     self.profile = UserProfile.objects.get(pk=2519)
     self.resource = ReceiptResource()
Esempio n. 3
0
class TestReceipt(amo.tests.TestCase):
    fixtures = fixture('user_2519', 'webapp_337141')

    def setUp(self):
        self.addon = Addon.objects.get(pk=337141)
        self.bundle = Bundle(data={'app': self.addon.pk})
        self.profile = UserProfile.objects.get(pk=2519)
        self.resource = ReceiptResource()

    def get_request(self, profile):
        request = RequestFactory().post('/')
        if not profile:
            request.user = AnonymousUser()
        else:
            request.user = profile.user
            request.amo_user = profile
        return request

    def handle(self, profile):
        return self.resource.handle(self.bundle, self.get_request(profile))

    def test_pending_free_for_developer(self):
        AddonUser.objects.create(addon=self.addon, user=self.profile)
        self.addon.update(status=amo.STATUS_PENDING)
        ok_(self.handle(self.profile))

    def test_pending_free_for_anonymous(self):
        self.addon.update(status=amo.STATUS_PENDING)
        with self.assertImmediate(http.HttpForbidden):
            ok_(self.handle(None))

    def test_pending_paid_for_developer(self):
        AddonUser.objects.create(addon=self.addon, user=self.profile)
        self.addon.update(status=amo.STATUS_PENDING,
                          premium_type=amo.ADDON_PREMIUM)
        ok_(self.handle(self.profile))
        eq_(self.profile.installed_set.all()[0].install_type,
            apps.INSTALL_TYPE_DEVELOPER)

    def test_pending_paid_for_anonymous(self):
        self.addon.update(status=amo.STATUS_PENDING,
                          premium_type=amo.ADDON_PREMIUM)
        with self.assertImmediate(http.HttpForbidden):
            ok_(self.handle(None))

    def test_not_record_addon(self):
        self.addon.update(type=amo.ADDON_EXTENSION)
        with self.assertImmediate(http.HttpBadRequest):
            ok_(self.handle(self.profile))

    @mock.patch('mkt.webapps.models.Webapp.has_purchased')
    def test_paid(self, has_purchased):
        has_purchased.return_value = True
        self.addon.update(premium_type=amo.ADDON_PREMIUM)
        ok_(self.handle(self.profile))

    def test_own_payments(self):
        self.addon.update(premium_type=amo.ADDON_OTHER_INAPP)
        ok_(self.handle(self.profile))

    def test_no_charge(self):
        self.make_premium(self.addon, '0.00')
        ok_(self.handle(self.profile))
        eq_(self.profile.installed_set.all()[0].install_type,
            apps.INSTALL_TYPE_USER)
        eq_(self.profile.addonpurchase_set.all()[0].type,
            CONTRIB_NO_CHARGE)

    @mock.patch('mkt.webapps.models.Webapp.has_purchased')
    def test_not_paid(self, has_purchased):
        has_purchased.return_value = False
        self.addon.update(premium_type=amo.ADDON_PREMIUM)
        with self.assertImmediate(HttpPaymentRequired):
            ok_(self.handle(self.profile))

    @mock.patch('mkt.receipts.api.receipt_cef.log')
    def test_record_install(self, cef):
        ok_(self.handle(self.profile))
        installed = self.profile.installed_set.all()
        eq_(len(installed), 1)
        eq_(installed[0].install_type, apps.INSTALL_TYPE_USER)

    @mock.patch('mkt.receipts.api.receipt_cef.log')
    def test_record_multiple_installs(self, cef):
        ok_(self.handle(self.profile))
        ok_(self.handle(self.profile))
        eq_(self.profile.installed_set.count(), 1)

    @mock.patch('mkt.receipts.api.receipt_cef.log')
    def test_record_receipt(self, cef):
        res = self.handle(self.profile)
        ok_(Receipt(res).receipt_decoded())
Esempio n. 4
0
class TestReceipt(amo.tests.TestCase):
    fixtures = fixture('user_2519', 'webapp_337141')

    def setUp(self):
        self.addon = Addon.objects.get(pk=337141)
        self.bundle = Bundle(data={'app': self.addon.pk})
        self.profile = UserProfile.objects.get(pk=2519)
        self.resource = ReceiptResource()

    def get_request(self, profile):
        request = RequestFactory().post('/')
        if not profile:
            request.user = AnonymousUser()
        else:
            request.user = profile.user
            request.amo_user = profile
        return request

    def handle(self, profile):
        return self.resource.handle(self.bundle, self.get_request(profile))

    def test_pending_free_for_developer(self):
        AddonUser.objects.create(addon=self.addon, user=self.profile)
        self.addon.update(status=amo.STATUS_PENDING)
        ok_(self.handle(self.profile))

    def test_pending_free_for_anonymous(self):
        self.addon.update(status=amo.STATUS_PENDING)
        with self.assertImmediate(http.HttpForbidden):
            ok_(self.handle(None))

    def test_pending_paid_for_developer(self):
        AddonUser.objects.create(addon=self.addon, user=self.profile)
        self.addon.update(status=amo.STATUS_PENDING,
                          premium_type=amo.ADDON_PREMIUM)
        ok_(self.handle(self.profile))
        eq_(self.profile.installed_set.all()[0].install_type,
            apps.INSTALL_TYPE_DEVELOPER)

    def test_pending_paid_for_anonymous(self):
        self.addon.update(status=amo.STATUS_PENDING,
                          premium_type=amo.ADDON_PREMIUM)
        with self.assertImmediate(http.HttpForbidden):
            ok_(self.handle(None))

    def test_not_record_addon(self):
        self.addon.update(type=amo.ADDON_EXTENSION)
        with self.assertImmediate(http.HttpBadRequest):
            ok_(self.handle(self.profile))

    @mock.patch('mkt.webapps.models.Webapp.has_purchased')
    def test_paid(self, has_purchased):
        has_purchased.return_value = True
        self.addon.update(premium_type=amo.ADDON_PREMIUM)
        ok_(self.handle(self.profile))

    def test_own_payments(self):
        self.addon.update(premium_type=amo.ADDON_OTHER_INAPP)
        ok_(self.handle(self.profile))

    def test_no_charge(self):
        self.make_premium(self.addon, '0.00')
        ok_(self.handle(self.profile))
        eq_(self.profile.installed_set.all()[0].install_type,
            apps.INSTALL_TYPE_USER)
        eq_(self.profile.addonpurchase_set.all()[0].type, CONTRIB_NO_CHARGE)

    @mock.patch('mkt.webapps.models.Webapp.has_purchased')
    def test_not_paid(self, has_purchased):
        has_purchased.return_value = False
        self.addon.update(premium_type=amo.ADDON_PREMIUM)
        with self.assertImmediate(HttpPaymentRequired):
            ok_(self.handle(self.profile))

    @mock.patch('mkt.receipts.api.receipt_cef.log')
    def test_record_install(self, cef):
        ok_(self.handle(self.profile))
        installed = self.profile.installed_set.all()
        eq_(len(installed), 1)
        eq_(installed[0].install_type, apps.INSTALL_TYPE_USER)

    @mock.patch('mkt.receipts.api.receipt_cef.log')
    def test_record_multiple_installs(self, cef):
        ok_(self.handle(self.profile))
        ok_(self.handle(self.profile))
        eq_(self.profile.installed_set.count(), 1)

    @mock.patch('mkt.receipts.api.receipt_cef.log')
    def test_record_receipt(self, cef):
        res = self.handle(self.profile)
        ok_(Receipt(res).receipt_decoded())