Add docs for URLPatternsTestCase

This commit is contained in:
Ryan P Kilby 2017-12-21 23:49:22 -05:00
parent c30a336b57
commit 683f1f4406

View File

@ -292,7 +292,7 @@ similar way as with `RequestsClient`.
--- ---
# Test cases # API Test cases
REST framework includes the following test case classes, that mirror the existing Django test case classes, but use `APIClient` instead of Django's default `Client`. REST framework includes the following test case classes, that mirror the existing Django test case classes, but use `APIClient` instead of Django's default `Client`.
@ -324,6 +324,32 @@ You can use any of REST framework's test case classes as you would for the regul
--- ---
# URLPatternsTestCase
REST framework also provides a test case class for isolating `urlpatterns` on a per-class basis. Note that this inherits from Django's `SimpleTestCase`, and will most likely need to be mixed with another test case class.
## Example
from django.urls import include, path, reverse
from rest_framework.test import APITestCase, URLPatternsTestCase
class AccountTests(APITestCase, URLPatternsTestCase):
urlpatterns = [
path('api/', include('api.urls')),
]
def test_create_account(self):
"""
Ensure we can create a new account object.
"""
url = reverse('account-list')
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 1)
---
# Testing responses # Testing responses
## Checking the response data ## Checking the response data