diff --git a/ietf/api.py b/ietf/api.py index 7b2b07e1e..e568c48e5 100644 --- a/ietf/api.py +++ b/ietf/api.py @@ -4,6 +4,7 @@ import datetime from django.conf import settings from django.http import HttpResponse +from django.core.urlresolvers import reverse from tastypie.api import Api from tastypie.serializers import Serializer @@ -30,11 +31,11 @@ for _app in settings.INSTALLED_APPS: def top_level(request): available_resources = {} - apitop = settings.RESTAPI_V1_URL_TOP + apitop = reverse('ietf.api.top_level') for name in sorted([ name for name, api in _api_list if len(api._registry) > 0 ]): available_resources[name] = { - 'list_endpoint': '/%s/%s/' % (apitop, name), + 'list_endpoint': '%s/%s/' % (apitop, name), } serializer = Serializer() diff --git a/ietf/settings.py b/ietf/settings.py index fddcde963..fc81b786f 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -459,8 +459,6 @@ GROUP_VIRTUAL_DOMAIN = "virtual.ietf.org" POSTCONFIRM_PATH = "/a/postconfirm/test-wrapper" -RESTAPI_V1_URL_TOP = "api/v1" # no leading or trailing slash - # Put the production SECRET_KEY in settings_local.py, and also any other # sensitive or site-specific changes. DO NOT commit settings_local.py to svn. from settings_local import * # pyflakes:ignore diff --git a/ietf/urls.py b/ietf/urls.py index 3130be5bd..3bcf19a48 100644 --- a/ietf/urls.py +++ b/ietf/urls.py @@ -65,13 +65,12 @@ urlpatterns = patterns('', ) # Endpoints for Tastypie's REST API -apitop = settings.RESTAPI_V1_URL_TOP urlpatterns += patterns('', - (r'^%s/?$'%apitop, api.top_level), + (r'^api/v1/?$', api.top_level), ) for n,a in api._api_list: urlpatterns += patterns('', - (r'^%s/'%apitop, include(a.urls)), + (r'^api/v1/', include(a.urls)), ) if settings.SERVER_MODE in ('development', 'test'): diff --git a/ietf/utils/tests_restapi.py b/ietf/utils/tests_restapi.py index 677c699e9..6da7812a8 100644 --- a/ietf/utils/tests_restapi.py +++ b/ietf/utils/tests_restapi.py @@ -3,14 +3,12 @@ from __future__ import print_function import debug debug.debug = True -from django.conf import settings +from django.core.urlresolvers import reverse from tastypie.test import ResourceTestCase + from ietf.utils.test_data import make_test_data - - - class RestApi(ResourceTestCase): def list_recursively(self, resource, format): """ @@ -34,12 +32,12 @@ class RestApi(ResourceTestCase): def test_json_api_explore(self): make_test_data() - apitop = settings.RESTAPI_V1_URL_TOP - self.list_recursively('/%s/'%apitop, format='json') + apitop = reverse('ietf.api.top_level') + self.list_recursively('%s/'%apitop, format='json') def test_xml_api_explore(self): - apitop = settings.RESTAPI_V1_URL_TOP - self.assertValidXMLResponse(self.api_client.get('/%s/doc/'%apitop, format='xml')) + apitop = reverse('ietf.api.top_level') + self.assertValidXMLResponse(self.api_client.get('%s/doc/'%apitop, format='xml')) def test_json_doc_document(self): """ @@ -48,8 +46,8 @@ class RestApi(ResourceTestCase): than 100 documents in the test-data (the current count is 10) """ make_test_data() - apitop = settings.RESTAPI_V1_URL_TOP - r = self.api_client.get('/%s/doc/document/'%apitop, format='json', limit=100) + apitop = reverse('ietf.api.top_level') + r = self.api_client.get('%s/doc/document/'%apitop, format='json', limit=100) doclist = self.deserialize(r)["objects"] docs = dict( (doc["name"], doc) for doc in doclist ) for name in ( @@ -68,12 +66,12 @@ class RestApi(ResourceTestCase): of relationships give URLs which are handled without raising exceptions. """ make_test_data() - apitop = settings.RESTAPI_V1_URL_TOP - r = self.api_client.get('/%s/doc/document/'%apitop, format='json') + apitop = reverse('ietf.api.top_level') + r = self.api_client.get('%s/doc/document/'%apitop, format='json') doclist = self.deserialize(r)["objects"] for doc in doclist: for key in doc: value = doc[key] - if isinstance(value, basestring) and value.startswith('/%s/'%apitop): + if isinstance(value, basestring) and value.startswith('%s/'%apitop): self.api_client.get(value, format='json') \ No newline at end of file