Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d036de0
(Not tested yet)
Dec 22, 2015
c6401a9
Preparing merge with upstream/master
Jan 3, 2016
deb9446
Add app_name in urls + tests
Jan 4, 2016
e2744a0
- Show the "Jump to" dropdown only if there is more than 1 value
Jan 5, 2016
b774268
Add '-' to the url patten
Jan 5, 2016
e866a41
Use the endpoint's namespace into the group url
Jan 5, 2016
2a56a35
Manage nested serializer and list fields/serializers in Endpoint fields
Jan 20, 2016
34f9683
correction of recursive call
Jan 20, 2016
5a43d41
Recursive include is now called with "only"
Jan 20, 2016
85ba4d2
Manage allowed_methods on ModelViewSets
Jan 21, 2016
a621943
Sort allowed_methods
Jan 22, 2016
8c12fdd
Merge remote-tracking branch 'upstream/master'
Jan 26, 2016
8dab8d9
Add line breaks on docstrings
Feb 19, 2016
52cf5ce
Merge from upstream/master
Feb 19, 2016
be8f4ce
Merge remote-tracking branch 'upstream/master'
Feb 29, 2016
4d2a370
Nested/List serializers + login_required
Feb 29, 2016
a97f94a
Re-enabling jumbotron block without content (too much space lost)
Feb 29, 2016
fa5871a
Merge branch 'master' into master
debnet Mar 8, 2016
3441d6f
Fix a TypeError fetching the allowed_methods when the ModelViewSet has
msaelices Mar 15, 2016
eedcae5
Merge pull request #1 from msaelices/master
debnet Mar 15, 2016
c6bbf50
Fixing flake8 issues after PR #1
Mar 16, 2016
0fd3c1d
Merge remote-tracking branch 'upstream/master'
Mar 25, 2016
1b5b1c2
Merge branch 'master' into master
debnet Mar 27, 2016
27e5d8e
Merge branch 'master' into master
debnet Mar 31, 2016
9a677dc
Merge remote-tracking branch 'upstream/master'
Jun 2, 2016
d08e25b
Merge upstream/master 0.0.10
Jun 2, 2016
fc9179f
Merge remote-tracking branch 'upstream/master'
Jul 29, 2016
550b372
Merge from upstream + allow list of drf_routers
Aug 1, 2016
15dead2
Fix flake8
Aug 1, 2016
33b41df
Update to Django 1.10
Sep 5, 2016
f36f8a1
Merge branch 'master' into master
debnet Sep 7, 2016
e5a8bef
Fix Django 2
Apr 12, 2018
ada797d
Fix _get_allowed_methods
Oct 11, 2018
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add app_name in urls + tests
  • Loading branch information
Maxence committed Jan 4, 2016
commit deb94461af2d2030d8d5bb56c9faa0637d7d4e75
5 changes: 3 additions & 2 deletions demo/project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
url(r'^docs/', include('rest_framework_docs.urls')),

# API
url(r'^accounts/', view=include('project.accounts.urls', namespace='accounts')),
url(r'^organisations/', view=include('project.organisations.urls', namespace='organisations')),
url(r'^accounts/', view=include('project.accounts.urls', namespace='accounts', app_name='accounts')),
url(r'^organisations/', view=include('project.organisations.urls', namespace='organisations',
app_name='organisations')),
]
3 changes: 1 addition & 2 deletions rest_framework_docs/api_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ class ApiEndpoint(object):
def __init__(self, pattern, parent_pattern=None):
self.pattern = pattern
self.callback = pattern.callback
# self.name = pattern.name
self.docstring = self.__get_docstring__()
if parent_pattern:
self.name_parent = parent_pattern.namespace or parent_pattern.app_name or \
simplify_regex(parent_pattern.regex.pattern).replace('/', '-')
if hasattr(pattern.callback, 'cls') and issubclass(pattern.callback.cls, ModelViewSet):
self.name_parent = '{} (REST)'.format(self.name_parent)
self.name_parent = '%s (REST)' % self.name_parent
else:
self.name_parent = ''
self.path = self.__get_path__(parent_pattern)
Expand Down
55 changes: 47 additions & 8 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def test_index_view_with_endpoints(self):
self.assertEqual(len(response.context["endpoints"]), 10)

# Test the login view
self.assertEqual(response.context["endpoints"][0].name_parent, "accounts")
self.assertEqual(response.context["endpoints"][0].allowed_methods, ['POST', 'OPTIONS'])
self.assertEqual(response.context["endpoints"][0].path, "/accounts/login/")
self.assertEqual(response.context["endpoints"][0].docstring, "A view that allows users to login providing their username and password.")
self.assertEqual(len(response.context["endpoints"][0].fields), 2)
self.assertEqual(response.context["endpoints"][0].fields[0]["type"], "CharField")
self.assertTrue(response.context["endpoints"][0].fields[0]["required"])
self.assertEqual(response.context["endpoints"][1].name_parent, "accounts")
self.assertEqual(response.context["endpoints"][1].allowed_methods, ['POST', 'OPTIONS'])
self.assertEqual(response.context["endpoints"][1].path, "/accounts/login/")
self.assertEqual(response.context["endpoints"][1].docstring, "A view that allows users to login providing their username and password.")
self.assertEqual(len(response.context["endpoints"][1].fields), 2)
self.assertEqual(response.context["endpoints"][1].fields[0]["type"], "CharField")
self.assertTrue(response.context["endpoints"][1].fields[0]["required"])

# The view "OrganisationErroredView" (organisations/(?P<slug>[\w-]+)/errored/) should contain an error.
self.assertEqual(str(response.context["endpoints"][8].errors), "'test_value'")
self.assertEqual(str(response.context["endpoints"][9].errors), "'test_value'")

def test_index_search_with_endpoints(self):
response = self.client.get("%s?search=reset-password" % reverse("drfdocs"))
Expand All @@ -59,3 +59,42 @@ def test_index_view_docs_hidden(self):

self.assertEqual(response.status_code, 404)
self.assertEqual(response.reason_phrase.upper(), "NOT FOUND")

def test_index_view_with_existent_app_name(self):
"""
Should load the drf docs view with all the endpoints contained in the specified app_name.
NOTE: Views that do **not** inherit from DRF's "APIView" are not included.
"""
# Test 'accounts' app_name
response = self.client.get(reverse('drfdocs-ns', args=['accounts']))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["endpoints"]), 5)

# Test the login view
self.assertEqual(response.context["endpoints"][0].name_parent, "accounts")
self.assertEqual(response.context["endpoints"][0].allowed_methods, ['POST', 'OPTIONS'])
self.assertEqual(response.context["endpoints"][0].path, "/accounts/login/")

# Test 'organisations' app_name
response = self.client.get(reverse('drfdocs-ns', args=['organisations']))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["endpoints"]), 4)

# The view "OrganisationErroredView" (organisations/(?P<slug>[\w-]+)/errored/) should contain an error.
self.assertEqual(str(response.context["endpoints"][3].errors), "'test_value'")

def test_index_search_with_existent_app_name(self):
response = self.client.get("%s?search=reset-password" % reverse('drfdocs-ns', args=['accounts']))

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["endpoints"]), 2)
self.assertEqual(response.context["endpoints"][1].path, "/accounts/reset-password/confirm/")
self.assertEqual(len(response.context["endpoints"][1].fields), 3)

def test_index_view_with_non_existent_app_name(self):
"""
Should load the drf docs view with no endpoint.
"""
response = self.client.get(reverse('drfdocs-ns', args=['non_existent_app_name']))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["endpoints"]), 0)
4 changes: 2 additions & 2 deletions tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
url(r'^docs/', include('rest_framework_docs.urls')),

# API
url(r'^accounts/', view=include(accounts_urls, namespace='accounts')),
url(r'^organisations/', view=include(organisations_urls, namespace='organisations')),
url(r'^accounts/', view=include(accounts_urls, namespace='accounts', app_name='accounts')),
url(r'^organisations/', view=include(organisations_urls, namespace='organisations', app_name='organisations')),

# Endpoints without parents/namespaces
url(r'^another-login/$', views.LoginView.as_view(), name="login"),
Expand Down