Skip to content

Commit 3cb39d4

Browse files
committed
Define the REST api top url in settings.py, rather than having literals in multiple places in the code.
- Legacy-Id: 8751
1 parent 7d2c934 commit 3cb39d4

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

ietf/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
def top_level(request):
3131
available_resources = {}
3232

33+
apitop = settings.RESTAPI_V1_URL_TOP
34+
3335
for name in sorted([ name for name, api in _api_list if len(api._registry) > 0 ]):
3436
available_resources[name] = {
35-
'list_endpoint': '/api/%s/' % name,
37+
'list_endpoint': '/%s/%s/' % (apitop, name),
3638
}
3739

3840
serializer = Serializer()

ietf/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ def skip_unreadable_post(record):
459459

460460
POSTCONFIRM_PATH = "/a/postconfirm/test-wrapper"
461461

462+
RESTAPI_V1_URL_TOP = "api/v1" # no leading or trailing slash
463+
462464
# Put the production SECRET_KEY in settings_local.py, and also any other
463465
# sensitive or site-specific changes. DO NOT commit settings_local.py to svn.
464466
from settings_local import * # pyflakes:ignore

ietf/urls.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@
6464
(r'^googlea30ad1dacffb5e5b.html', TemplateView.as_view(template_name='googlea30ad1dacffb5e5b.html')),
6565
)
6666

67+
# Endpoints for Tastypie's REST API
68+
apitop = settings.RESTAPI_V1_URL_TOP
69+
urlpatterns += patterns('',
70+
(r'^%s/?$'%apitop, api.top_level),
71+
)
6772
for n,a in api._api_list:
6873
urlpatterns += patterns('',
69-
(r'^api/?$', api.top_level),
70-
(r'^api/', include(a.urls)),
74+
(r'^%s/'%apitop, include(a.urls)),
7175
)
7276

7377
if settings.SERVER_MODE in ('development', 'test'):

ietf/utils/tests_restapi.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import debug
44
debug.debug = True
55

6+
from django.conf import settings
7+
68
from tastypie.test import ResourceTestCase
79
from ietf.utils.test_data import make_test_data
810

@@ -32,10 +34,12 @@ def list_recursively(self, resource, format):
3234

3335
def test_json_api_explore(self):
3436
make_test_data()
35-
self.list_recursively('/api/', format='json')
37+
apitop = settings.RESTAPI_V1_URL_TOP
38+
self.list_recursively('/%s/'%apitop, format='json')
3639

3740
def test_xml_api_explore(self):
38-
self.assertValidXMLResponse(self.api_client.get('/api/doc/', format='xml'))
41+
apitop = settings.RESTAPI_V1_URL_TOP
42+
self.assertValidXMLResponse(self.api_client.get('/%s/doc/'%apitop, format='xml'))
3943

4044
def test_json_doc_document(self):
4145
"""
@@ -44,7 +48,8 @@ def test_json_doc_document(self):
4448
than 100 documents in the test-data (the current count is 10)
4549
"""
4650
make_test_data()
47-
r = self.api_client.get('/api/doc/document/', format='json', limit=100)
51+
apitop = settings.RESTAPI_V1_URL_TOP
52+
r = self.api_client.get('/%s/doc/document/'%apitop, format='json', limit=100)
4853
doclist = self.deserialize(r)["objects"]
4954
docs = dict( (doc["name"], doc) for doc in doclist )
5055
for name in (
@@ -63,11 +68,12 @@ def test_json_doc_relationships(self):
6368
of relationships give URLs which are handled without raising exceptions.
6469
"""
6570
make_test_data()
66-
r = self.api_client.get('/api/doc/document/', format='json')
71+
apitop = settings.RESTAPI_V1_URL_TOP
72+
r = self.api_client.get('/%s/doc/document/'%apitop, format='json')
6773
doclist = self.deserialize(r)["objects"]
6874
for doc in doclist:
6975
for key in doc:
7076
value = doc[key]
71-
if isinstance(value, basestring) and value.startswith('/api/'):
77+
if isinstance(value, basestring) and value.startswith('/%s/'%apitop):
7278
self.api_client.get(value, format='json')
7379

0 commit comments

Comments
 (0)