diff options
| author | Tom Christie | 2013-07-15 11:38:38 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-07-15 11:38:38 +0100 |
| commit | ae63c49777f4d5b766b85a4b28f6328bd6f9516a (patch) | |
| tree | 2462b69085edba2995034939c5a1e7e40738e4ce /docs/api-guide | |
| parent | 6de9b7c8caaea00df2b1399ecd7b815ac556a70e (diff) | |
| download | django-rest-framework-ae63c49777f4d5b766b85a4b28f6328bd6f9516a.tar.bz2 | |
Added test case classes
Diffstat (limited to 'docs/api-guide')
| -rw-r--r-- | docs/api-guide/testing.md | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/docs/api-guide/testing.md b/docs/api-guide/testing.md index aba9283e..40b07763 100644 --- a/docs/api-guide/testing.md +++ b/docs/api-guide/testing.md @@ -167,6 +167,36 @@ As usual CSRF validation will only apply to any session authenticated views. Th --- +# 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`. + +* `APISimpleTestCase` +* `APITransactionTestCase` +* `APITestCase` +* `APILiveServerTestCase` + +## Example + +You can use any of REST framework's test case classes as you would for the regular Django test case classes. The `self.client` attribute will be an `APIClient` instance. + + from django.core.urlresolvers import reverse + from rest_framework import status + from rest_framework.test import APITestCase + + class AccountTests(APITestCase): + def test_create_account(self): + """ + Ensure we can create a new account object. + """ + url = reverse('account-list') + data = {'name': 'DabApps'} + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertEqual(response.data, data) + +--- + # Testing responses ## Checking the response data |
