Updated Search API to use AppResource (bug 838914)
This commit is contained in:
Родитель
9bbd23c2c3
Коммит
fba559bec9
|
@ -1,25 +1,24 @@
|
|||
from tastypie.serializers import Serializer
|
||||
from tastypie.authentication import Authentication
|
||||
from tastypie.authorization import ReadOnlyAuthorization
|
||||
|
||||
import amo
|
||||
from amo.helpers import absolutify
|
||||
|
||||
import mkt
|
||||
from mkt.api.base import MarketplaceResource
|
||||
from mkt.api.resources import AppResource
|
||||
from mkt.search.views import _get_query, _filter_search
|
||||
from mkt.search.forms import ApiSearchForm
|
||||
from mkt.webapps.models import Webapp
|
||||
|
||||
|
||||
class SearchResource(MarketplaceResource):
|
||||
class SearchResource(AppResource):
|
||||
|
||||
class Meta:
|
||||
available_methods = []
|
||||
list_available_methods = ['get', 'post']
|
||||
fields = ['id', 'name', 'description', 'premium_type', 'slug',
|
||||
'summary']
|
||||
object_class = Webapp
|
||||
class Meta(AppResource.Meta):
|
||||
resource_name = 'search'
|
||||
serializer = Serializer(formats=['json'])
|
||||
allowed_methods = []
|
||||
detail_allowed_methods = []
|
||||
list_allowed_methods = ['get']
|
||||
authorization = ReadOnlyAuthorization()
|
||||
authentication = Authentication()
|
||||
|
||||
def get_resource_uri(self, bundle):
|
||||
# At this time we don't have an API to the Webapp details.
|
||||
|
@ -49,6 +48,7 @@ class SearchResource(MarketplaceResource):
|
|||
return bundle.obj.app_slug
|
||||
|
||||
def dehydrate(self, bundle):
|
||||
bundle = super(SearchResource, self).dehydrate(bundle)
|
||||
for size in amo.ADDON_ICON_SIZES:
|
||||
bundle.data['icon_url_%s' % size] = bundle.obj.get_icon_url(size)
|
||||
bundle.data['absolute_url'] = absolutify(bundle.obj.get_detail_url())
|
||||
|
|
|
@ -66,7 +66,7 @@ class TestApi(BaseOAuth, ESTestCase):
|
|||
res = self.client.get(self.list_url + ({'cat': self.category.pk},))
|
||||
eq_(res.status_code, 200)
|
||||
obj = json.loads(res.content)['objects'][0]
|
||||
eq_(obj['slug'], self.webapp.app_slug)
|
||||
eq_(obj['app_slug'], self.webapp.app_slug)
|
||||
eq_(obj['icon_url_128'], self.webapp.get_icon_url(128))
|
||||
eq_(obj['absolute_url'], self.webapp.get_absolute_url())
|
||||
eq_(obj['resource_uri'], None)
|
||||
|
|
Загрузка…
Ссылка в новой задаче