Add downloads count and creation date to the app API results (bug 867839)

This commit is contained in:
Mathieu Pillard 2013-06-21 17:58:01 +02:00
Родитель 238189ebb7
Коммит e6e72f5be6
2 изменённых файлов: 18 добавлений и 4 удалений

Просмотреть файл

@ -143,6 +143,7 @@ class TestESAppToDict(amo.tests.ESTestCase):
expected = {
'absolute_url': 'http://testserver/app/something-something/',
'app_type': 'hosted',
'created': '2011-10-18T16:28:24',
'current_version': {
'release_notes': None,
'version': '1.0',
@ -172,13 +173,21 @@ class TestESAppToDict(amo.tests.ESTestCase):
'developed': False,
'installed': False,
'purchased': False,
}
},
'weekly_downloads': None,
}
for k, v in res.items():
if k in expected:
eq_(expected[k], v, u'Unexpected value for field: %s' % k)
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)
def test_icons(self):
"""
Tested separately b/c they have timestamps.

Просмотреть файл

@ -81,6 +81,7 @@ def app_to_dict(app, region=None, profile=None):
'name': cr.get_rating().name,
'description': unicode(cr.get_rating().description),
}) for cr in app.content_ratings.all()]) or None,
'created': app.created,
'current_version': version_data,
'default_locale': app.default_locale,
'image_assets': dict([(ia.slug, (ia.image_url, ia.hue))
@ -102,7 +103,8 @@ def app_to_dict(app, region=None, profile=None):
'regions': RegionResource().dehydrate_objects(app.get_regions()),
'slug': app.app_slug,
'supported_locales': (supported_locales.split(',') if supported_locales
else [])
else []),
'weekly_downloads': app.weekly_downloads if app.public_stats else None,
}
data['upsell'] = False
@ -176,9 +178,9 @@ def es_app_to_dict(obj, region=None, profile=None):
is_packaged = src['app_type'] == amo.ADDON_WEBAPP_PACKAGED
app = Webapp(app_slug=obj.app_slug, is_packaged=is_packaged)
attrs = ('content_ratings', 'current_version', 'default_locale',
attrs = ('content_ratings', 'created', 'current_version', 'default_locale',
'homepage', 'manifest_url', 'previews', 'ratings', 'status',
'support_email', 'support_url')
'support_email', 'support_url', 'weekly_downloads')
data = dict(zip(attrs, attrgetter(*attrs)(obj)))
data.update({
'absolute_url': absolutify(app.get_detail_url()),
@ -201,6 +203,9 @@ def es_app_to_dict(obj, region=None, profile=None):
'slug': obj.app_slug,
})
if not data['public_stats']:
data['weekly_downloads'] = None
data['regions'] = RegionResource().dehydrate_objects(
map(REGIONS_CHOICES_ID_DICT.get,
app.get_region_ids(worldwide=True,