本文整理汇总了Python中mkt.webapps.utils.es_app_to_dict函数的典型用法代码示例。如果您正苦于以下问题:Python es_app_to_dict函数的具体用法?Python es_app_to_dict怎么用?Python es_app_to_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了es_app_to_dict函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_devices
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"])
示例2: test_content_ratings
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'}])
示例3: test_icons
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"))
示例4: test_basic
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))
示例5: test_content_ratings
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'}])
示例6: serialize
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
示例7: test_has_price
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')
示例8: test_content_ratings_regions
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')
示例9: test_user_not_mine
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})
示例10: test_user
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})
示例11: test_no_currency
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)
示例12: test_has_price
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)
示例13: dehydrate
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
示例14: test_not_paid
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)
示例15: test_user
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})