From cd3ce77f7e768757b26fddc1a190d9c856a67b22 Mon Sep 17 00:00:00 2001 From: Allen Short Date: Wed, 24 Apr 2013 11:55:26 -0700 Subject: [PATCH] clean up regions/carriers --- docs/api/topics/misc.rst | 12 ++++++------ mkt/api/resources.py | 26 ++------------------------ mkt/api/tests/test_handlers.py | 10 +++++----- mkt/api/urls.py | 4 ++-- 4 files changed, 15 insertions(+), 37 deletions(-) diff --git a/docs/api/topics/misc.rst b/docs/api/topics/misc.rst index 458624395e..ec3a787350 100644 --- a/docs/api/topics/misc.rst +++ b/docs/api/topics/misc.rst @@ -322,7 +322,7 @@ Carriers ======= -.. http:get:: /api/v1/apps/carrier/ +.. http:get:: /api/v1/services/carrier/ Returns a list of possible carriers for apps. @@ -335,7 +335,7 @@ Carriers .. _carrier-response-label: -.. http:get:: /api/v1/apps/carrier// +.. http:get:: /api/v1/services/carrier// Returns a carrier. @@ -350,7 +350,7 @@ Carriers { "id": "1", "name": "PhoneORama", - "resource_uri": "/api/v1/apps/carrier/phoneorama/", + "resource_uri": "/api/v1/services/carrier/phoneorama/", "slug": "phoneorama" } @@ -360,7 +360,7 @@ Regions ======= -.. http:get:: /api/v1/apps/region/ +.. http:get:: /api/v1/services/region/ Returns a list of possible regions for apps. @@ -373,7 +373,7 @@ Regions .. _region-response-label: -.. http:get:: /api/v1/apps/region// +.. http:get:: /api/v1/services/region// Returns a region. @@ -388,7 +388,7 @@ Regions { "id": "1", "name": "Appistan", - "resource_uri": "/api/v1/apps/region/ap/", + "resource_uri": "/api/v1/services/region/ap/", "slug": "ap", "default_currency": "USD", "default_language": "en-AP" diff --git a/mkt/api/resources.py b/mkt/api/resources.py index 19679e66c5..1a146ce155 100644 --- a/mkt/api/resources.py +++ b/mkt/api/resources.py @@ -460,6 +460,7 @@ class RegionResource(CORSResource, MarketplaceResource): detail_allowed_methods = ['get'] list_allowed_methods = ['get'] resource_name = 'region' + slug_lookup = 'slug' def dehydrate_ratingsbodies(self, bundle): return [rb.name for rb in bundle.obj.ratingsbodies] @@ -470,18 +471,6 @@ class RegionResource(CORSResource, MarketplaceResource): def obj_get(self, request=None, **kwargs): return REGIONS_DICT.get(kwargs['pk'], None) - def get_resource_uri(self, bundle_or_obj): - kwargs = { - 'resource_name': self._meta.resource_name, - 'api_name': self._meta.api_name - } - if isinstance(bundle_or_obj, Bundle): - kwargs['pk'] = bundle_or_obj.obj.slug - else: - kwargs['pk'] = bundle_or_obj.slug - - return self._build_reverse_url("api_dispatch_detail", kwargs=kwargs) - class CarrierResource(CORSResource, MarketplaceResource): name = fields.CharField('name') @@ -492,6 +481,7 @@ class CarrierResource(CORSResource, MarketplaceResource): detail_allowed_methods = ['get'] list_allowed_methods = ['get'] resource_name = 'carrier' + slug_lookup = 'slug' def dehydrate_ratingsbodies(self, bundle): return [rb.name for rb in bundle.obj.ratingsbodies] @@ -501,15 +491,3 @@ class CarrierResource(CORSResource, MarketplaceResource): def obj_get(self, request=None, **kwargs): return CARRIER_MAP.get(kwargs['pk'], None) - - def get_resource_uri(self, bundle_or_obj): - kwargs = { - 'resource_name': self._meta.resource_name, - 'api_name': self._meta.api_name - } - if isinstance(bundle_or_obj, Bundle): - kwargs['pk'] = bundle_or_obj.obj.slug - else: - kwargs['pk'] = bundle_or_obj.slug - - return self._build_reverse_url("api_dispatch_detail", kwargs=kwargs) diff --git a/mkt/api/tests/test_handlers.py b/mkt/api/tests/test_handlers.py index f2ddcf4822..53c03db394 100644 --- a/mkt/api/tests/test_handlers.py +++ b/mkt/api/tests/test_handlers.py @@ -945,6 +945,9 @@ class TestPreviewHandler(BaseOAuth, AMOPaths): class TestRegionsCarriers(BaseOAuth, AMOPaths): + def setUp(self): + super(TestRegionsCarriers, self).setUp(api_name='services') + def test_regions_list(self): res = self.client.get(list_url('region')) data = json.loads(res.content) @@ -952,8 +955,7 @@ class TestRegionsCarriers(BaseOAuth, AMOPaths): set(r.slug for r in regions.ALL_REGIONS)) def test_region(self): - res = self.client.get(('api_dispatch_detail', - {'resource_name': 'region', 'pk': 'co'})) + res = self.client.get(get_url('region', pk='co')) data = json.loads(res.content) eq_(data['default_currency'], regions.CO.default_currency) @@ -964,8 +966,6 @@ class TestRegionsCarriers(BaseOAuth, AMOPaths): set(r.slug for r in carriers.CARRIERS)) def test_carrier(self): - res = self.client.get(('api_dispatch_detail', - {'resource_name': 'carrier', - 'pk': 'telefonica'})) + res = self.client.get(get_url('carrier', pk='telefonica')) data = json.loads(res.content) eq_(data['id'], carriers.TELEFONICA.id) diff --git a/mkt/api/urls.py b/mkt/api/urls.py index 2127bb5144..9a44a28738 100644 --- a/mkt/api/urls.py +++ b/mkt/api/urls.py @@ -21,14 +21,14 @@ api.register(WithFeaturedResource()) api.register(SearchResource()) api.register(StatusResource()) api.register(RatingResource()) -api.register(RegionResource()) -api.register(CarrierResource()) stats_api = Api(api_name='stats') stats_api.register(GlobalStatsResource()) services = Api(api_name='services') services.register(ConfigResource()) +services.register(RegionResource()) +services.register(CarrierResource()) if settings.ALLOW_TASTYPIE_SERVICES: services.register(ErrorResource(set_handler=handle_500))