-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1832 from uktrade/feature/api-docs
Enable the Django Rest Framework built-in documentation feature
- Loading branch information
Showing
14 changed files
with
138 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The Django Rest Framework built-in documentation was enabled at the URL path ``/docs``. | ||
|
||
This is currently only enabled if the ``ENABLE_API_DOCUMENTATION`` environment variable is | ||
set to ``True`` as the documentation is not fully functional as yet. | ||
|
||
You must also log into Django admin prior to accessing ``/docs``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
from django.conf import settings | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
from datahub.core.test_utils import get_admin_user | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestDocsView: | ||
"""Test the DRF docs view.""" | ||
|
||
def test_returns_200_if_logged_in(self, client): | ||
""" | ||
Test that a 200 is returned if a user is logged in using session authentication. | ||
This is primarily to make sure that the page is functioning and no views are breaking it. | ||
""" | ||
password = 'test-password' | ||
user = get_admin_user(password=password) | ||
client.login(username=user.email, password=password) | ||
|
||
url = reverse('api-docs:docs-index') | ||
response = client.get(url) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
assert settings.API_DOCUMENTATION_TITLE.encode('utf-8') in response.rendered_content | ||
|
||
def test_returns_403_if_not_logged_in(self, client): | ||
"""Test that a 403 error is returned if the user is not logged in.""" | ||
url = reverse('api-docs:docs-index') | ||
response = client.get(url) | ||
|
||
assert response.status_code == status.HTTP_403_FORBIDDEN | ||
assert settings.API_DOCUMENTATION_TITLE.encode('utf-8') not in response.rendered_content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters