Report which features are present if passed a profile in features list API (bug 980409)

This commit is contained in:
Mathieu Pillard 2014-03-06 17:35:54 +01:00
Родитель 062e6775b1
Коммит 3049dc4c3d
3 изменённых файлов: 41 добавлений и 7 удалений

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

@ -18,6 +18,24 @@ Features List
:status 200: successfully completed.
The response will be an object with each key representing a feature. The
following parameters will be set for each feature:
:param position: the position of the feature in the list
:type position: int
:param name: the feature name
:type name: string
:param description: the feature description
:type description: string
If a :ref:`feature profile <feature-profile-label>` is passed,
then each feature will also contain the following:
:param present: a boolean indicating whether the feature is present in the
profile passed to the request.
:type present: boolean
Example:
.. code-block:: json

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

@ -5,7 +5,7 @@ from nose.tools import eq_
from django.core.urlresolvers import reverse
from mkt.api.tests.test_oauth import RestOAuth
from mkt.constants import APP_FEATURES
from mkt.constants.features import APP_FEATURES, FeatureProfile
class TestConfig(RestOAuth):
@ -16,7 +16,7 @@ class TestConfig(RestOAuth):
def _test_response(self, res):
eq_(res.status_code, 200)
data = json.loads(res.content)
data = res.json
eq_(len(data), len(APP_FEATURES))
self.assertSetEqual(data.keys(),
[f.lower() for f in APP_FEATURES.keys()])
@ -24,6 +24,13 @@ class TestConfig(RestOAuth):
name = feature[0].lower()
eq_(i + 1, data[name]['position'])
def test_with_profile(self):
profile = FeatureProfile(apps=True).to_signature()
res = self.anon.get(self.url, {'pro': profile})
self._test_response(res)
eq_(res.json['apps']['present'], True)
eq_(res.json['audio']['present'], False)
def test_anon(self):
res = self.anon.get(self.url)
self._test_response(res)

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

@ -4,21 +4,30 @@ from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from mkt.constants import APP_FEATURES
from mkt.api.base import CORSMixin
from mkt.constants.features import APP_FEATURES, FeatureProfile
class AppFeaturesList(APIView):
class AppFeaturesList(CORSMixin, APIView):
authentication_classes = permission_classes = []
cors_allowed_methods = ['get']
def _feature(self, i, slug):
feature = APP_FEATURES[slug.upper()]
return (slug.lower(), {
data = {
'name': feature['name'],
'description': feature['description'],
'position': i + 1
})
'position': i + 1,
}
if self.profile:
data['present'] = self.profile.get(slug.lower(), False)
return (slug.lower(), data)
def get(self, request, *args, **kwargs):
if 'pro' in request.GET:
self.profile = FeatureProfile.from_signature(request.GET['pro'])
else:
self.profile = None
features = OrderedDict(self._feature(i, slug) for i, slug in
enumerate(APP_FEATURES.keys()))
return Response(features, status=status.HTTP_200_OK)