mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Add docs for URLPatternsTestCase
This commit is contained in:
parent
c30a336b57
commit
683f1f4406
|
@ -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`.
|
||||
|
||||
|
@ -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
|
||||
|
||||
## Checking the response data
|
||||
|
|
Loading…
Reference in New Issue
Block a user