def test_devices(self): AddonDeviceType.objects.create(addon=self.app, device_type=amo.DEVICE_GAIA.id) self.app.save() self.refresh("webapp") res = es_app_to_dict(self.get_obj()) eq_(res["device_types"], ["firefoxos"])
def test_content_ratings(self): self.app.set_content_ratings({ ratingsbodies.CLASSIND: ratingsbodies.CLASSIND_18, ratingsbodies.GENERIC: ratingsbodies.GENERIC_18, }) self.app.set_descriptors(['has_esrb_blood', 'has_pegi_scary']) self.app.set_interactives(['has_social_networking', 'has_shares_info']) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) 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)}) eq_(sorted(res['content_ratings']['descriptors'], key=lambda x: x['name']), [{'label': 'esrb-blood', 'name': 'Blood', 'ratings_body': 'esrb'}, {'label': 'pegi-scary', 'name': 'Fear', 'ratings_body': 'pegi'}]) eq_(sorted(res['content_ratings']['interactive_elements'], key=lambda x: x['name']), [{'label': 'shares-info', 'name': 'Shares Info'}, {'label': 'social-networking', 'name': 'Social Networking'}])
def test_content_ratings(self): self.create_switch('iarc') self.app.set_content_ratings({ ratingsbodies.CLASSIND: ratingsbodies.CLASSIND_18, ratingsbodies.GENERIC: ratingsbodies.GENERIC_18, }) self.app.set_descriptors(['has_esrb_blood', 'has_pegi_scary']) self.app.set_interactives(['has_digital_purchases', 'has_shares_info']) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) eq_(res['content_ratings']['ratings']['classind'], {'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)}) eq_(dict(res['content_ratings']['descriptors']), {'esrb': [{'label': 'blood', 'name': 'Blood'}], 'pegi': [{'label': 'scary', 'name': 'Fear'}]}) eq_(sorted(res['content_ratings']['interactive_elements'], key=lambda x: x['name']), [{'label': 'digital-purchases', 'name': 'Digital Purchases'}, {'label': 'shares-info', 'name': 'Shares Info'}])
def test_icons(self): """ Tested separately b/c they have timestamps. """ res = es_app_to_dict(self.get_obj()) self.assertSetEqual(set([16, 48, 64, 128]), set(res["icons"].keys())) ok_(res["icons"][128].startswith("http://testserver/img/uploads/addon_icons/337/337141-128.png"))
def test_basic(self): res = es_app_to_dict(self.get_obj()) expected = { "absolute_url": "http://testserver/app/something-something/", "app_type": "hosted", "author": "Mozilla Tester", "created": self.app.created, "current_version": "1.0", "description": u"Something Something Steamcube description!", "homepage": "", "id": "337141", "is_packaged": False, "latest_version": {"status": 4, "is_privileged": False}, "manifest_url": "http://micropipes.com/temp/steamcube.webapp", "name": "Something Something Steamcube!", "premium_type": "free", "public_stats": False, "ratings": {"average": 0.0, "count": 0}, "slug": "something-something", "status": 4, "support_email": None, "support_url": None, "user": {"developed": False, "installed": False, "purchased": False}, "versions": {"1.0": "/api/v1/apps/versions/1268829/"}, "weekly_downloads": None, } for k, v in res.items(): if k in expected: eq_(expected[k], v, u'Expected value "%s" for field "%s", got "%s"' % (expected[k], k, v))
def serialize(self, req, app): amo_user = getattr(req, 'amo_user', None) data = es_app_to_dict(app, region=req.REGION.id, profile=amo_user, request=req) data['resource_uri'] = reverse('app-detail', kwargs={'pk': data['id']}) return data
def test_devices(self): AddonDeviceType.objects.create(addon=self.app, device_type=amo.DEVICE_GAIA.id) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) eq_(res['device_types'], ['firefoxos'])
def test_has_price(self): self.make_premium(self.app) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) eq_(res['price'], Decimal('1.00')) eq_(res['price_locale'], '$1.00')
def test_content_ratings_regions(self): self.create_switch('iarc') res = es_app_to_dict(self.get_obj()) region_rating_bodies = res['content_ratings']['regions'] eq_(region_rating_bodies['br'], 'classind') eq_(region_rating_bodies['de'], 'usk') eq_(region_rating_bodies['es'], 'pegi') eq_(region_rating_bodies['us'], 'esrb')
def test_icons(self): """ Tested separately b/c they have timestamps. """ res = es_app_to_dict(self.get_obj()) self.assertSetEqual(set([16, 48, 64, 128]), set(res['icons'].keys())) ok_(res['icons'][128].startswith( 'http://testserver/img/uploads/addon_icons/337/337141-128.png'))
def test_user_not_mine(self): self.app.addonuser_set.create(user_id=31337) Installed.objects.create(addon=self.app, user_id=31337) self.app.addonpurchase_set.create(user_id=31337) self.app.save() self.refresh("webapp") res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res["user"], {"developed": False, "installed": False, "purchased": False})
def test_user(self): self.app.addonuser_set.create(user=self.profile) self.profile.installed_set.create(addon=self.app) self.app.addonpurchase_set.create(user=self.profile) self.app.save() self.refresh("webapp") res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res["user"], {"developed": True, "installed": True, "purchased": True})
def dehydrate(self, bundle): obj = bundle.obj amo_user = getattr(bundle.request, 'amo_user', None) bundle.data.update(es_app_to_dict(obj, region=bundle.request.REGION.id, profile=amo_user, request=bundle.request)) return bundle
def dehydrate(self, bundle): obj = bundle.obj amo_user = getattr(bundle.request, "amo_user", None) bundle.data.update( es_app_to_dict(obj, region=bundle.request.REGION.id, profile=amo_user, request=bundle.request) ) return bundle
def test_has_price(self): self.make_premium(self.app) self.app.save() self.refresh('webapp') req = amo.tests.req_factory_factory('/', data={'region': 'us'}) res = es_app_to_dict(self.get_obj(), request=req) eq_(res['price'], Decimal('1.00')) eq_(res['price_locale'], '$1.00') eq_(res['payment_required'], True) # Test invalid region. This falls back to the region set by the region # middleware. req = amo.tests.req_factory_factory('/', data={'region': 'xx'}) res = es_app_to_dict(self.get_obj(), request=req) eq_(res['price'], Decimal('1.00')) eq_(res['price_locale'], '$1.00') eq_(res['payment_required'], True)
def test_not_paid(self): self.make_premium(self.app) PriceCurrency.objects.update(paid=False) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) eq_(res['price'], None) eq_(res['price_locale'], None)
def test_no_currency(self): self.make_premium(self.app) PriceCurrency.objects.all().delete() self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) eq_(res['price'], None) eq_(res['price_locale'], None)
def test_user(self): self.app.addonuser_set.create(user=self.profile) self.profile.installed_set.create(addon=self.app) self.app.addonpurchase_set.create(user=self.profile) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res['user'], {'developed': True, 'installed': True, 'purchased': True})
def test_user(self): AddonPurchase.objects.create(addon=self.app, user=self.profile) Installed.objects.create(addon=self.app, user=self.profile) AddonUser.objects.create(addon=self.app, user=self.profile) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res['user'], {'developed': True, 'installed': True, 'purchased': True})
def test_user_not_mine(self): self.app.addonuser_set.create(user_id=31337) Installed.objects.create(addon=self.app, user_id=31337) self.app.addonpurchase_set.create(user_id=31337) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res['user'], {'developed': False, 'installed': False, 'purchased': False})
def test_user(self): self.app.addonuser_set.create(user=self.profile) self.profile.installed_set.create(addon=self.app) self.app.addonpurchase_set.create(user=self.profile) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res['user'], {'developed': True, 'installed': True, 'purchased': True})
def test_user_not_mine(self): self.app.addonuser_set.create(user_id=31337) Installed.objects.create(addon=self.app, user_id=31337) self.app.addonpurchase_set.create(user_id=31337) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res['user'], {'developed': False, 'installed': False, 'purchased': False})
def test_content_ratings_regions_no_switch(self): self.app.set_content_ratings({ ratingsbodies.CLASSIND: ratingsbodies.CLASSIND_18, ratingsbodies.GENERIC: ratingsbodies.GENERIC_18, }) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) assert 'us' not in res['content_ratings']['regions'] eq_(res['content_ratings']['regions']['br'], 'classind')
def test_content_ratings(self): rating = ratingsbodies.CLASSIND_18 self.app.content_ratings.create( ratings_body=ratingsbodies.CLASSIND.id, rating=rating.id) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) eq_(res['content_ratings'], {'br': [{'body': 'CLASSIND', 'name': rating.name, 'description': unicode(rating.description)}]})
def dehydrate(self, bundle): obj = bundle.obj amo_user = getattr(bundle.request, 'amo_user', None) bundle.data.update(es_app_to_dict(obj, region=bundle.request.REGION.id, profile=amo_user, request=bundle.request)) # Add extra data for reviewers. Used in reviewer tool search. bundle = update_with_reviewer_data(bundle, using_es=True) return bundle
def test_user(self): AddonPurchase.objects.create(addon=self.app, user=self.profile) Installed.objects.create(addon=self.app, user=self.profile) AddonUser.objects.create(addon=self.app, user=self.profile) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res['user'], { 'developed': True, 'installed': True, 'purchased': True, })
def test_user(self): Contribution.objects.create(addon=self.app, user=self.profile, amount='1.00', type=amo.CONTRIB_PURCHASE) Installed.objects.create(addon=self.app, user=self.profile) AddonUser.objects.create(addon=self.app, user=self.profile) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj(), profile=self.profile) eq_(res['user'], { 'developed': True, 'installed': True, 'purchased': True, })
def test_content_ratings(self): self.app.set_content_ratings({ ratingsbodies.CLASSIND: ratingsbodies.CLASSIND_18, ratingsbodies.GENERIC: ratingsbodies.GENERIC_18, }) self.app.set_descriptors(['has_esrb_blood', 'has_pegi_scary']) self.app.set_interactives(['has_social_networking', 'has_shares_info']) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) 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) }) eq_( sorted(res['content_ratings']['descriptors'], key=lambda x: x['name']), [{ 'label': 'esrb-blood', 'name': 'Blood', 'ratings_body': 'esrb' }, { 'label': 'pegi-scary', 'name': 'Fear', 'ratings_body': 'pegi' }]) eq_( sorted(res['content_ratings']['interactive_elements'], key=lambda x: x['name']), [{ 'label': 'shares-info', 'name': 'Shares Info' }, { 'label': 'social-networking', 'name': 'Social Networking' }])
def test_basic(self): res = es_app_to_dict(self.get_obj(), profile=self.profile) expected = { 'absolute_url': 'http://testserver/app/something-something/', 'app_type': 'hosted', 'author': 'Mozilla Tester', 'created': self.app.created, 'current_version': '1.0', 'default_locale': u'en-US', 'description': { u'en-US': u'Something Something Steamcube description!'}, 'homepage': None, 'id': '337141', 'is_offline': False, 'is_packaged': False, 'manifest_url': 'http://micropipes.com/temp/steamcube.webapp', 'name': {u'en-US': u'Something Something Steamcube!', u'es': u'Algo Algo Steamcube!'}, 'premium_type': 'free', 'public_stats': False, 'ratings': { 'average': 0.0, 'count': 0, }, 'reviewed': self.version.reviewed, 'slug': 'something-something', 'status': 4, 'support_email': None, 'support_url': None, 'supported_locales': [u'en-US', u'es', u'pt-BR'], 'upsell': False, 'user': { 'developed': False, 'installed': False, 'purchased': False, }, # 'version's handled below to support API URL assertions. 'weekly_downloads': None, } ok_('1.0' in res['versions']) self.assertApiUrlEqual(res['versions']['1.0'], '/apps/versions/1268829/') for k, v in expected.items(): eq_(res[k], v, u'Expected value "%s" for field "%s", got "%s"' % (v, k, res[k]))
def test_payment_account(self): self.make_premium(self.app) seller = SolitudeSeller.objects.create( resource_uri='/path/to/sel', uuid='seller-id', user=self.profile) account = PaymentAccount.objects.create( user=self.profile, uri='asdf', name='test', inactive=False, solitude_seller=seller, account_id=123) AddonPaymentAccount.objects.create( addon=self.app, account_uri='foo', payment_account=account, product_uri='bpruri') self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) eq_(res['payment_account'], reverse('payment-account-detail', kwargs={'pk': account.pk}))
def test_basic(self): res = es_app_to_dict(self.get_obj()) expected = { 'absolute_url': 'http://testserver/app/something-something/', 'app_type': 'hosted', 'author': 'Mozilla Tester', 'created': self.app.created, 'current_version': '1.0', 'description': u'Something Something Steamcube description!', 'homepage': '', 'id': '337141', 'is_packaged': False, 'latest_version': { 'status': 4, 'is_privileged': False }, 'manifest_url': 'http://micropipes.com/temp/steamcube.webapp', 'name': 'Something Something Steamcube!', 'premium_type': 'free', 'public_stats': False, 'ratings': { 'average': 0.0, 'count': 0, }, 'slug': 'something-something', 'status': 4, 'support_email': None, 'support_url': None, 'user': { 'developed': False, 'installed': False, 'purchased': False, }, 'versions': { '1.0': '/api/apps/versions/1268829/' }, 'weekly_downloads': None, } for k, v in res.items(): if k in expected: eq_( expected[k], v, u'Expected value "%s" for field "%s", got "%s"' % (expected[k], k, v))
def test_content_ratings_by_region(self): self.create_switch('iarc') self.app.set_content_ratings({ ratingsbodies.CLASSIND: ratingsbodies.CLASSIND_18, ratingsbodies.GENERIC: ratingsbodies.GENERIC_18, }) self.app.set_descriptors(['has_classind_lang', 'has_generic_lang']) self.app.save() self.refresh('webapp') req = amo.tests.req_factory_factory('/', data={'region': 'br'}) res = es_app_to_dict(self.get_obj(), request=req)['content_ratings'] for iarc_obj in ('ratings', 'descriptors', 'regions'): eq_(len(res[iarc_obj]), 1) for iarc_obj in ('ratings', 'descriptors'): assert 'classind' in res[iarc_obj], iarc_obj assert 'br' in res['regions']
def test_basic(self): res = es_app_to_dict(self.get_obj()) expected = { 'absolute_url': 'http://testserver/app/something-something/', 'app_type': 'hosted', 'author': 'Mozilla Tester', 'created': self.app.created, 'current_version': '1.0', 'description': u'Something Something Steamcube description!', 'homepage': '', 'id': '337141', 'is_packaged': False, 'latest_version': { 'status': 4, 'is_privileged': False }, 'manifest_url': 'http://micropipes.com/temp/steamcube.webapp', 'name': 'Something Something Steamcube!', 'premium_type': 'free', 'public_stats': False, 'ratings': { 'average': 0.0, 'count': 0, }, 'slug': 'something-something', 'status': 4, 'support_email': None, 'support_url': None, 'user': { 'developed': False, 'installed': False, 'purchased': False, }, 'versions': { '1.0': '/api/v1/apps/versions/1268829/' }, 'weekly_downloads': None, } for k, v in res.items(): if k in expected: eq_(expected[k], v, u'Expected value "%s" for field "%s", got "%s"' % (expected[k], k, v))
def dehydrate(self, bundle): obj = bundle.obj amo_user = getattr(bundle.request, 'amo_user', None) uses_es = waffle.switch_is_active('search-api-es') if uses_es: bundle.data.update(es_app_to_dict( obj, region=bundle.request.REGION.id, profile=amo_user)) else: bundle = AppResource().dehydrate(bundle) bundle.data['absolute_url'] = absolutify( bundle.obj.get_detail_url()) # Add extra data for reviewers. Used in reviewer tool search. bundle = update_with_reviewer_data(bundle) return bundle
def test_basic_with_lang(self): # Check that when ?lang is passed, we get the right language and we get # empty stings instead of None if the strings don't exist. request = RequestFactory().get('/?lang=es') res = es_app_to_dict(self.get_obj(), profile=self.profile, request=request) expected = { 'id': 337141, 'description': u'Something Something Steamcube description!', 'homepage': u'', 'name': u'Algo Algo Steamcube!', 'support_email': u'', 'support_url': u'', } for k, v in expected.items(): eq_(res[k], v, u'Expected value "%s" for field "%s", got "%s"' % (v, k, res[k]))
def dehydrate(self, bundle): obj = bundle.obj amo_user = getattr(bundle.request, 'amo_user', None) uses_es = waffle.switch_is_active('search-api-es') if uses_es: bundle.data.update( es_app_to_dict(obj, currency=bundle.request.REGION.default_currency, profile=amo_user)) else: bundle = AppResource().dehydrate(bundle) bundle.data['absolute_url'] = absolutify( bundle.obj.get_detail_url()) # Add extra data for reviewers. Used in reviewer tool search. # TODO: Reviewer flags in ES (bug 848446) if acl.action_allowed(bundle.request, 'Apps', 'Review'): addon_id = bundle.obj._id if uses_es else bundle.obj.id version = Version.objects.filter(addon_id=addon_id).latest() escalated = EscalationQueue.objects.filter( addon_id=addon_id).exists() if uses_es: bundle.data['latest_version_status'] = ( obj.latest_version_status) else: try: file_ = version and version.files.latest() bundle.data['latest_version_status'] = (file_.status if file_ else None) except ObjectDoesNotExist: bundle.data['latest_version_status'] = None bundle.data['reviewer_flags'] = { 'has_comment': version.has_editor_comment, 'has_info_request': version.has_info_request, 'is_escalated': escalated, } return bundle
def dehydrate(self, bundle): obj = bundle.obj amo_user = getattr(bundle.request, 'amo_user', None) uses_es = waffle.switch_is_active('search-api-es') if uses_es: bundle.data.update(es_app_to_dict( obj, currency=bundle.request.REGION.default_currency, profile=amo_user)) else: bundle = AppResource().dehydrate(bundle) bundle.data['absolute_url'] = absolutify( bundle.obj.get_detail_url()) # Add extra data for reviewers. Used in reviewer tool search. # TODO: Reviewer flags in ES (bug 848446) if acl.action_allowed(bundle.request, 'Apps', 'Review'): addon_id = bundle.obj._id if uses_es else bundle.obj.id version = Version.objects.filter(addon_id=addon_id).latest() escalated = EscalationQueue.objects.filter( addon_id=addon_id).exists() if uses_es: bundle.data['latest_version_status'] = ( obj.latest_version_status) else: try: file_ = version and version.files.latest() bundle.data['latest_version_status'] = ( file_.status if file_ else None) except ObjectDoesNotExist: bundle.data['latest_version_status'] = None bundle.data['reviewer_flags'] = { 'has_comment': version.has_editor_comment, 'has_info_request': version.has_info_request, 'is_escalated': escalated, } return bundle
def test_basic(self): res = es_app_to_dict(self.get_obj()) expected = { 'absolute_url': 'http://testserver/app/something-something/', 'app_type': 'hosted', 'current_version': { 'release_notes': None, 'version': '1.0', }, 'description': u'Something Something Steamcube description!', 'homepage': '', 'id': '337141', 'is_packaged': False, 'listed_authors': [ { 'name': u'31337 \u0627\u0644\u062a\u0637\u0628' }, ], 'manifest_url': 'http://micropipes.com/temp/steamcube.webapp', 'name': 'Something Something Steamcube!', 'premium_type': 'free', 'public_stats': False, 'ratings': { 'average': 0.0, 'count': 0, }, 'slug': 'something-something', 'status': 4, 'summary': u'', 'support_email': None, 'support_url': None, 'user': { 'developed': False, 'installed': False, 'purchased': False, } } for k, v in res.items(): if k in expected: eq_(expected[k], v, u'Unexpected value for field: %s' % k)
def test_basic(self): res = es_app_to_dict(self.get_obj()) expected = { 'absolute_url': 'http://testserver/app/something-something/', 'app_type': 'hosted', 'current_version': { 'release_notes': None, 'version': '1.0', 'developer_name': u'31337 \u0627\u0644\u062a\u0637\u0628' }, 'description': u'Something Something Steamcube description!', 'homepage': '', 'id': '337141', 'is_packaged': False, 'listed_authors': [ {'name': u'31337 \u0627\u0644\u062a\u0637\u0628'}, ], 'manifest_url': 'http://micropipes.com/temp/steamcube.webapp', 'name': 'Something Something Steamcube!', 'premium_type': 'free', 'public_stats': False, 'ratings': { 'average': 0.0, 'count': 0, }, 'slug': 'something-something', 'status': 4, 'summary': u'', 'support_email': None, 'support_url': None, 'user': { 'developed': False, 'installed': False, 'purchased': False, } } for k, v in res.items(): if k in expected: eq_(expected[k], v, u'Unexpected value for field: %s' % k)
def test_content_ratings_no_switch(self): self.app.set_content_ratings({ ratingsbodies.CLASSIND: ratingsbodies.CLASSIND_18, ratingsbodies.GENERIC: ratingsbodies.GENERIC_18, }) self.app.save() self.refresh('webapp') res = es_app_to_dict(self.get_obj()) assert 'us' not in res['content_ratings']['ratings'] assert 'generic' not in res['content_ratings']['ratings'] 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']['de'], {'body': 'Generic', 'body_label': 'generic', 'rating': 'For ages 18+', 'rating_label': '18', 'description': unicode(ratingsbodies.GENERIC_18.description)})
def test_show_downloads_count(self): """Show weekly_downloads in results if app stats are public.""" self.app.update(public_stats=True) self.refresh('webapp') res = es_app_to_dict(self.get_obj()) eq_(res['weekly_downloads'], 9999)