Exemplo n.º 1
0
 def test_can_purchase(self):
     self.make_premium(self.app, price='0.99')
     res = app_to_dict(self.app, region=regions.UK.id)
     res = app_to_dict(self.app, region=regions.UK.id)
     eq_(res['price'], None)
     eq_(res['price_locale'], None)
     eq_(res['payment_required'], True)
Exemplo n.º 2
0
 def test_can_purchase(self):
     self.make_premium(self.app, price='0.99')
     with self.settings(PURCHASE_ENABLED_REGIONS=[regions.UK.id]):
         res = app_to_dict(self.app, region=regions.UK.id)
     res = app_to_dict(self.app, region=regions.UK.id)
     eq_(res['price'], None)
     eq_(res['price_locale'], None)
     eq_(res['payment_required'], True)
Exemplo n.º 3
0
 def test_versions_multiple(self):
     ver = Version.objects.create(addon=self.app, version='1.9')
     self.app.update(_current_version=ver, _latest_version=ver)
     res = app_to_dict(self.app)
     eq_(res['current_version'], ver.version)
     self.assertSetEqual([v.version for v in self.app.versions.all()],
                         res['versions'].keys())
Exemplo n.º 4
0
 def test_categories(self):
     cat1 = Category.objects.create(type=amo.ADDON_WEBAPP, slug='cat1')
     cat2 = Category.objects.create(type=amo.ADDON_WEBAPP, slug='cat2')
     AddonCategory.objects.create(addon=self.app, category=cat1)
     AddonCategory.objects.create(addon=self.app, category=cat2)
     res = app_to_dict(self.app)
     self.assertSetEqual(res['categories'], ['cat1', 'cat2'])
Exemplo n.º 5
0
 def test_categories(self):
     cat1 = Category.objects.create(type=amo.ADDON_WEBAPP, slug="cat1")
     cat2 = Category.objects.create(type=amo.ADDON_WEBAPP, slug="cat2")
     AddonCategory.objects.create(addon=self.app, category=cat1)
     AddonCategory.objects.create(addon=self.app, category=cat2)
     res = app_to_dict(self.app)
     self.assertSetEqual(res["categories"], ["cat1", "cat2"])
Exemplo n.º 6
0
 def test_cannot_purchase(self):
     self.make_premium(self.app, price="0.99")
     with self.settings(PURCHASE_ENABLED_REGIONS=[]):
         res = app_to_dict(self.app, region=regions.UK.id)
     eq_(res["price"], None)
     eq_(res["price_locale"], None)
     eq_(res["payment_required"], True)
Exemplo n.º 7
0
 def test_with_preview(self):
     obj = Preview.objects.create(**{
         'filetype': 'image/png', 'thumbtype': 'image/png',
         'addon': self.app})
     preview = app_to_dict(self.app)['previews'][0]
     self.assertSetEqual(preview,
         ['filetype', 'id', 'image_url', 'thumbnail_url', 'resource_uri'])
     eq_(int(preview['id']), obj.pk)
Exemplo n.º 8
0
    def test_missing_price(self):
        premium = self.make_premium(self.app, price='0.99')
        premium.price = None
        premium.save()

        res = app_to_dict(self.app)
        eq_(res['price'], None)
        eq_(res['price_locale'], None)
Exemplo n.º 9
0
 def dehydrate(self, bundle):
     obj = bundle.obj
     amo_user = getattr(bundle.request, 'amo_user', None)
     bundle.data.update(app_to_dict(obj,
         currency=bundle.request.REGION.default_currency, profile=amo_user))
     bundle.data['privacy_policy'] = (
         PrivacyPolicyResource().get_resource_uri(bundle))
     return bundle
Exemplo n.º 10
0
 def test_with_preview(self):
     obj = Preview.objects.create(
         **{"caption": "foo", "filetype": "image/png", "thumbtype": "image/png", "addon": self.app}
     )
     preview = app_to_dict(self.app)["previews"][0]
     self.assertSetEqual(preview, ["caption", "filetype", "id", "image_url", "thumbnail_url", "resource_uri"])
     eq_(preview["caption"], "foo")
     eq_(int(preview["id"]), obj.pk)
Exemplo n.º 11
0
    def dehydrate(self, bundle):
        obj = bundle.obj
        amo_user = getattr(bundle.request, "amo_user", None)
        bundle.data.update(app_to_dict(obj, region=bundle.request.REGION.id, profile=amo_user, request=bundle.request))
        bundle.data["privacy_policy"] = PrivacyPolicyResource().get_resource_uri(bundle)

        self.dehydrate_extra(bundle)
        return bundle
Exemplo n.º 12
0
    def test_with_locale(self):
        premium = self.make_premium(self.app, price="0.99")
        PriceCurrency.objects.create(region=regions.PL.id, currency="PLN", price="5.01", tier=premium.price, provider=1)

        with self.activate(locale="fr"):
            res = app_to_dict(self.app, region=regions.PL.id)
            eq_(res["price"], Decimal("5.01"))
            eq_(res["price_locale"], u"5,01\xa0PLN")
Exemplo n.º 13
0
    def test_with_locale(self):
        premium = self.make_premium(self.app, price='0.99')
        PriceCurrency.objects.create(region=regions.PL.id, currency='PLN',
                                     price='5.01', tier=premium.price,
                                     provider=1)

        with self.activate(locale='fr'):
            res = app_to_dict(self.app, region=regions.PL.id)
            eq_(res['price'], Decimal('5.01'))
            eq_(res['price_locale'], u'5,01\xa0PLN')
Exemplo n.º 14
0
 def test_with_preview(self):
     obj = Preview.objects.create(**{'caption': 'foo',
         'filetype': 'image/png', 'thumbtype': 'image/png',
         'addon': self.app})
     preview = app_to_dict(self.app)['previews'][0]
     self.assertSetEqual(preview,
         ['caption', 'filetype', 'id', 'image_url', 'thumbnail_url',
          'resource_uri'])
     eq_(preview['caption'], 'foo')
     eq_(int(preview['id']), obj.pk)
Exemplo n.º 15
0
 def dehydrate(self, bundle):
     obj = bundle.obj
     user = getattr(bundle.request, 'user', None)
     bundle.data.update(app_to_dict(obj,
         currency=bundle.request.REGION.default_currency, user=user))
     bundle.data['upsell'] = False
     if obj.upsell:
         upsell_bundle = Bundle(obj=obj.upsell.premium,
                                request=bundle.request)
         bundle.data['upsell'] = self.full_dehydrate(upsell_bundle).data
     return bundle
Exemplo n.º 16
0
    def dehydrate(self, bundle):
        obj = bundle.obj
        amo_user = getattr(bundle.request, 'amo_user', None)
        bundle.data.update(app_to_dict(obj,
            region=bundle.request.REGION.id, profile=amo_user,
            request=bundle.request))
        bundle.data['privacy_policy'] = (
            PrivacyPolicyResource().get_resource_uri(bundle))

        self.dehydrate_extra(bundle)
        return bundle
Exemplo n.º 17
0
 def dehydrate(self, bundle):
     obj = bundle.obj
     user = getattr(bundle.request, 'user', None)
     bundle.data.update(app_to_dict(obj, user=user))
     bundle.data['upsell'] = False
     if obj.upsell:
         upsell_bundle = Bundle(obj=obj.upsell.premium,
                                request=bundle.request)
         bundle.data['upsell'] = self.full_dehydrate(upsell_bundle).data
     if not obj.has_price():
         bundle.data['price'] = None
     return bundle
Exemplo n.º 18
0
 def test_waffle_fallback_anon(self):
     flag = waffle.models.Flag.objects.get(name='allow-paid-app-search')
     flag.everyone = True
     flag.save()
     self.make_premium(self.app, price='0.99')
     req = RequestFactory().get('/')
     req.user = AnonymousUser()
     with self.settings(PURCHASE_ENABLED_REGIONS=[]):
         res = app_to_dict(self.app, region=regions.US.id, request=req)
     eq_(res['price'], Decimal('0.99'))
     eq_(res['price_locale'], '$0.99')
     eq_(res['payment_required'], True)
Exemplo n.º 19
0
 def dehydrate(self, bundle):
     obj = bundle.obj
     user = getattr(bundle.request, 'user', None)
     bundle.data.update(app_to_dict(obj, user=user))
     bundle.data['upsell'] = False
     if obj.upsell:
         upsell_bundle = Bundle(obj=obj.upsell.premium,
                                request=bundle.request)
         bundle.data['upsell'] = self.full_dehydrate(upsell_bundle).data
     if not obj.has_price():
         bundle.data['price'] = None
     return bundle
Exemplo n.º 20
0
 def dehydrate(self, bundle):
     obj = bundle.obj
     amo_user = getattr(bundle.request, 'amo_user', None)
     bundle.data.update(app_to_dict(obj,
         currency=bundle.request.REGION.default_currency, profile=amo_user))
     bundle.data['upsell'] = False
     bundle.data['privacy_policy'] = PrivacyPolicyResource().get_resource_uri(bundle)
     if obj.upsell:
         upsell_bundle = Bundle(obj=obj.upsell.premium,
                                request=bundle.request)
         bundle.data['upsell'] = self.full_dehydrate(upsell_bundle).data
     return bundle
Exemplo n.º 21
0
    def dehydrate(self, bundle):
        obj = bundle.obj
        amo_user = getattr(bundle.request, 'amo_user', None)
        bundle.data.update(app_to_dict(obj,
            region=bundle.request.REGION.id, profile=amo_user))
        bundle.data['privacy_policy'] = (
            PrivacyPolicyResource().get_resource_uri(bundle))

        # Add extra data for reviewers. Used in reviewer tool search.
        bundle = update_with_reviewer_data(bundle)

        return bundle
Exemplo n.º 22
0
    def dehydrate(self, bundle):
        obj = bundle.obj
        amo_user = getattr(bundle.request, 'amo_user', None)
        region = (bundle.request.REGION.id if hasattr(bundle.request, 'REGION')
                  else None)
        bundle.data.update(app_to_dict(obj, region=region, profile=amo_user,
                                       request=bundle.request))
        bundle.data['privacy_policy'] = (
            PrivacyPolicyResource().get_resource_uri(bundle))

        self.dehydrate_extra(bundle)
        return bundle
Exemplo n.º 23
0
    def test_waffle_fallback(self):
        self.make_premium(self.app, price='0.99')
        flag = waffle.models.Flag.objects.get(name='override-app-purchase')
        flag.everyone = None
        flag.users.add(self.profile.user)
        flag.save()

        req = RequestFactory().get('/')
        req.user = self.profile.user
        with self.settings(PURCHASE_LIMITED=True):
            res = app_to_dict(self.app, region=regions.US.id, request=req)
        eq_(res['price'], Decimal('0.99'))
        eq_(res['price_locale'], '$0.99')
        eq_(res['payment_required'], True)
Exemplo n.º 24
0
    def test_waffle_fallback(self):
        self.make_premium(self.app, price="0.99")
        flag = waffle.models.Flag.objects.get(name="allow-paid-app-search")
        flag.everyone = None
        flag.users.add(self.profile.user)
        flag.save()

        req = RequestFactory().get("/")
        req.user = self.profile.user
        with self.settings(PURCHASE_ENABLED_REGIONS=[]):
            res = app_to_dict(self.app, region=regions.US.id, request=req)
        eq_(res["price"], Decimal("0.99"))
        eq_(res["price_locale"], "$0.99")
        eq_(res["payment_required"], True)
Exemplo n.º 25
0
 def test_content_ratings(self):
     self.app.set_content_ratings({
         ratingsbodies.CLASSIND: ratingsbodies.CLASSIND_18,
         ratingsbodies.GENERIC: ratingsbodies.GENERIC_18,
     })
     res = app_to_dict(self.app)
     eq_(res['content_ratings']['ratings']['br'],
         {'body': 'CLASSIND',
          'body_label': 'classind',
          'rating': 'For ages 18+',
          'rating_label': '18',
          'description': unicode(ratingsbodies.CLASSIND_18.description)})
     eq_(res['content_ratings']['ratings']['generic'],
         {'body': 'Generic',
          'body_label': 'generic',
          'rating': 'For ages 18+',
          'rating_label': '18',
          'description': unicode(ratingsbodies.GENERIC_18.description)})
Exemplo n.º 26
0
 def test_current_version(self):
     res = app_to_dict(self.app)
     ok_('current_version' in res)
     eq_(res['current_version'], self.app.current_version.version)
Exemplo n.º 27
0
 def test_regions(self):
     res = app_to_dict(self.app)
     self.assertSetEqual([region['slug'] for region in res['regions']],
                         [region.slug for region in self.app.get_regions()])
Exemplo n.º 28
0
 def test_multiple_locales(self):
     self.app.current_version.update(supported_locales='en-US,it')
     res = app_to_dict(self.app)
     self.assertSetEqual(res['supported_locales'], ['en-US', 'it'])
Exemplo n.º 29
0
 def test_locales(self):
     res = app_to_dict(self.app)
     eq_(res['default_locale'], 'en-US')
     eq_(res['supported_locales'], [])
Exemplo n.º 30
0
 def test_all_features(self):
     data = dict(('has_' + f.lower(), True) for f in APP_FEATURES)
     self.features.update(**data)
     res = app_to_dict(self.app)
     self.assertSetEqual(res['current_version']['required_features'],
                         [f.lower() for f in APP_FEATURES])
Exemplo n.º 31
0
 def test_multiple_locales(self):
     self.app.current_version.update(supported_locales='en-US,it')
     res = app_to_dict(self.app)
     self.assertSetEqual(res['supported_locales'], ['en-US', 'it'])
Exemplo n.º 32
0
 def test_no_features(self):
     res = app_to_dict(self.app)
     self.assertSetEqual(res['current_version']['required_features'], [])
Exemplo n.º 33
0
 def test_versions_one(self):
     res = app_to_dict(self.app)
     self.assertSetEqual([v.version for v in self.app.versions.all()],
                         res['versions'].keys())
Exemplo n.º 34
0
 def test_to_native(self):
     membership = self.collection.collectionmembership_set.all()[0]
     native = self.field.to_native(membership)
     eq_(native, app_to_dict(self.app))
Exemplo n.º 35
0
 def test_some_price(self):
     self.make_premium(self.app, price='0.99')
     res = app_to_dict(self.app, region=regions.US.id)
     eq_(res['price'], Decimal('0.99'))
     eq_(res['price_locale'], '$0.99')
     eq_(res['payment_required'], True)
Exemplo n.º 36
0
 def test_no_price(self):
     res = app_to_dict(self.app)
     eq_(res['price'], None)
     eq_(res['price_locale'], None)
Exemplo n.º 37
0
 def test_some_price(self):
     res = app_to_dict(self.app)
     eq_(res['price'], Decimal('0.99'))
     eq_(res['price_locale'], '$0.99')
Exemplo n.º 38
0
 def test_no_charge(self):
     self.make_premium(self.app, price='0.00')
     res = app_to_dict(self.app, region=regions.US.id)
     eq_(res['price'], Decimal('0.00'))
     eq_(res['price_locale'], '$0.00')
     eq_(res['payment_required'], False)
Exemplo n.º 39
0
 def test_wrong_region(self):
     self.make_premium(self.app, price='0.99')
     res = app_to_dict(self.app, region=regions.PL.id)
     eq_(res['price'], None)
     eq_(res['price_locale'], None)
     eq_(res['payment_required'], True)
Exemplo n.º 40
0
 def test_no_previews(self):
     eq_(app_to_dict(self.app)['previews'], [])
Exemplo n.º 41
0
 def test_owned(self):
     self.app.addonuser_set.create(user=self.profile)
     res = app_to_dict(self.app, profile=self.profile)
     self.check_profile(res['user'], developed=True)
Exemplo n.º 42
0
 def test_purchased(self):
     self.app.addonpurchase_set.create(user=self.profile)
     res = app_to_dict(self.app, profile=self.profile)
     self.check_profile(res['user'], purchased=True)
Exemplo n.º 43
0
 def test_missing_price(self):
     self.premium.update(price=None)
     res = app_to_dict(self.app)
     eq_(res['price'], None)
     eq_(res['price_locale'], None)
Exemplo n.º 44
0
 def test_locales(self):
     res = app_to_dict(self.app)
     eq_(res['default_locale'], 'en-US')
     eq_(res['supported_locales'], [])
Exemplo n.º 45
0
 def test_no_rating(self):
     eq_(app_to_dict(self.app)['content_ratings'], None)
Exemplo n.º 46
0
 def test_regions(self):
     res = app_to_dict(self.app)
     self.assertSetEqual([region['slug'] for region in res['regions']],
                         [region.slug for region in self.app.get_regions()])
Exemplo n.º 47
0
 def test_no_price(self):
     res = app_to_dict(self.app)
     eq_(res['price'], None)
     eq_(res['price_locale'], None)
     eq_(res['payment_required'], False)
Exemplo n.º 48
0
 def test_one_feature(self):
     self.features.update(has_pay=True)
     res = app_to_dict(self.app)
     self.assertSetEqual(res['current_version']['required_features'],
                         ['pay'])
Exemplo n.º 49
0
 def test_installed(self):
     self.app.installed.create(user=self.profile)
     res = app_to_dict(self.app, profile=self.profile)
     self.check_profile(res['user'], installed=True)
Exemplo n.º 50
0
 def test_with_locale(self):
     with self.activate(locale='fr'):
         res = app_to_dict(self.app)
         eq_(res['price'], Decimal('5.01'))
         eq_(res['price_locale'], u'5,01\xa0\u20ac')
Exemplo n.º 51
0
 def test_purchased(self):
     self.app.addonpurchase_set.create(user=self.profile)
     res = app_to_dict(self.app, profile=self.profile)
     self.check_profile(res['user'], purchased=True)
Exemplo n.º 52
0
 def test_owned(self):
     self.app.addonuser_set.create(user=self.profile)
     res = app_to_dict(self.app, profile=self.profile)
     self.check_profile(res['user'], developed=True)
Exemplo n.º 53
0
 def to_native(self, value):
     return app_to_dict(value.app)