clean up regions/carriers
This commit is contained in:
Родитель
39a5e5ae3b
Коммит
cd3ce77f7e
|
@ -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/<slug>/
|
||||
.. http:get:: /api/v1/services/carrier/<slug>/
|
||||
|
||||
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/<slug>/
|
||||
.. http:get:: /api/v1/services/region/<slug>/
|
||||
|
||||
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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
Загрузка…
Ссылка в новой задаче